[bug-004] [tcp] after the network is disconnected and reconnected, the client recv function blocks all the time and does not return
[premise] the client uses tcp blocking mode
[phenomenon] after establishing a connection with the camera equipment, there are occasional times when the data sent by the camera cannot be received; after several investigations, it is suspected that it has something to do with the network fluctuation, so the network fluctuation is simulated by plugging in the network cable, and sure enough, the bug reappears.
[analysis] Why does the network interrupt tcp not actively notify the application? This involves a design principle of the TPC/IP protocol, that is, terminal-to-terminal parameters. What do you mean? It is up to the caller to choose whether this function is needed, and if so, the caller sets the appropriate parameters themselves, rather than timely feedback as soon as tcp detects a network outage, because most applications do not need immediate notification.
Ps: we should also consider this principle when designing our own interfaces.
[solution]
1. Switch to non-blocking mode
2. Blocking + keeping alive.
In this way, the return value of the function can be used to determine whether a reconnection is needed.