SOCK: Add TCP keepalive support to all incoming and outgoing TCP sockets.
This allows detection of network failures when there is no traffic across established circuits,
This commit is contained in:
parent
d8b55677c1
commit
f2674766ca
1 changed files with 13 additions and 0 deletions
13
sim_sock.c
13
sim_sock.c
|
@ -1015,7 +1015,14 @@ if ((sta == SOCKET_ERROR) &&
|
||||||
(WSAGetLastError () != WSAEWOULDBLOCK) &&
|
(WSAGetLastError () != WSAEWOULDBLOCK) &&
|
||||||
(WSAGetLastError () != WSAEINPROGRESS))
|
(WSAGetLastError () != WSAEINPROGRESS))
|
||||||
return sim_err_sock (newsock, "connect", 1);
|
return sim_err_sock (newsock, "connect", 1);
|
||||||
|
if (!datagram) {
|
||||||
|
int keepalive = 1;
|
||||||
|
|
||||||
|
/* enable TCP Keep Alives */
|
||||||
|
sta = setsockopt (newsock, SOL_SOCKET, SO_KEEPALIVE, (char *)&keepalive, sizeof(keepalive));
|
||||||
|
if (sta == -1)
|
||||||
|
return sim_err_sock (newsock, "setsockopt KEEPALIVE", 1);
|
||||||
|
}
|
||||||
return newsock; /* got it! */
|
return newsock; /* got it! */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1027,6 +1034,7 @@ return sim_accept_conn_ex (master, connectaddr, FALSE);
|
||||||
SOCKET sim_accept_conn_ex (SOCKET master, char **connectaddr, t_bool nodelay)
|
SOCKET sim_accept_conn_ex (SOCKET master, char **connectaddr, t_bool nodelay)
|
||||||
{
|
{
|
||||||
int32 sta, err;
|
int32 sta, err;
|
||||||
|
int keepalive = 1;
|
||||||
#if defined (macintosh) || defined (__linux) || defined (__linux__) || \
|
#if defined (macintosh) || defined (__linux) || defined (__linux__) || \
|
||||||
defined (__APPLE__) || defined (__OpenBSD__) || \
|
defined (__APPLE__) || defined (__OpenBSD__) || \
|
||||||
defined(__NetBSD__) || defined(__FreeBSD__) || \
|
defined(__NetBSD__) || defined(__FreeBSD__) || \
|
||||||
|
@ -1076,6 +1084,11 @@ if (nodelay) {
|
||||||
return sim_err_sock (newsock, "setnodelay", 0);
|
return sim_err_sock (newsock, "setnodelay", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* enable TCP Keep Alives */
|
||||||
|
sta = setsockopt (newsock, SOL_SOCKET, SO_KEEPALIVE, (char *)&keepalive, sizeof(keepalive));
|
||||||
|
if (sta == -1)
|
||||||
|
return sim_err_sock (newsock, "setsockopt KEEPALIVE", 1);
|
||||||
|
|
||||||
return newsock;
|
return newsock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue