This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SO_KEEPALIVE not working.

Dear all,

I'm maintaining an application with CSS 2.20.0. A network server has been implemented. To check if the socket connection with the client is down or not, the option SO_KEEPALIVE is enabled in the socket:

int optval; optval = 1;
if (setsockopt(stcpactive, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)) < 0)
{
  return -1;  
}

However, if I unplug the Ethernet wire when a connection is established,  no error is detected from network: the program doesn't exit the fdSelect call to read a byte from socket to detect that the connection is broken. Also I've check that the keepalive time interval is configured in _ipcfg.RtKeepAliveTime.

Is the SO_KEEPALIVE option implemented? How can I change the RtKeepAliveTime?

 

Thanks and Best Regards,

Joaquim Duran

 

  • Joaquim,

    How long did you have the network cable unplugged for?

    Have you seen these options?

    _ipcfg.TcpKeepIntvl

    Keep Probe Interval (0.1 Sec Units)
    Default Value 750 (75 seconds)
    Description This parameter only affects sockets that have specified the SO_KEEPALIVE socket
    option. It specifies the time between probe intervals once TCP begins sending KEEP
    probes.


    _ipcfg.TcpKeepMaxIdle Keep Probe Timeout (0.1 Sec Units)
    Default Value 6000 (10 minutes)
    Description This parameter only affects sockets that have specified the SO_KEEPALIVE socket
    option. It is the time the TCP will continue to send unanswered KEEP probes before
    timing out the connection.

    You may want to try playing around with these settings, as well as RtKeepAliveTime.  You can change these in your stack thread function.

    For example, I tested out modifying one value of the _ipcfg struct as follows:

    #include <stkmain.h>

    #include <stdio.h>

    int StackTest()
    {
        int               rc;
        HANDLE            hCfg;
        CI_SERVICE_TELNET telnet;
        CI_SERVICE_HTTP   http;

        printf("****** ip config: %d\n", _ipcfg.TcpKeepIntvl);


        _ipcfg.TcpKeepIntvl += 1;


        printf("****** ip config after: %d\n", _ipcfg.TcpKeepIntvl);

        //
        // THIS MUST BE THE ABSOLUTE FIRST THING DONE IN AN APPLICATION!!
        //
        rc = NC_SystemOpen( NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT );

    ....

     

    Steve

  • Steve,

    Thanks for your answer. Sorry for the delay in answering your post, but these days I've been on holidays and  I has been impossible.

    > How long did you have the network cable unplugged for?

    More than 20 minutes.

     

    I couldn't execute the red lines of your code because the _ipcfg struct hasn't TcpKeepMaxIdle  nor TcpKeepIntvl fields. I include the definition of _ipcfg struct:

    typedef struct _ipconfig {
    uint IcmpDoRedirect; // Update RtTable on ICMP redirect (1=Yes)
    uint IcmpTtl; // TTL for ICMP messages RFC1700 says 64
    uint IcmpTtlEcho; // TTL for ICMP echo RFC1700 says 64
    uint IpIndex; // IP Start Index
    uint IpForwarding; // IP Forwarding (1 = Enabled)
    uint IpNatEnable; // IP NAT Enable (1 = Yes)
    uint IpFilterEnable; // IP Filtering Enable (1 = Yes)
    uint IpReasmMaxTime; // Max reassembly time in seconds
    uint IpReasmMaxSize; // Max reassembly packet size
    uint IpDirectedBCast; // Look for directed BCast IP addresses
    uint TcpReasmMaxPkt; // Max reasm pkts held by TCP socket
    uint RtcEnableDebug; // Enable Route Control Messages (1=On)
    uint RtcAdvTime; // Time in sec to send RtAdv (0=don't)
    uint RtcAdvLife; // Litetime of route in RtAdv
    int RtcAdvPref; // Preference Level (signed) in RtAdv
    uint RtArpDownTime; // Time 5 failed ARPs keep Rt down (sec)
    uint RtKeepaliveTime; // VALIDATED route timeout (sec)
    uint RtCloneTimeout; // INITIAL route timeout (sec)
    uint RtDefaultMTU; // Default MTU for internal routes
    uint SockTtlDefault; // Default Packet TTL
    uint SockTosDefault; // Default Packet TOS
    int SockMaxConnect; // Max Socket Connections
    uint SockTimeConnect; // Max time to connect (sec)
    uint SockTimeIo; // Default Socket IO timeout (sec)
    int SockTcpTxBufSize; // TCP Transmit buffer size
    int SockTcpRxBufSize; // TCP Receive buffer size (copy mode)
    int SockTcpRxLimit; // TCP Receive limit (non-copy mode)
    int SockUdpRxLimit; // UDP Receive limit
    int SockBufMinTx; // Min Tx space for "able to write"
    int SockBufMinRx; // Min Rx data for "able to read"
    uint PipeTimeIo; // Default Pipe IO timeout (sec)
    int PipeBufSize; // Pipe internal buffer size
    int PipeBufMinTx; // Min Tx space for "able to write"
    int PipeBufMinRx; // Min Rx data for "able to read"
    } IPCONFIG;

    extern IPCONFIG _ipcfg; // Configuration

     

    Thanks and Best Regards,

    Joaquim Duran