10-08-2014
3,
0
Join Date: Oct 2014
Last Activity: 9 October 2014, 1:28 PM EDT
Posts: 3
Thanks Given: 0
Thanked 0 Times in 0 Posts
How to use EPOLLOUT exactly?
Hi, I'm wondering how one typically uses epoll for sending out data on a socket?
I have a server that listens on a socket in a thread that calls epoll_wait to receive data. Each time a new connection is opened, the new FD gets added to epoll. I am using EPOLLET by the way.
I have other threads that may want to send data on the connected clients. So when they do, they add their message to a thread-safe ring-buffer.
But when a message gets added in the ring-buffer, I need to wake up the epolling thread so that it can start emptying the buffer.
So what is the proper way that people usually do this?
1) upon adding data to the ringbuffer, add EPOLLOUT in the event, and remove it when the ringbuffer is empty (and if EAGAIN happens, then things will work out naturally) ?
2) set EPOLLOUT upon adding the FD, when adding data to the ringbuffer, send a signal to the other thread to wake him up and flush the ringbuffer (and if EAGAIN happens, then things will work out naturally)?
3) should I NOT use EPOLLET?
Any advice would be great. Thanks.