1
0
mirror of https://github.com/prirun/p50em.git synced 2026-01-11 23:42:56 +00:00

Set the keepalive idle time at accept time

Set the keepalive idle time per connection, at accept time,
using the setsockopt TCP_KEEPIDLE flag.  This seems to be
reasonably portable.
This commit is contained in:
Dennis Boone 2020-05-17 00:35:04 -04:00
parent 7e8e7236ec
commit 9c6722ffc5

View File

@ -911,7 +911,12 @@ int devamlc (int class, int func, int device) {
optval = 1;
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &optval, sizeof(optval)) == -1)
perror("unable to set TCP_NODELAY");
/* Should we re-set optval here? Any chance it gets modified? */
/* Set 600 second keepalive idle time for this socket */
optval = 600;
if (setsockopt(fd, 6 /* TCP */, TCP_KEEPIDLE, &optval, sizeof(optval)) == -1)
perror("unable to set TCP_KEEPIDLE");
/* ... and turn on keepalive */
optval = 1;
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)) == -1)
perror("unable to set SO_KEEPALIVE");