Add KeepAlive support for all TCP sockets.
authorEdouard Tisserant
Mon, 22 Mar 2021 14:57:48 +0100
changeset 12 16ea5cbbda4e
parent 11 7c955a1d39e8
child 17 e319814f1c17
Add KeepAlive support for all TCP sockets.
mb_tcp.c
--- a/mb_tcp.c	Mon Jun 01 14:28:49 2020 +0100
+++ b/mb_tcp.c	Mon Mar 22 14:57:48 2021 +0100
@@ -467,6 +467,18 @@
   }
 
   /* configure the socket */
+  {
+   int optval;
+   socklen_t optlen = sizeof(optval);
+   optval = 1;
+   if(setsockopt(socket_id, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0) {
+#ifdef ERRMSG
+    perror("setsockopt()");
+    fprintf(stderr, ERRMSG_HEAD "Error configuring socket 'KeepAlive' option.\n");
+#endif
+      return -1;
+   }
+  }
     /* set the TCP no delay flag. */
   {int bool_opt = 1;
   if (setsockopt(socket_id, SOL_TCP, TCP_NODELAY,