Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Don't get "socket closed" on a 'recv' call when connection is lost...

3 views
Skip to first unread message

Freddan

unread,
Mar 7, 2003, 5:37:12 AM3/7/03
to
Hi,

When sending data over a TCP connection and removes the ethernet cable
from the computer, I don't get socket closed or some indication that the
socket has disconnected. I'm listen on the socket with the recv function.

If I send multiple data to the socket I can send until the TCP window is
full,
then the send will hang. I don't get any send failure...

Can I set some options so my socket will trigg on socket close and
disconnections?

Please help! I'm running linux Mandrake 8 and ReadHat 7.3.

Thanks in advance.

Greetings Fredrik.


Michael Fuhr

unread,
Mar 7, 2003, 10:09:26 AM3/7/03
to
"Freddan" <fredrik_...@hotmail.com> writes:

> When sending data over a TCP connection and removes the ethernet cable
> from the computer, I don't get socket closed or some indication that the
> socket has disconnected. I'm listen on the socket with the recv function.

The socket hasn't been disconnected -- the ethernet cable has been
disconnected. TCP was designed to continue working in the face of
intermittent network outages.

> If I send multiple data to the socket I can send until the TCP window is
> full,
> then the send will hang. I don't get any send failure...

What makes you think you should get a send failure? TCP doesn't
know how long the outage will last, so it doesn't close the
connection at the first sign of trouble.

> Can I set some options so my socket will trigg on socket close and
> disconnections?

The socket hasn't been closed, and a network outage should NOT
automatically cause a TCP connection to close. TCP was designed
to handle packet loss and it has no way of knowing whether the
network will come back up in 5 seconds or if it will never come
back up.

If you want to close a connection when there appear to be network
problems, then consider adding a timeout mechanism to your program.
You can use select() or poll() for this, and you might want to
consider using non-blocking I/O.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

Freddan

unread,
Mar 12, 2003, 7:26:13 AM3/12/03
to

> The socket hasn't been disconnected -- the ethernet cable has been
> disconnected. TCP was designed to continue working in the face of
> intermittent network outages.
Yes, thats correct... I want to get "trigged" when the LINK ethernet
connection is lost, is this posssible? To catch when network cable gets
disconnected?

> What makes you think you should get a send failure? TCP doesn't
> know how long the outage will last, so it doesn't close the
> connection at the first sign of trouble.

Correct, but I want to get a send failure if the computer is not connected
to the network, I don't want to interfere with the specific TCP protocol
handling such as congestion control and so... I get this send failure when
the socket times out, so its alright...

> The socket hasn't been closed, and a network outage should NOT
> automatically cause a TCP connection to close. TCP was designed
> to handle packet loss and it has no way of knowing whether the
> network will come back up in 5 seconds or if it will never come
> back up.

Yes, but the OS will close the socket after around 10-20 minutes, can I
change this timeout interval?

Thanks,
Fredrik.


0 new messages