I am trying to set the TCP Keep Alive Socket option and adjust some of its value using the NDK, at this point, I think the NDK version is irrelevant.
The relevant code is C++, is called from a method in a class and looks like the following:
// Assume the socket handle is valid and was created with socket()
// Enable TCP Keep Alive
int nOptVal = 1;
setsockopt(hSocket, SOL_SOCKET, SO_KEEPALIVE, reinterpret_cast<char*>(&nOptVal), sizeof(nOptVal));
// Every 15 secs.
nOptVal = 15;
setsockopt(hSocket, SOL_TCP, SO_KEEPINTVL, reinterpret_cast<char*>(&nOptVal), sizeof(nOptVal));
// Send a single probe
nOptVal = 1;
setsockopt(hSocket, SOL_TCP, SO_KEEPCNT, reinterpret_cast<char*>(&nOptVal), sizeof(nOptVal));
When I try to compile the above, the SO_KEEPINTVL
and SO_KEEPCNT
macros are unfound and I cannot seem to find their definition in the include files of the NDK.
As anyone ever made this work?
One last note, I cannot do it from the java code since the options need to be set on sockets that are inside a library the java code is using.
I looked through SO and found this question which explains how to do it in Java so it should be possible, I guess.
Thanks for any help on this.