Skip to content

Instantly share code, notes, and snippets.

@kotaroito
Created February 2, 2014 11:45
Show Gist options
  • Save kotaroito/8767140 to your computer and use it in GitHub Desktop.
Save kotaroito/8767140 to your computer and use it in GitHub Desktop.
poll
#include <stdlib.h>
#include <stdio.h>
#include <poll.h>
#include <unistd.h>
#define BUFFSIZE 1024
int main(void)
{
struct pollfd pfd;
int retval;
char readbuf[BUFFSIZE];
pfd.fd = STDIN_FILENO;
pfd.events = POLLIN;
retval = poll(&pfd, 1, 10 * 1000);
if ( retval == 0 ) {
printf("timeout\n");
}
else if ( retval < 0 ) {
perror("poll");
}
else {
read(STDIN_FILENO, readbuf, BUFFSIZE);
printf("%s\n", readbuf);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment