Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/select.h>
- #include <sys/time.h>
- #include <sys/stat.h>
- #include <stddef.h>
- #include <fcntl.h>
- #include <stdio.h>
- #define nfds 2
- int
- main() {
- fd_set read, write;
- struct timeval timeout;
- int fd1 = open("fds/1", O_RDWR),
- fd2 = open("fds/2", O_RDWR);
- printf("fd: %i\n", fd1);
- printf("fd: %i\n", fd2);
- int ready;
- FD_ZERO(&read);
- FD_ZERO(&write);
- FD_SET(fd1, &read);
- FD_SET(fd2, &read);
- for(;;){
- timeout.tv_sec = 5;
- timeout.tv_usec = 0;
- ready = select(nfds + 1, &read, NULL, NULL, &timeout);
- printf("ready = %i\t", ready);
- if (ready < 0) {
- perror("fail\n");
- return 1;
- } else if (ready > 0) {
- printf("reading\n");
- } else {
- printf("no data within time interval\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement