Le 1/7/13 5:35 PM, Hallvard Breien Furuseth a écrit :
Howard Chu writes:
We listen for writable sockets if a write attempt returns incomplete. There's a pair of mutexes and condition variables used to synch up here between the writing threads and the listener thread. It's quite a lot of lock overhead. As far as I can tell the main reason we do this is so that we can stop a writer thread on demand instead of having it just block forever in write().
slapd seems to use non-blocking socket descriptors if it can, so it's rather that write() to a full socket would otherwise do a busy loop write()ing 0 bytes until there was room.
If you try to write to a full socket, you'll get a 0 as a result to a write attempt, and then, you will have to enqueue the data and set the write_op type so that epoll_wait wakes up when the socket is ready.
When the socket is ready for write, the thread will check the queue, and will try to empty it. If it succeeds, the write_op is unset and you are done. Otherwise, the socket is bloked again, and you enter in a new wait. Of course, never forget to unset the write_op flag, otherwise the epoll_wait() will exit immediately, and you'll get a busy loop again...