8 #include "sys/socket.h"
9 #include "netinet/in.h"
10 #include "arpa/inet.h"
11 #include "sys/select.h"
17 int main(int argc
, char **argv
)
21 struct fd_set fdr
, fdw
, fde
;
27 test_banner("Big Select Test");
30 nsock
= atoi(argv
[1]);
32 if (nsock
< 1 || nsock
> 50) {
33 printf("Unrealistic value of sockets given. Must be between 1 and 50\n");
34 err(-1, "Parameters");
37 s
= (int *) malloc(nsock
* sizeof(int));
39 err(-1, "Not enought memory for sockets array");
41 printf("\nTest will be run with %d sockets\n\n", nsock
);
43 for (i
=0;i
<nsock
;i
++) {
44 s
[i
] = socket(AF_INET
, SOCK_DGRAM
, 0);
47 err(errno
, "Socket creation failed");
52 for (i
=0;i
<nsock
;i
++) {
65 printf("Trying with timeval (5 secs)...\n");
66 rtc
= real_time_clock();
67 rv
= select(max
+ 1, &fdr
, NULL
, &fde
, &tv
);
68 rtc
= real_time_clock() - rtc
;
69 printf("select gave %d in %ld seconds\n", rv
, rtc
);
71 printf("errno = %d [%s]\n", errno
, strerror(errno
));
73 printf("resetting select fd's\n");
84 printf("Trying without timeval (= NULL)\n");
85 rv
= select(max
+1, &fdr
, &fdw
, &fde
, NULL
);
86 printf("select gave %d\n", rv
);
89 if (FD_ISSET(s
[0], &fdr
))
90 printf("Data to read\n");
91 if (FD_ISSET(s
[0], &fdw
))
92 printf("OK to write\n");
93 if (FD_ISSET(s
[0], &fde
))
94 printf("Exception!\n");
96 printf("error was %d [%s]\n", errno
, strerror(errno
));
103 printf("Test complete.\n");