support openbsd // implement tcp keep-alive polling
This commit is contained in:
parent
4ac6887deb
commit
727e09ebe7
1 changed files with 30 additions and 2 deletions
|
|
@ -11,6 +11,13 @@
|
||||||
# include <mstcpip.h>
|
# include <mstcpip.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined __OpenBSD__
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <sys/sysctl.h>
|
||||||
|
# include <netinet/tcp_timer.h>
|
||||||
|
# include <netinet/tcp_var.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace fc {
|
namespace fc {
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
|
|
@ -186,16 +193,37 @@ namespace fc {
|
||||||
if (setsockopt(my->_sock.native_handle(), IPPROTO_TCP,
|
if (setsockopt(my->_sock.native_handle(), IPPROTO_TCP,
|
||||||
#if defined( __APPLE__ )
|
#if defined( __APPLE__ )
|
||||||
TCP_KEEPALIVE,
|
TCP_KEEPALIVE,
|
||||||
|
#elif defined( __OpenBSD__ )
|
||||||
|
SO_KEEPALIVE,
|
||||||
#else
|
#else
|
||||||
TCP_KEEPIDLE,
|
TCP_KEEPIDLE,
|
||||||
#endif
|
#endif
|
||||||
(char*)&timeout_sec, sizeof(timeout_sec)) < 0)
|
(char*)&timeout_sec, sizeof(timeout_sec)) < 0)
|
||||||
wlog("Error setting TCP keepalive idle time");
|
wlog("Error setting TCP keepalive idle time");
|
||||||
# if !defined(__APPLE__) || defined(TCP_KEEPINTVL) // TCP_KEEPINTVL not defined before 10.9
|
# if defined(__OpenBSD__)
|
||||||
|
int name[4];
|
||||||
|
name[0] = CTL_NET;
|
||||||
|
name[1] = PF_INET;
|
||||||
|
name[2] = IPPROTO_TCP;
|
||||||
|
|
||||||
|
int value;
|
||||||
|
size_t sz;
|
||||||
|
|
||||||
|
// get tics per second
|
||||||
|
name[3] = TCPCTL_SLOWHZ;
|
||||||
|
if (sysctl(name, 4, &value, &sz, NULL, 0) == -1)
|
||||||
|
wlog("Error setting TCP keepalive interval");
|
||||||
|
|
||||||
|
// set interval
|
||||||
|
value *= timeout_sec;
|
||||||
|
name[3] = TCPCTL_KEEPINTVL;
|
||||||
|
if (sysctl(name, 4, NULL, NULL, &value, sizeof(value)) == -1)
|
||||||
|
wlog("Error setting TCP keepalive interval");
|
||||||
|
# elif !defined(__APPLE__) || defined(TCP_KEEPINTVL) // TCP_KEEPINTVL not defined before 10.9
|
||||||
if (setsockopt(my->_sock.native_handle(), IPPROTO_TCP, TCP_KEEPINTVL,
|
if (setsockopt(my->_sock.native_handle(), IPPROTO_TCP, TCP_KEEPINTVL,
|
||||||
(char*)&timeout_sec, sizeof(timeout_sec)) < 0)
|
(char*)&timeout_sec, sizeof(timeout_sec)) < 0)
|
||||||
wlog("Error setting TCP keepalive interval");
|
wlog("Error setting TCP keepalive interval");
|
||||||
# endif // !__APPLE__ || TCP_KEEPINTVL
|
# endif // (__OpenBSD__) or (!__APPLE__ || TCP_KEEPINTVL)
|
||||||
#endif // !WIN32
|
#endif // !WIN32
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue