Created
June 18, 2013 14:33
-
-
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
This file contains 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 <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