Doing synchronous writes from a stream's callback
Doing synchronous writes from a stream's callback
- Subject: Doing synchronous writes from a stream's callback
- From: Frederick Cheung <email@hidden>
- Date: Fri, 13 May 2005 19:01:38 +0100
The situation is a pair of read/write streams, both arising from the
same socket. this socket was created in response to an incoming
connection.
The read stream is scheduled with the runloop and has a callback
installed, but the write stream does not, mainly because I am only
sending out small bits of data (usually 100-200 bytes of data,
basically some sort of status reply to the client's request)
I am pretty sure this didn't happen in panther (or if it did,
infrequently enough for me not to notice), but on tiger if I call
CFWriteStreamWrite from the read stream callback (usually in a
kCFStreamEventHasBytesAvailable), it quite frequently blocks for an
extended period of time (a minute or 2) before returning -1 (and
CFStreamGetError reveals that the error is ETIMEDOUT) . This happens
almost systematically when I have several server threads running,
each dealing with an almost simultaneous request.
I was able to solve the problem by making the write stream
asynchronous and writing from the write stream's callback if
CFWriteStreamCanAcceptBytes is false.
What i was wondering was why CFWriteStreamWrite takes so long to
time out when called from the read stream callback (and indeed why it
is timing out, sending a 100 bytes on a gigabit lan should not be
hard), and why I did not observe this behaviour on panther. Is one
not supposed to do this kind of thing from the read callback (ie.
have I been lucky not to see this before) or is this exposing a bug
in CFNetwork?
Fred
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden