0

I'm writing a JNI library for a Java application that needs to set the values of the TCP Keep Alive option. (It sets the values for Keep Alive Timeout and Interval) For the most part, I think I have it working, as I can set the Keep Alive on/off from Java and query it with correct result in the C++ code. I can set the other two options, and there are no errors, but I'm not sure how to query for these option values. It would be useful to query these values to prove quickly that they've been set.

Any ideas?

Only constraints are that I'm using C++, Winsock and the target OS is Windows XP or higher.

Alex
  • 26
  • 5

1 Answers1

0

See here for how:

The magic words are getsockopt, setsockopt and SO_KEEPALIVE.

You might also need WSAIoctl:

The system doesn't have any method of checking the current values of the tcp_keepalive structure passed to WSAIoctl for SIO_KEEPALIVE_VALS. You can set them to the values you want, but you cannot interrogate what they are presently.

If you want to check whether they are being honored, you can set up a test case and use wireshark or Network Monitor, and see what the values are. But note that there is probably nothing you can do about it if the system won't honor the settings.

However if are trying to overload the TCP keepalive with an application level meaning, you may want to see my answer to this question:

Community
  • 1
  • 1
Ben
  • 34,935
  • 6
  • 74
  • 113
  • Unfortunately, those don't help for querying the extra options that I need. I'm already using getsockopt, setsockopt and WSAIoctl, but as far as I can tell, these don't expose the values of Keep Alive Interval and Keep Alive Timeout. – Alex Jan 07 '13 at 15:15
  • @Alex, You can set both of those the desired values using the corresponding entries in the `tcp_keepalive` structure passed to `WSAIoctl` for `SIO_KEEPALIVE_VALS`. Not sure what else you want? If you just want to check the value is being honored, set up a test case and use wireshark to see the packets go past. – Ben Jan 07 '13 at 15:26
  • 1
    Right, I am already able to set the options. I want to **get** them now, but this doesn't seem possible. Wireshark is a good suggestion, but is not very automatable which would be my next concern. Thanks. – Alex Jan 07 '13 at 15:34
  • @Alex, you have to trust your platform. If you have set them, consider them set. However if are trying to overload the TCP keepalive with an application level meaning, you may want to see my answer to this question: http://stackoverflow.com/questions/5338352/asyncsockets-and-silent-disconnections/5338459#5338459 – Ben Jan 07 '13 at 15:42