4 * Objetive: The purpose of this test is to make sure that select works
5 * when working with the terminal with timeouts
7 * Description: This tests wait entry from stdin using select and displays
8 * it again in stdout when it is ready to write (which is always). It has
9 * a timeout value as well.
15 #include <sys/types.h>
16 #include <sys/asynchio.h>
19 #include <sys/select.h>
26 fd_set fds_read
, fds_write
;
29 struct timeval timeout
;
37 FD_SET(1, &fds_write
);
38 printf("Input some data: ");
40 retval
=select(3, &fds_read
, NULL
, NULL
, &timeout
);
42 fprintf(stderr
, "Error while executing select\n");
46 printf("\n Hey! Feed me some data!\n");
50 if (!FD_ISSET(0, &fds_read
)) {
51 fprintf(stderr
, "Error: stdin not ready (?)\n");
55 if (!strcmp(data
, "exit"))
57 printf("Try to write it back\n");
58 retval
=select(3, NULL
, &fds_write
, NULL
, NULL
);
60 fprintf(stderr
, "Error while executing select\n");
63 if (!FD_ISSET(1, &fds_write
)) {
64 fprintf(stderr
, "Error: stdout not ready (?)\n");
67 printf("Data: %s\n", data
);