一旦在套接字上配置了Keepalive参数(TCP_KEEPIDLE,TCP_KEEPCNT,TCP_KEEPINTVL),即使在修改时也保留较早的值

时间:2019-05-10 05:33:03

标签: c tcp-keepalive

我正在尝试在与Linux上的客户端和Windows上的服务器的套接字连接上配置keepalive配置。我发现每30秒设置一次SO_KEEPALIVE = 1, TCP_KEEPIDLE=30sec, keepalive_count = 3, keepalive_interval = 20成功执行keepalive。然后,我想更改上述参数以采用不同的值,例如TCP_KEEPIDLE = 60 sec,但我一直仅在30秒时看到keepalive。如果需要重新配置连接上的这些参数还有其他线索吗?

int option = 1;
int keepalive_time = 30;
int keepalive_count = 3;
int keepalive_interval = 20;

if(setsockopt(CreateSocket , SOL_SOCKET, SO_KEEPALIVE, (char *)&option, sizeof(option)) == -1)
{
    printf("\n setsockopt SO_KEEPALIVE retuened -1 !!!");
                    // ignore this error
}

if(setsockopt(CreateSocket, IPPROTO_TCP, TCP_KEEPIDLE, &keepalive_time, sizeof(keepalive_time)) == -1)
{
    printf("\n error in setsockopt keepalive_time");
}   

if(setsockopt(CreateSocket, SOL_TCP, TCP_KEEPCNT, (char*)&keepalive_count, sizeof(keepalive_count)) == -1)
{
    printf("\n error in setsockopt keepalive_count");
}
if(setsockopt(CreateSocket, SOL_TCP, TCP_KEEPINTVL, (char*)&keepalive_interval, sizeof (keepalive_interval)) == -1)
{
    printf("\n error in setsockopt keepalive_interval");
}

第二次尝试时,将keepalive_time更改为60秒。

关于更新值需要做什么的任何线索?

0 个答案:

没有答案