Configuring TCP keepalive after accept

前端 未结 2 592
迷失自我
迷失自我 2021-02-05 21:53

After the accept() on a socket, I\'m trying to configure the TCP keepalive.

SockConnected = accept(SockListen, &RemoteAddr,
                   &         


        
2条回答
  •  花落未央
    2021-02-05 22:35

    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.

提交回复
热议问题