I’m using epoll to get notifications about incoming data. It’s not hard because all events returned by epoll_wait() indicates, that I can read data from epoll_event.data.fd (socket descriptor).
But now I want get both types of notification: receiving and sending (socket is available for send). But I can’t to do it because:
epoll_event.eventswhich is returned byepoll_wait()is the same as I pass inepoll_ctl(). So it contains bothEPOLLINandEPOLLOUTin my case.- Also if i trying to twice add one socket in
epoll(as EPOLLIN and as EPOLLOUT event) I’ll get aEEXIST.
How can I solve this problem without manually calling select() every time I get notification?
man epoll_waitclearly states that “the events member will contain the returned event bit field.”. Therefore, if you are gettingEPOLLIN | EPOLLOUTinepoll_event.events, then your socket must be ready for both reading and writing.If you only want to be notified when the socket changes state, use
EPOLLETfor edge-triggered operation.