Re: Posted read() hangs on socket disconnect
Re: Posted read() hangs on socket disconnect
- Subject: Re: Posted read() hangs on socket disconnect
- From: Quinn <email@hidden>
- Date: Thu, 28 May 2009 10:07:56 +0100
At 17:09 -0700 27/5/09, Jonathon Kuo wrote:
Thanks, Jens, that's very informative. Would this be a good
candidate case for using select()? I'm expecting new incoming
packets about 30 per second.
In this situation select() will report that there's no data
available, for exactly the same reason that read() is stuck: the
kernel doesn't know that the other end is gone. However, with
select() you can apply your own timeout. You have to choose a
timeout value that's appropriate for your situation; the kernel tends
to be very conservative in this regard. One option is for you to not
disconnect on timeout, but message the remote peer on timeout. If
the kernel is actively trying to send data down the TCP stream and
failing, that will trigger a disconnect relatively quickly.
You can do similar things with Mac OS X's high-level frameworks
(things like CFSocketStream) but if you're already working with
sockets there's really no benefit to using them. The root cause of
this problem is below you.
S+E
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
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