Get keepalive code building on os x

This commit is contained in:
Eric Frias 2014-04-15 13:40:19 -04:00
parent 1b16e15585
commit 7849cc7ada

View file

@ -84,13 +84,18 @@ namespace fc {
if (WSAIoctl(my->_sock.native(), SIO_KEEPALIVE_VALS, &keepalive_settings, sizeof(keepalive_settings),
NULL, 0, &dwBytesRet, NULL, NULL) == SOCKET_ERROR)
wlog("Error setting TCP keepalive values");
#elif !defined( __APPLE__ ) // TODO: add proper support for OS X Mavericks... SOL_TCP and TCP_KEEPIDLE are not defined
#else
// This should work for modern Linuxes and for OSX >= Mountain Lion
int timeout_sec = interval.count() / fc::seconds(1).count();
if (setsockopt(my->_sock.native(), SOL_TCP, TCP_KEEPIDLE,
if (setsockopt(my->_sock.native(), IPPROTO_TCP,
# if defined( __APPLE__ )
TCP_KEEPALIVE,
# else
TCP_KEEPIDLE,
# endif
(char*)&timeout_sec, sizeof(timeout_sec)) < 0)
wlog("Error setting TCP keepalive idle time");
if (setsockopt(my->_sock.native(), SOL_TCP, TCP_KEEPINTVL,
if (setsockopt(my->_sock.native(), IPPROTO_TCP, TCP_KEEPINTVL,
(char*)&timeout_sec, sizeof(timeout_sec)) < 0)
wlog("Error setting TCP keepalive interval");
#endif