What Is a Socket Timeout?
A specific period of time allowed before a particular event in the system occurs. For example, when dialing into the ISP, the communication software is designed to wait for a specific number of seconds. If no response is obtained within the prescribed time and a correct handshake signal is established, the dialing is suspended. In addition, when a request is made to enter a Web page, if it cannot be met within the specified time, the browser will display a "connection timeout" message. If the computer does not have such a function, it will wait for an event to occur, and when the user is impatient, it is still waiting, it is not appropriate. [1]
- Timeout is when the network device wants to connect to another network device within a certain time.
- In many cases, retransmissions may occur even if no data loss occurs. This unnecessary retransmission is called spurious retransmission. The main cause is spurious timeout, that is, premature determination of timeout. Other factors such as packet out-of-order, packet duplication, or ACK loss may also cause The phenomenon. When the actual RTT increases significantly and exceeds the current RTO, a pseudo timeout may occur. This situation occurs more frequently in environments where the performance of the underlying protocols varies greatly (such as wireless environments).
- Many methods have been proposed for dealing with pseudo timeouts. These methods usually include a detection algorithm and a response algorithm. The detection algorithm is used to judge whether a certain timeout or timer-based retransmission is real. Once a false timeout is determined to occur, a response algorithm is executed to cancel or mitigate the impact of the timeout. [3]
- When any fragment of a datagram arrives first, the IP layer must start a timer. If you do not do this, the unreachable shards (as shown on the right) may eventually cause the receiver to run out of cache, leaving an opportunity for attack. The example in the list is generated by a special program that constructs an ICMPv4 echo request message and sends it only with a certain delay.
- Datagram socket communication is unreliable and data sent may be lost. If the datagram is lost, the message will not reach the service and the service will not return an answer. In this case, the program will wait indefinitely on the recvfrom0 call. In addition, there are also infinite blocking situations for streaming socket connections and I / O. To avoid this infinite waiting, we need to set a timeout for I / O operations involving the socket. When the time slice runs out, either resend the message or close the socket and exit execution. There are three ways to set the timeout:
- (1) Call alrm () to make the system generate SIGALRM signal when the specified time slice expires.
- (2) Use select () to establish a time slice and wait for the socket to be ready.
- (3) Use SO-RCVTIMEO and SO-SNDTIMEO socket options, these two options automatically set timeout processing for socket read and write.
- These three methods can be used for both input and output. [5]