Created
August 18, 2019 02:02
-
-
Save heiher/50141b156f4be21cbf19d9507eb0372d to your computer and use it in GitHub Desktop.
Why the edge-triggered mode doesn't work for epoll file descriptor itself?
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 <unistd.h> | |
#include <sys/epoll.h> | |
int | |
main (int argc, char *argv[]) | |
{ | |
int efd[2]; | |
struct epoll_event e; | |
efd[0] = epoll_create (1); | |
if (efd[0] < 0) | |
return -1; | |
efd[1] = epoll_create (1); | |
if (efd[1] < 0) | |
return -2; | |
e.events = EPOLLIN | EPOLLET; | |
e.data.u64 = 1; | |
if (epoll_ctl (efd[0], EPOLL_CTL_ADD, efd[1], &e) < 0) | |
return -3; | |
e.events = EPOLLOUT | EPOLLET; | |
e.data.u64 = 2; | |
if (epoll_ctl (efd[1], EPOLL_CTL_ADD, 1, &e) < 0) | |
return -4; | |
for (;;) { | |
struct epoll_event events[16]; | |
int nfds; | |
nfds = epoll_wait (efd[0], events, 16, -1); | |
printf ("nfds: %d\n", nfds); | |
} | |
close (efd[1]); | |
close (efd[0]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment