Skip to content

Instantly share code, notes, and snippets.

@heiher
Created August 18, 2019 02:02
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 heiher/50141b156f4be21cbf19d9507eb0372d to your computer and use it in GitHub Desktop.
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?
#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