5 written by Stefan Metzmacher <metze@samba.org>
7 this code calls epoll_wait() in a endless loop with a
8 timeout of 1000 = 1s, before the loop we add one event
9 to epoll via epoll_ctl(EPOLL_CTL_ADD), we add it with an event mask
10 of 0, so we don't request notification for any events!
12 this test demonstrates that we'll get an EPOLLHUP notification,
13 when the fd was closed by the other end of the pipe/socket
15 this programm used the stdin (fd=0).
18 (sleep 5 &) | ./epoll_test
22 struct epoll_event event;
26 struct epoll_event events[MAXEVENTS];
29 epoll_fd = epoll_create(64);
33 memset(&event, 0, sizeof(event));
35 event.data.fd = socket_fd;
36 ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, socket_fd, &event);
37 printf("epoll_ctl:ADD: %d\n", ret);
40 ret = epoll_wait(epoll_fd, events, MAXEVENTS, 1000);
41 if (ret == -1 && errno != EINTR) {
44 printf("epool_wait: ret[%d] errno[%d]\n",ret, errno);
47 printf("event i[%d] fd[%d] events[0x%08X]", i, events[i].data.fd, events[i].events);
48 if (events[i].events & EPOLLIN) printf(" EPOLLIN");
49 if (events[i].events & EPOLLHUP) printf(" EPOLLHUP");
50 if (events[i].events & EPOLLERR) printf(" EPOLLERR");
51 if (events[i].events & EPOLLOUT) printf(" EPOLLOUT");