I have a network client library that I’m putting together that reads/writes to some network sockets.
There is a single thread that does the network I/O and responds to requests from the exposed client API. Those client API requests are to be popped off a FIFO queue.
In order for the thread to get at the request, when my main loop is blocked on epoll_wait
I am thinking I should use an eventfd which I can add with epoll_ctl.
So the question is how can I distinguish between an event pushed onto my FIFO queue and network I/O if epoll just notifies with EPOLLIN?
EDIT:
I should add that I am not wanting to store the event fd in the data member, but rather use the ptr member. I suppose I need to store the fd somewhere inside that structure.
Can I simply check to see if the triggered event = my event file descriptor and therefore read from my fifo as well, and if it’s not equal then it must be a network event? Is this safe? or is there a best practice approach.
Yes you have to compare the file descriptors. The example in the manual page does this.