Skip to content

Instantly share code, notes, and snippets.

@AlexsJones
Created August 28, 2012 12:25
Show Gist options
  • Select an option

  • Save AlexsJones/3497625 to your computer and use it in GitHub Desktop.

Select an option

Save AlexsJones/3497625 to your computer and use it in GitHub Desktop.
#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