asynchronous socket writing
minfrin at sharp.fm
Fri Mar 12 17:07:37 CET 2010
On 12 Mar 2010, at 5:49 PM, Jonas H. wrote:
> How on earth can I get the 'you-can-now-write' event for another
> client/request/whatever while writing to another client the same time?
You don't, thus the importance of everything you do being non blocking.
> Is this something libev handles for you? Splitting up big writes
> into smaller ones, giving other clients a chance to be written to
> after each part?
This isn't something that libev could handle for you, you have just a
single thread of execution, and libev - and your code - can only do
one thing at a time (obviously we're talking the no-threads case here).
Typically you set up one event for every connection you are monitoring
(or possibly two events, one for read, one for write), and then wait
to be called to be told "ready". libev gives you the option to pass
additional information along with event call, where you have
previously saved any handles and other state information you might
need to process the request.
When you're told "this socket is ready for write", all it's telling
you is that you are ready to write once. If you want to write a second
time, you need to return, and then wait to be called again to confirm
the os is ready for your second write, and third, and so on until you
have nothing left to write.
Does that make sense (and am I understanding you correctly?)
More information about the libev