问题描述:

I want to be able to set the TCP socket KEEPALIVE parameters (TCP_KEEPIDLE, TCP_KEEPINTVL, and TCP_KEEPCNT) but these don't appear to be available in the Socket class. Based on the documentation of the SocketImpl and SocketOptions classes along with the bit about implementation details at the bottom of this page, I'm led to the conclusion that the library implementers hard coded the "level" argument of setsockopt to SOL_SOCKET, which makes it impossible to access options at other levels such as SOL_TCP/IPPROTO_TCP. Is there another Java class that I'm missing which handles these options? If not, is there any way to get the raw file descriptor number so that I can pass it through JNI to a bit of C code that calls setsockopt directly since it doesn't seem to be available from FileDescriptor?

网友答案:

These are all non-portable Linux-specific options, that's probably why they are not available in a cross-platform language library. Most of them though have respective entries in proc(5) and sysctl(2) options.

网友答案:

The manpage you are looking for is tcp(7). Note that instead of SOL_TCP, it is safer to use IPPROTO_TCP

相关阅读:
Top