I\'m currently adding sockfds created from accept to an epoll instance with the following events:
const int EVENTS = (
EPOLLET |
EPOLLIN |
EPOLLR
However, I only receive the EPOLLIN event one time. Also, if I kill the client anytime after the first event is received, I do not get hangup events either.
man page for epoll_ctl(2) says that:
EPOLLONESHOT (since Linux 2.6.2) Sets the one-shot behavior for the associated file descriptor. This means that after an event is pulled out with epoll_wait(2) the associated file descriptor is internally disabled and no other events will be reported by the epoll interface. The user must call epoll_ctl() with EPOLL_CTL_MOD to rearm the file descriptor with a new event mask.
In your case, when you get the first event, epoll disables your sockfd.
When you re-enable your sockfd using EPOLL_CTL_MOD
, it will notify all the events that are received by kernel after the re-registration. So any event between first notification and re-registration will be lost. This can be reason for not getting any hangup events or data.
Removing EPOLLONESHOT
from events will correct your code, eventually you don't need to re-enable sockfd also.
And since you are using EPOLLET
, there won't be any performance issue also.