Reputation: 41
I'm using epoll to write large messages to a server using HTTP protocol. The fds are all set to non-blocking and I'm using edge-triggered events. I know for EPOLLIN I need to loop over reading the fd until EAGAIN is returned. For writing I am unsure if I should keep looping once I get EAGAIN or should I wait for epoll to notify when the fd is available for read again.
For instance, I am writing a 20K message, and on the first ::write attempt the amount of data sent = 13K. The next attempt to write returns a retVal = -1 and errno = EAGAIN.
At this point should I continue looping in a while(1) until I can write the data or should I wait for epoll to invoke my call back when the FD is ready for writing again. My understanding is that since the fd is registered for writing, epoll should notify me when the FD is ready for writing again. But that doesn't seem to be happening in my program.
Do I need to set a special flag or modify the FD to get the notification?
Upvotes: 4
Views: 3813
Reputation: 16718
At this point should I continue looping in a while(1) until I can write the data
No!
or should I wait for epoll to invoke my call back when the FD is ready for writing again.
Yes, you should (but what callback? epoll_wait
doesn't have a callback mechanism, it just returns)
My understanding is that since the fd is registered for writing, epoll should notify me when the FD is ready for writing again. But that doesn't seem to be happening in my program.
If the FD is registered with EPOLLOUT
or EPOLLIN | EPOLLOUT
, it should indeed. Could you provide a small example demonstrating the problem?
Upvotes: 7