Skip to content

Instantly share code, notes, and snippets.

@elazarl
Created June 18, 2013 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elazarl/5805848 to your computer and use it in GitHub Desktop.
Save elazarl/5805848 to your computer and use it in GitHub Desktop.
A simple test to determine if your OS allows polling devices, e.g. /dev/null
#include <stdio.h>
#include <poll.h>
#include <fcntl.h>
int main() {
int fd = open("/dev/null", O_WRONLY);
struct pollfd pollfds = { fd, POLLOUT, 0 };
if (fd < 0) {
perror("open");
return 1;
}
if (poll(&pollfds, 1, -1) < 0) {
perror("poll");
return 2;
}
if (pollfds.revents == POLLNVAL) {
puts("huh? why poll({/dev/null, POLLOUT, 0}, 1) returns POLLNVAL?");
}
if (pollfds.revents == POLLOUT) {
puts("working as expected");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment