Created
October 15, 2013 06:15
-
-
Save nelhage/6987264 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <unistd.h> | |
#include <sys/epoll.h> | |
#include "lib.h" | |
#define DEPTH 6 | |
#define FANOUT 1000 | |
void add_many(int parent, int child) { | |
int i; | |
int fds[FANOUT]; | |
struct epoll_event evt = { .events = EPOLLIN }; | |
for (i = 0; i < FANOUT; i++) { | |
if ((fds[i] = dup(child)) < 0) | |
die_errno("dup"); | |
if (epoll_ctl(parent, EPOLL_CTL_ADD, fds[i], &evt) < 0) | |
die_errno("add"); | |
} | |
for (i = 0; i < FANOUT; i++) | |
close(fds[i]); | |
} | |
int main(void) { | |
int fds[DEPTH]; | |
int i; | |
int p[2]; | |
struct epoll_event evt = { .events = EPOLLIN }; | |
for (i = 0; i < DEPTH; i++) { | |
if ((fds[i] = epoll_create(1)) < 0) | |
die_errno("create"); | |
} | |
for (i = 1; i < DEPTH; i++) { | |
add_many(fds[i-1], fds[i]); | |
} | |
if (pipe(p) < 0) | |
die_errno("pipe"); | |
epoll_ctl(fds[DEPTH-1], EPOLL_CTL_ADD, p[0], &evt); | |
write(p[1], p, sizeof(int)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment