After the accept()
on a socket, I\'m trying to configure the TCP keepalive.
SockConnected = accept(SockListen, &RemoteAddr,
&
SO_KEEPALIVE
should be used with SOL_SOCKET
, not IPPROTO_TCP
or SOL_TCP
. See socket(7) and tcp(7).
So try this:
int val = 1;
setsockopt(SockConnected, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val));
I guess TCP_KEEPIDLE
and similar options are just ignored if SO_KEEPALIVE
was not set correctly, and SOL_TCP
is a synonym for IPPROTO_TCP
.
If it does not help, consider posting a minimal example that reproduces the problem.