1

Let's say I epoll_create1() and only interest in EPOLLIN | EPOLLET for 1 socket.

Is it possible that I will get epoll_wait() > 1 (assuming timeout=-1) for that socket and the event is EPOLLIN?

Or will epoll_wait() return 1 even there are multiple packets (let's say spread over few sec that I pause the program on purpose in the epoll_wait loop)?

Thanks in advance.

Hei
  • 1,844
  • 3
  • 21
  • 35
  • With edge-triggered mode you have to be particularly careful to drain the file descriptor for each event type that fired, or you won't see future events. – Kerrek SB Aug 10 '13 at 14:29

2 Answers2

2

epoll_wait returns the number of events, which according to the documentation equals the "number of file descriptors ready for I/O". So you cannot get more events than the number of file descriptors you have registered.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • If the socket has some data ready and then gets disconnected, epoll_wait() will first return 1 with event=EPOLLIN and then the next epoll_wait() will return 1 with event=EPOLLRDHUP? In other words, epoll_wait() won't return 2 for the same file descriptor but 2 different events? – Hei Aug 11 '13 at 06:19
  • @Hei: Good question. Maybe [see this question](http://stackoverflow.com/q/6437879/596781). The manual says that events are combined, so perhaps you should check for readability as well as for hup. – Kerrek SB Aug 11 '13 at 12:11
1

According to these docs for epoll_wait it should return the number of fd's that are "ready". If you only pass in one fd, then you should not get more than 1 back - that would certainly be a bug in the epoll_wait implementation, and it's been around for a while, so I expect it's fairly well tested (unless you are working on a completely new architecture or a beta-version of a C library or some such).

Also, timeout = 0, not -1.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227