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.
> 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/
> 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.