openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/rsyslog/8.1903.0-r0/rsyslog-8.1903.0/runtime/nsd_ptcp.c
static rsRetVal EnableKeepAlive(nsd_t* pNsd)
{
    nsd_ptcp_t* pThis = (nsd_ptcp_t*)pNsd;
    int ret;
    int optval;
    socklen_t optlen;
    DEFiRet;
    ISOBJ_TYPE_assert(pThis, nsd_ptcp);

    optval = 1;
    optlen = sizeof(optval);
    ret = setsockopt(pThis->sock, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen);
    if (ret < 0)
    {
        dbgprintf("EnableKeepAlive socket call returns error %d\n", ret);
        ABORT_FINALIZE(RS_RET_ERR);
    }

#if defined(IPPROTO_TCP) && defined(TCP_KEEPCNT)
    if (pThis->iKeepAliveProbes > 0)
    {
        optval = pThis->iKeepAliveProbes;
        optlen = sizeof(optval);
        ret =
            setsockopt(pThis->sock, IPPROTO_TCP, TCP_KEEPCNT, &optval, optlen);
    }
    else
    {
        ret = 0;
    }
#else
    ret = -1;
#endif
    if (ret < 0)
    {
        LogError(ret, NO_ERRCODE,
                 "imptcp cannot set keepalive probes - ignored");
    }

#if defined(IPPROTO_TCP) && defined(TCP_KEEPIDLE)
    if (pThis->iKeepAliveTime > 0)
    {
        optval = pThis->iKeepAliveTime;
        optlen = sizeof(optval);
        ret =
            setsockopt(pThis->sock, IPPROTO_TCP, TCP_KEEPIDLE, &optval, optlen);
    }
    else
    {
        ret = 0;
    }
#else
    ret = -1;
#endif
    if (ret < 0)
    {
        LogError(ret, NO_ERRCODE, "imptcp cannot set keepalive time - ignored");
    }

#if defined(IPPROTO_TCP) && defined(TCP_KEEPCNT)
    if (pThis->iKeepAliveIntvl > 0)
    {
        optval = pThis->iKeepAliveIntvl;
        optlen = sizeof(optval);
        ret = setsockopt(pThis->sock, IPPROTO_TCP, TCP_KEEPINTVL, &optval,
                         optlen);
    }
    else
    {
        ret = 0;
    }
#else
    ret = -1;
#endif
    if (ret < 0)
    {
        LogError(errno, NO_ERRCODE,
                 "imptcp cannot set keepalive intvl - ignored");
    }

    dbgprintf("KEEPALIVE enabled for socket %d\n", pThis->sock);

finalize_it:
    RETiRet;
}
/* Enable KEEPALIVE handling on the socket.
 * rgerhards, 2009-06-02
 */
Enable KEEPALIVE handling on the socket.
Enable KEEPALIVE handling on the socket .
static rsRetVal EnableKeepAlive(nsd_t* pNsd)
{
    nsd_ptcp_t* pThis = (nsd_ptcp_t*)pNsd;
    int ret;
    int optval;
    socklen_t optlen;
    DEFiRet;
    ISOBJ_TYPE_assert(pThis, nsd_ptcp);
    optval = 1;
    optlen = sizeof(optval);
    ret = setsockopt(pThis->sock, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen);
    if (ret < 0)
    {
        dbgprintf("EnableKeepAlive socket call returns error %d\n", ret);
        ABORT_FINALIZE(RS_RET_ERR);
    }
#if defined(IPPROTO_TCP) && defined(TCP_KEEPCNT)
    if (pThis->iKeepAliveProbes > 0)
    {
        optval = pThis->iKeepAliveProbes;
        optlen = sizeof(optval);
        ret =
            setsockopt(pThis->sock, IPPROTO_TCP, TCP_KEEPCNT, &optval, optlen);
    }
    else
    {
        ret = 0;
    }
#else
    ret = -1;
#endif
    if (ret < 0)
    {
        LogError(ret, NO_ERRCODE,
                 "imptcp cannot set keepalive probes - ignored");
    }
#if defined(IPPROTO_TCP) && defined(TCP_KEEPIDLE)
    if (pThis->iKeepAliveTime > 0)
    {
        optval = pThis->iKeepAliveTime;
        optlen = sizeof(optval);
        ret =
            setsockopt(pThis->sock, IPPROTO_TCP, TCP_KEEPIDLE, &optval, optlen);
    }
    else
    {
        ret = 0;
    }
#else
    ret = -1;
#endif
    if (ret < 0)
    {
        LogError(ret, NO_ERRCODE, "imptcp cannot set keepalive time - ignored");
    }
#if defined(IPPROTO_TCP) && defined(TCP_KEEPCNT)
    if (pThis->iKeepAliveIntvl > 0)
    {
        optval = pThis->iKeepAliveIntvl;
        optlen = sizeof(optval);
        ret = setsockopt(pThis->sock, IPPROTO_TCP, TCP_KEEPINTVL, &optval,
                         optlen);
    }
    else
    {
        ret = 0;
    }
#else
    ret = -1;
#endif
    if (ret < 0)
    {
        LogError(errno, NO_ERRCODE,
                 "imptcp cannot set keepalive intvl - ignored");
    }
    dbgprintf("KEEPALIVE enabled for socket %d\n", pThis->sock);
finalize_it:
    RETiRet;
}
static rsRetVal EnableKeepAlive ( nsd_t * pNsd ) { nsd_ptcp_t * pThis = ( nsd_ptcp_t * ) pNsd ; int ret ; int optval ; socklen_t optlen ; DEFiRet ; ISOBJ_TYPE_assert ( pThis , nsd_ptcp ) ; optval = 1 ; optlen = sizeof ( optval ) ; ret = setsockopt ( pThis -> sock , SOL_SOCKET , SO_KEEPALIVE , & optval , optlen ) ; if ( ret < 0 ) { dbgprintf ( " \n " , ret ) ; ABORT_FINALIZE ( RS_RET_ERR ) ; } #if defined ( IPPROTO_TCP ) && defined ( TCP_KEEPCNT ) if ( pThis -> iKeepAliveProbes > 0 ) { optval = pThis -> iKeepAliveProbes ; optlen = sizeof ( optval ) ; ret = setsockopt ( pThis -> sock , IPPROTO_TCP , TCP_KEEPCNT , & optval , optlen ) ; } else { ret = 0 ; } #else ret = -1 ; #endif if ( ret < 0 ) { LogError ( ret , NO_ERRCODE , " " ) ; } #if defined ( IPPROTO_TCP ) && defined ( TCP_KEEPIDLE ) if ( pThis -> iKeepAliveTime > 0 ) { optval = pThis -> iKeepAliveTime ; optlen = sizeof ( optval ) ; ret = setsockopt ( pThis -> sock , IPPROTO_TCP , TCP_KEEPIDLE , & optval , optlen ) ; } else { ret = 0 ; } #else ret = -1 ; #endif if ( ret < 0 ) { LogError ( ret , NO_ERRCODE , " " ) ; } #if defined ( IPPROTO_TCP ) && defined ( TCP_KEEPCNT ) if ( pThis -> iKeepAliveIntvl > 0 ) { optval = pThis -> iKeepAliveIntvl ; optlen = sizeof ( optval ) ; ret = setsockopt ( pThis -> sock , IPPROTO_TCP , TCP_KEEPINTVL , & optval , optlen ) ; } else { ret = 0 ; } #else ret = -1 ; #endif if ( ret < 0 ) { LogError ( errno , NO_ERRCODE , " " ) ; } dbgprintf ( " \n " , pThis -> sock ) ; finalize_it : RETiRet ; }
Enable KEEPALIVE handling on the socket.
Enable KEEPALIVE handling on the socket .