如何在VxWorks中为特定套接字fd(非系统范围)设置TCP保持活动间隔? [英] How to set TCP keep alive interval for a specific socket fd (Not system wide) in VxWorks?

查看:237
本文介绍了如何在VxWorks中为特定套接字fd(非系统范围)设置TCP保持活动间隔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在启用了该套接字的KEEPALIVE的应用程序中创建了一个TCP套接字.我可以看到keepalive数据包的频率是我在iptcp的系统变量中设置的keepalive间隔的频率,即30秒.

I created a TCP socket in an application with KEEPALIVE enabled for this socket. I can see that keepalive packets are coming with the frequency of keepalive interval which i have already set in my system variable of iptcp, i.e 30secs.

套接字创建:

  if( ( sockFD = socket( AF_INET, SOCK_STREAM, 0 ) ) == ERROR )
  {
    DS_SWX_ERROR( "socket(%d,%d,%d) failed.", AF_INET, SOCK_STREAM, 0 );
    return;
  }

VxWorks TCP系统变量:

VxWorks TCP System Variables:

[vxWorks *]# sysvar list iptcp
System variables:
   iptcp.KeepCnt=3
   iptcp.KeepIdle=60
   iptcp.KeepIntvl=30

如上所述,根据系统变量,它工作正常.在连续3个数据包丢失后,我以30秒为间隔获取活动数据包,我的连接关闭了.一切都可以作为系统变量正常工作.但是,对于所有启用了活动的套接字,此TCP系统变量配置都是相同的.

As mentioned above according to system variables it is working fine. I am getting keep alive packets at the 30 seconds interval after 3 consecutive packets loss my connection get closed. Everything is working fine as system variables. But this TCP system variable configuration is same for all the sockets which have keep alive enabled.

我只想为我创建的套接字而不是整个系统设置此存活间隔.

我已经尝试过使用setsockopt设置保持活动间隔.

I already tried to set the keep alive interval using the setsockopt.

 if( (setsockopt( sockFD, SOL_SOCKET, IP_TCP_KEEPINTVL,
      (char *)5, sizeof(int) )) == ERROR )
  {
    DS_SWX_ERROR( "setsockopt(%d,%d,%d,0x%x,%d) failed, Error is %d\n",
                  sockFD, SOL_SOCKET, SO_KEEPALIVE,
                  (char*) &optVal, sizeof(optVal), errnum );
  }

 if( (setsockopt( sockFD, IP_IPPROTO_IP, IP_TCP_KEEPINTVL,
      (char *)5, sizeof(int) )) == ERROR )
  {
    DS_SWX_ERROR( "setsockopt(%d,%d,%d,0x%x,%d) failed, Error is %d\n",
                  sockFD, SOL_SOCKET, SO_KEEPALIVE,
                  (char*) &optVal, sizeof(optVal), errnum );
  }

以上setsockopt都返回相同的错误状态,即不支持操作". (45,IP_ERRNO_EOPNOTSUPP)

both the above setsockopt is returning the same Error status which is Operation not supported. (45, IP_ERRNO_EOPNOTSUPP)

在这里,我想将TCP KEEP ALIVE INTERVAL设置为5秒.

Here i wanted to set the TCP KEEP ALIVE INTERVAL as 5 secs.

我希望为特定的套接字fd设置tcp保持活动间隔.

I expect to set the tcp keep alive interval for a specific socket fd.

此问题不是>如何设置keepalive选项的重复项在VxWorks中用于单个套接字 这个问题没有我的答案.请检查.第一个答案是我在这里问的相同问题,第二个答案是链接不起作用.

Edited: This question is not the duplicate of How to set keepalive option for induvidual socket in VxWorks That question does not have my answer. Please check. First answer is the same question i asked here, and in the second answer that link is not working.

推荐答案

我认为您的vxworks版本低于6.8.因为在vxworks的早期版本中,setsockopt不支持此选项(IP_TCP_KEEPINTVL以及TCP_KEEPIDLE,TCP_KEEPCNT).据我所知,没有办法为以前版本的特定套接字fd单独设置此选项.

I suppose your vxworks version is less than 6.8. because this option (IP_TCP_KEEPINTVL and also TCP_KEEPIDLE, TCP_KEEPCNT) is not supported by setsockopt for former releases of vxworks. As far as I know there is no way to set this option individually for a specific socket fd for former releases.

这篇关于如何在VxWorks中为特定套接字fd(非系统范围)设置TCP保持活动间隔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆