How to get underlying TCP socket from BSD socket?

Hello.

I am adding TCP-Keepalives to an existing project using BSD sockets. It seems that setting the TCP connection/idle timeout is only possible for TCP API Sockets using netTCP_SetOption() but not for BSD Sockets. (Other than the default setting in Net_Config_TCP.h.)

Since BSD Sockets are implemented on top of the UDP and TCP Socket APIs, (how) can I get the underlying native TCP connection socket from a BSD connection socket?

From Can I use both TCP native sockets and BSD sockets? I glean that I should not use "mixed" native TCP and BSD API functions on the same connection. So I would just like to set the timeout and then forget about the TCP native Socket. - Would that be fine?

Parents
  • You can activate the TCP keepalives in BSD sockets with the setsockopt() function. There is no need to search for the underlying native TCP connection socket. Use the following code:

    int32_t enable = 1;
    
    setsockopt (sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&enable, sizeof (enable));

    The documentation for the function setsockopt() can be found here.

Reply
  • You can activate the TCP keepalives in BSD sockets with the setsockopt() function. There is no need to search for the underlying native TCP connection socket. Use the following code:

    int32_t enable = 1;
    
    setsockopt (sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&enable, sizeof (enable));

    The documentation for the function setsockopt() can be found here.

Children