crash network and consequent state of socket

352 Views Asked by At

I would like to know how do the state of a socket become when the network on which it work crashes. My problem is when I simulate the collapse of this network the select() function, that controls all socket, returns me some socket that theoretically should not be set. It's possible that the operating system set a crashed socket both in writing and in reading?

2

There are 2 best solutions below

3
On BEST ANSWER

The first thing to keep in mind is that your computer typically will not know when the "network crashes" per se. All the computer will know is whether or not it is receiving packets from the network, or not. (Some computers might also know if the electrical signal on their local Ethernet port has gone away, but since it is possible for more distant parts of the network to go down without affecting the signal on the local Ethernet cable, that information is only occasionally useful).

In practice, if the network between your computer and (the computer it was talking to) stops working, you'll see the following effects:

(1) Any UDP packets you send will be dropped without a trace, and usually without any error indication. And of course you won't receive any UDP packets from the remote peer either.

(2) Data traffic on any TCP connection between your computer and the remote peer will grind quickly to a halt. After a certain timeout period (usually several minutes) has elapsed without the OS receiving any responses from the remote peer, the operating system will "give up" and mark the TCP connection as closed; at which point you will see behavior identical to what you would get if the remote peer had deliberately closed the connection: that is, select() will return ready-for-read (and possibly ready-for-write also, I forget), and then when you try to actually do a recv() or read() on the socket, you will get an EOF (i.e. recv() on a blocking socket will return 0; recv() on a non-blocking socket will return -1). (if the network recovers before the timeout completes, then TCP traffic on your socket will resume, although it will start resuming slowly and gradually speed up again over time)

0
On

Your description is unclear, but it is possible that the select() is signalling an EOS on the socket concerned, which wouldn't represent a network 'crash' but an orderly close by the peer, possibly unexpected by you.