How to set TCP keep alive interval for a specific socket fd (Not system wide) in VxWorks?

旧街凉风 提交于 2019-12-25 18:19:19

问题


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.

Socket Creation:

  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 System Variables:

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

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.

I want to set this keep alive interval only for my socket created, not for the complete system.

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 );
  }

and

 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 );
  }

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

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

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

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.


回答1:


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.



来源:https://stackoverflow.com/questions/57326996/how-to-set-tcp-keep-alive-interval-for-a-specific-socket-fd-not-system-wide-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!