Re: Timeouts on CFWriteStreams
Re: Timeouts on CFWriteStreams
- Subject: Re: Timeouts on CFWriteStreams
- From: Becky Willrich <email@hidden>
- Date: Thu, 6 Mar 2003 10:04:48 -0800
Unfortunately, this is all a little bit too unreliable for me. Since I
don't send great amount of data and have no keepalive or ack signal,
it takes too much time until I realize that the remote side has died;
I can still put quite a lot of data into the buffer until it is full.
Why do I get the kCFStreamEventCanAcceptBytes event at all, even
though no data could be written to the socket since the last time I
called CFWriteStreamWrite()? And why is the CFWriteStream in status
kCFStreamStatusOpen and not in status kCFStreamStatusWriting when I
receive kCFStreamEventCanAcceptBytes and the buffer is not yet empty?
CFNetwork is simply propagating the behavior you'd see if you were
writing to the socket directly - writes are considered done once the
bytes have been copied in to the kernel's internal buffers, but that
doesn't mean those bytes have gone out over the wire, yet. Because of
the way TCP works, it could be quite a while before the kernel realizes
that the remote side of an open socket has died. You are receiving
CanAcceptBytes events because there is still room in the kernel's
buffer, not because the other side is guaranteed ready to receive them,
and StatusWriting only occurs while actually copying bytes to the
kernel's buffer.
There are options you can set on sockets to reduce or "eliminate" the
kernel buffer (you can never truly eliminate the kernel's buffering,
but you can minimize it); those are available to you if you want to use
them. After opening the stream, get the native socket out of the
stream, and call setsockopt() and/or ioctl() to configure it as you
desire; a good book like UNIX Network Programming can show you all the
different options available.
Hope that helps,
REW
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.