Skip to content

Commit

Permalink
Merge pull request #165 from signalwire/ifdefkeepalive
Browse files Browse the repository at this point in the history
Disable use of	TCP_KEEPIDLE and TCP_KEEPINTVL socket options. Introduce undefined KS_KEEP_IDLE_INTVL.
  • Loading branch information
andywolk authored Jul 18, 2023
2 parents 8f924da + 16a961a commit 0783723
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/include/libks/ks.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
/* libks version as a number */
#define KS_VERSION_NUM 20001

/* Use this to allow enabling TCP_KEEPIDLE and TCP_KEEPINTVL socket options */
//#define KS_KEEP_IDLE_INTVL 1

#include "libks/ks_platform.h"
#include "libks/ks_types.h"

Expand Down
2 changes: 2 additions & 0 deletions src/ks_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ KS_DECLARE(ks_status_t) ks_socket_option(ks_socket_t socket, int option_name, ks
case TCP_NODELAY:
case SO_KEEPALIVE:
case SO_LINGER:
#ifdef KS_KEEP_IDLE_INTVL
#ifndef __APPLE__
case TCP_KEEPIDLE:
case TCP_KEEPINTVL:
#endif
#endif /* KS_KEEP_IDLE_INTVL */
#ifdef WIN32
result = setsockopt(socket, SOL_SOCKET, option_name, (char *) &opt, sizeof(opt));
#else
Expand Down
2 changes: 2 additions & 0 deletions src/kws.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,12 @@ static void setup_socket(ks_socket_t sock)
ks_socket_option(sock, KS_SO_NONBLOCK, KS_TRUE);
ks_socket_option(sock, TCP_NODELAY, KS_TRUE);
ks_socket_option(sock, SO_KEEPALIVE, KS_TRUE);
#ifdef KS_KEEP_IDLE_INTVL
#ifndef __APPLE__
ks_socket_option(sock, TCP_KEEPIDLE, 30);
ks_socket_option(sock, TCP_KEEPINTVL, 30);
#endif
#endif /* KS_KEEP_IDLE_INTVL */
}

static void restore_socket(ks_socket_t sock)
Expand Down

0 comments on commit 0783723

Please sign in to comment.