In my C++ application I’m using the recv function in a loop.
I want to identify a network connection issue by getting a negative value from recv function.
The one thing I can see in my tests is that when I’m getting off the network cable, I can wait for ~minute till I can see that my application got this negative value.
Do you know what is the time duration for the C++ code to know that a network connection issue occur? Can I manage this time?
There’s no sane way of doing this on the TCP-only level. The option that was intended for this is
SO_KEEPALIVE, but it’s pretty useless.Implement application-level heartbeats and mark the socket disconnected when no data or heartbeat was received within specified time (this pretty much assumes non-blocking mode, or at least a
select(2)loop with timeout).