mkfs: symlink support
[minix.git] / test / select / test10.c
blob6f68c84905b01dd00da1c6109bc71405fbb8da53
1 /*
2 * Test name: test10.c
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.
11 * Jose M. Gomez
14 #include <time.h>
15 #include <sys/types.h>
16 #include <sys/asynchio.h>
17 #include <fcntl.h>
18 #include <unistd.h>
19 #include <sys/select.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <limits.h>
23 #include <string.h>
25 int main(int argc, char *argv[])
27 fd_set fds_read, fds_write;
28 int retval;
29 char data[1024];
30 struct timeval timeout;
32 while(1) {
33 timeout.tv_sec = 3;
34 timeout.tv_usec = 0;
35 FD_ZERO(&fds_read);
36 FD_ZERO(&fds_write);
37 FD_SET(0, &fds_read);
38 FD_SET(1, &fds_write);
39 printf("Input some data: ");
40 fflush(stdout);
41 retval=select(3, &fds_read, NULL, NULL, &timeout);
42 if (retval < 0) {
43 fprintf(stderr, "Error while executing select\n");
44 exit(-1);
46 if (retval == 0) {
47 printf("\n Hey! Feed me some data!\n");
48 fflush(stdout);
49 continue;
51 if (!FD_ISSET(0, &fds_read)) {
52 fprintf(stderr, "Error: stdin not ready (?)\n");
53 exit(-1);
55 gets(data);
56 if (!strcmp(data, "exit"))
57 exit(0);
58 printf("Try to write it back\n");
59 retval=select(3, NULL, &fds_write, NULL, NULL);
60 if (retval < 0) {
61 fprintf(stderr, "Error while executing select\n");
62 exit(-1);
64 if (!FD_ISSET(1, &fds_write)) {
65 fprintf(stderr, "Error: stdout not ready (?)\n");
66 exit(-1);
68 printf("Data: %s\n", data);
70 return 1;