sock: refactore tcp keepalive setting
- Leave default number of keepalive probes rather than hardcoded value - QNX and OSX use TCP_KEEPALIVE instead of TCP_KEEPIDLE - QNX doesn't have TCP_KEEPINTVL
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
- xmpp_uuid_gen()
|
||||
- xmpp_conn_get_flags()
|
||||
- xmpp_conn_set_flags()
|
||||
- xmpp_conn_set_keepalive()
|
||||
- xmpp_conn_is_secured()
|
||||
- xmpp_stanza_del_attribute()
|
||||
- xmpp_stanza_get_to()
|
||||
|
||||
22
src/sock.c
22
src/sock.c
@@ -115,6 +115,8 @@ int sock_set_keepalive(const sock_t sock, int timeout, int interval)
|
||||
int ret;
|
||||
int optval = (timeout && interval) ? 1 : 0;
|
||||
|
||||
/* This function doesn't change maximum number of keepalive probes */
|
||||
|
||||
#ifdef _WIN32
|
||||
struct tcp_keepalive ka;
|
||||
DWORD dw = 0;
|
||||
@@ -129,20 +131,22 @@ int sock_set_keepalive(const sock_t sock, int timeout, int interval)
|
||||
return ret;
|
||||
|
||||
if (optval) {
|
||||
/* it's not possible to set keepalive count in Windows, so just use some
|
||||
* acceptable value for UNIX to keep things work the same */
|
||||
optval = 5;
|
||||
ret = setsockopt(sock, SOL_TCP, TCP_KEEPCNT, &optval, sizeof(optval));
|
||||
#ifdef TCP_KEEPIDLE
|
||||
ret = setsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE, &timeout, sizeof(timeout));
|
||||
#else
|
||||
/* QNX receives `struct timeval' as argument, but it seems OSX does int */
|
||||
ret = setsockopt(sock, IPPROTO_TCP, TCP_KEEPALIVE, &timeout, sizeof(timeout));
|
||||
#endif /* TCP_KEEPIDLE */
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
ret = setsockopt(sock, SOL_TCP, TCP_KEEPIDLE, &timeout, sizeof(timeout));
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
ret = setsockopt(sock, SOL_TCP, TCP_KEEPINTVL, &interval, sizeof(interval));
|
||||
#ifdef TCP_KEEPINTVL
|
||||
ret = setsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL, &interval, sizeof(interval));
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
#endif /* TCP_KEEPINTVL */
|
||||
}
|
||||
#endif
|
||||
#endif /* _WIN32 */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user