Created
August 28, 2012 12:25
-
-
Save AlexsJones/3497625 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <sys/time.h> | |
| #include <sys/types.h> | |
| #include <unistd.h> | |
| int main(void) | |
| { | |
| fd_set bar; | |
| struct timeval foo; | |
| int ret; | |
| /* Watch stdin (fd 0) to see when it has input. As per unix man example*/ | |
| FD_ZERO(&bar); | |
| FD_SET(0, &bar); | |
| foo.tv_sec = 5; | |
| foo.tv_usec = 0; | |
| ret = select(1, &bar, NULL, NULL, &foo); | |
| if (ret == -1) | |
| { | |
| perror("select()"); | |
| } | |
| else if (ret) | |
| { | |
| printf("Data is available now.\n"); | |
| /* rfds is true*/ | |
| } | |
| else | |
| { | |
| printf("No data within five seconds.\n"); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment