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>
25 int main(int argc
, char *argv
[])
27 fd_set fds_read
, fds_write
;
30 struct timeval timeout
;
38 FD_SET(1, &fds_write
);
39 printf("Input some data: ");
41 retval
=select(3, &fds_read
, NULL
, NULL
, &timeout
);
43 fprintf(stderr
, "Error while executing select\n");
47 printf("\n Hey! Feed me some data!\n");
51 if (!FD_ISSET(0, &fds_read
)) {
52 fprintf(stderr
, "Error: stdin not ready (?)\n");
56 if (!strcmp(data
, "exit"))
58 printf("Try to write it back\n");
59 retval
=select(3, NULL
, &fds_write
, NULL
, NULL
);
61 fprintf(stderr
, "Error while executing select\n");
64 if (!FD_ISSET(1, &fds_write
)) {
65 fprintf(stderr
, "Error: stdout not ready (?)\n");
68 printf("Data: %s\n", data
);