admin 管理员组文章数量: 1086019
I have a Client-Server set up in C. The Client is running on a development board (FreeRTOS with lwip stack). Server is running on a Ubuntu. I am trying to set the KEEP_ALIVE params using the following code:
int optval = 1;
ret =setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval));
if (ret)
{
printf("Failed to set socket option - SO_KEEPALIVE ret=%d, ret\n");
}
else
{
printf("Keep Alive Set!\n");
}
ret = setsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE, &KEEP_ALIVE_TIME, sizeof(KEEP_ALIVE_TIME));
if (ret)
{
printf("Failed to set socket option - TCP_KEEPIDLE ret=%d, ret\n");
}
else
{
printf("Keep Idle Set!\n");
}
ret = setsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL, &KEEP_ALIVE_INTERVAL, sizeof(KEEP_ALIVE_INTERVAL));
if (ret)
{
printf("Failed to set socket option - TCP_KEEPINTVL ret=%d, ret\n");
}
else
{
printf("Keep Alive Interval Set!\n");
}
ret = setsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT, &KEEP_ALIVE_PROBES, sizeof(KEEP_ALIVE_PROBES));
if (ret)
{
printf("Failed to set socket option - TCP_KEEPCNT ret=%d, ret\n");
}
else
{
printf("Keep Count Set!\n");
}
The SO_KEEPALIVE
works fine and gets set but for the rest I keep getting a return value error code of 16. When I look this error code up it says the following:
16 EBUSY All Listen has already been called for this socket. Device or file to be accessed is busy. Check if the device or file is in use.
In my google trawling I have come across some posts that seem to suggest KEEP_ALIVE
setting is not supported in the lwip stack. Some others seem to indicate this can be done by editing the lwipopts.h
file.
Any help would be great.
本文标签: tcpHow to set KEEPALIVE parameters via C codeStack Overflow
版权声明:本文标题:tcp - How to set KEEP_ALIVE parameters via C code - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744020021a2519633.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论