Fix compatibility with TCP_KEEPIDLE and Darwin

Darwin uses for the same setting the TCP_KEEPALIVE option.
Use TCP_KEEPALIVE instead of TCP_KEEPIDLE for Darwin.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
Frediano Ziglio 2020-04-15 20:47:05 +01:00 committed by Frediano Ziglio
parent 8772163cf9
commit 90453ddf06

View File

@ -35,6 +35,10 @@
#include "net-utils.h"
#include "sys-socket.h"
#if !defined(TCP_KEEPIDLE) && defined(TCP_KEEPALIVE) && defined(__APPLE__)
#define TCP_KEEPIDLE TCP_KEEPALIVE
#endif
/**
* red_socket_set_keepalive:
* @fd: a socket file descriptor
@ -57,7 +61,7 @@ bool red_socket_set_keepalive(int fd, bool enable, int timeout)
return true;
}
#ifdef HAVE_TCP_KEEPIDLE
#ifdef TCP_KEEPIDLE
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &timeout, sizeof(timeout)) == -1) {
if (errno != ENOTSUP) {
g_warning("setsockopt for keepalive timeout failed, %s", strerror(errno));