• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Posted read() hangs on socket disconnect
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Posted read() hangs on socket disconnect (From: Jonathon Kuo <email@hidden>)
 >Re: Posted read() hangs on socket disconnect (From: Jens Alfke <email@hidden>)
 >Re: Posted read() hangs on socket disconnect (From: Jonathon Kuo <email@hidden>)
 >Re: Posted read() hangs on socket disconnect (From: Jens Alfke <email@hidden>)
 >Re: Posted read() hangs on socket disconnect (From: Jonathon Kuo <email@hidden>)

  • Prev by Date: Re: Posted read() hangs on socket disconnect
  • Next by Date: FW: copy some kernel extensions to /tmp directory and then load that kext when program Launches
  • Previous by thread: Re: Posted read() hangs on socket disconnect
  • Next by thread: Re: Posted read() hangs on socket disconnect
  • Index(es):
    • Date
    • Thread