For the impatient:
How to change the value of /proc/sys/net/ipv4/tcp_retries2
for a single connection in Linux, using setsockopt()
After some thinking (and googling), I came to the conclusion that you can't change tcp_retries1
and tcp_retries2
value for a single socket unless you apply some sort of patch to the kernel. Is that feasible for you?
Otherways, you could use TCP_KEEPALIVE
socket option whose purpose is to check if a connection is still active (it seems to me that that's exactly what you are trying to achieve, so it has sense). Pay attention to the fact that you need to tweak its default parameter a little, because the default is to disconnect after about 2 hrs!!!