Re: Posted read() hangs on socket disconnect
Re: Posted read() hangs on socket disconnect
- Subject: Re: Posted read() hangs on socket disconnect
- From: Jonathon Kuo <email@hidden>
- Date: Wed, 27 May 2009 17:07:08 -0700
On May 27, 2009, at 5:02 PM, Vincent Lubet wrote:
On May 27, 2009, at 4:49 PM, Jonathon Kuo wrote:
On May 27, 2009, at 4:46 PM, Jens Alfke wrote:
On May 27, 2009, at 4:32 PM, Jonathon Kuo wrote:
The receiving process uses a read() posted on a socket that reads
small data packets in a loop. It works fine until the sender
quits (disconnects/aborts). I was expecting the posted read()
call to return with a status < 0, but it never returns, it just
hangs forever.
If the sending process closes the socket, exits or crashes, then
the socket will be closed on the receiving end too. I would think
the read call would return immediately, with errno==ECONNRESET,
but I'm somewhat sketchy on the low-level POSIX network APIs.
On the other hand, if the sending machine is abruptly disconnected
(Ethernet unplugged, power failure, kernel panic...) then the
receiver never gets notified that the connection's closed, and so
it will end up waiting for a very long time, like 90 minutes,
before giving up and deciding the socket's closed.
Yes, this seems to be what I'm seeing. I was hoping that there
might be some sort of Mac networking framework I could use as an
alternate to the low level read() call that would catch this
condition?
What does you loop do when read() returns 0?
A return value of 0 means the peer has closed it the connection.
The problem is that the read() doesn't return at all in this case --
it just hangs, preventing the sender from reconnecting since I can't
close() the socket and reestablish it.
_______________________________________________
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