mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-24 18:51:36 +01:00
Poll works!
This commit is contained in:
@@ -6,32 +6,29 @@
|
||||
#include <unistd.h> /* read */
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char buf[1024];
|
||||
int fd, n;
|
||||
char buf[1024], path[1024];
|
||||
int fd, i, n;
|
||||
short revents;
|
||||
struct pollfd pfd;
|
||||
|
||||
fd = open(argv[1], O_RDONLY | O_NONBLOCK);
|
||||
if (fd == -1) {
|
||||
perror("open");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
pfd.fd = fd;
|
||||
pfd.events = POLLIN;
|
||||
while (1) {
|
||||
puts("loop");
|
||||
poll(&pfd, 1, -1);
|
||||
i = poll(&pfd, 1, -1);
|
||||
if (i == -1) {
|
||||
perror("poll");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
revents = pfd.revents;
|
||||
if (revents & POLLIN) {
|
||||
n = read(pfd.fd, buf, sizeof(buf));
|
||||
printf("POLLIN n=%d buf=%.*s\n", n, n, buf);
|
||||
}
|
||||
if (revents & POLLHUP) {
|
||||
printf("POLLHUP\n");
|
||||
close(pfd.fd);
|
||||
break;
|
||||
}
|
||||
if (revents & POLLNVAL) {
|
||||
printf("POLLNVAL\n");
|
||||
}
|
||||
if (revents & POLLERR) {
|
||||
printf("POLLERR\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user