]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Common source file changes not applicable to open-vm-tools.
authorOliver Kurth <okurth@vmware.com>
Tue, 21 Apr 2020 21:43:45 +0000 (14:43 -0700)
committerOliver Kurth <okurth@vmware.com>
Tue, 21 Apr 2020 21:43:45 +0000 (14:43 -0700)
open-vm-tools/lib/asyncsocket/asyncsocket.c
open-vm-tools/lib/include/asyncsocket.h
open-vm-tools/lib/include/loglevel_user.h

index fb9d4bdb5943f59d557ee7a6a786920a14cc1a33..038a9486ecde5a65d4517be82b0913ee87aea0bf 100644 (file)
@@ -61,6 +61,7 @@
 #include <ws2tcpip.h>
 #include <wspiapi.h>
 #include <MSWSock.h>
+#include <mstcpip.h>
 #include <windows.h>
 #if !(defined(__GOT_SECURE_LIB__) && __GOT_SECURE_LIB__ >= 200402L)
 #undef strcpy
@@ -6373,3 +6374,91 @@ AsyncTCPSocketListenerError(int error,           // IN
 
    AsyncSocketHandleError(s, error);
 }
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * AsyncSocket_SetKeepAlive --
+ *
+ *      Set keep-alive socket option.
+ *
+ * Results:
+ *      TRUE if successful.
+ *
+ * Side effects:
+ *      None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+Bool
+AsyncSocket_SetKeepAlive(AsyncSocket *asock, // IN
+                         int keepIdle)       // IN
+{
+   int fd;
+
+   fd = AsyncSocket_GetFd(asock);
+#ifdef WIN32
+   {
+      struct tcp_keepalive keepalive = { 1, keepIdle * 1000, keepIdle * 10 };
+      DWORD ret;
+
+      if (WSAIoctl(fd, SIO_KEEPALIVE_VALS, &keepalive, sizeof keepalive,
+                   NULL, 0, &ret, NULL, NULL)) {
+         Err_Number sysErr = ASOCK_LASTERROR();
+         ASOCKLG0(asock, "Could not set keepalive options, error %d: %s\n",
+                  sysErr, Err_Errno2String(sysErr));
+      }
+   }
+#else
+   {
+      static const int keepAlive = 1;
+      if (keepIdle) {
+#  ifdef TCP_KEEPIDLE
+#     define VMTCP_KEEPIDLE TCP_KEEPIDLE
+#  else
+#     define VMTCP_KEEPIDLE TCP_KEEPALIVE
+#  endif
+         if (setsockopt(fd,
+                        IPPROTO_TCP,
+                        VMTCP_KEEPIDLE,
+                        (const char *)&keepIdle, sizeof keepIdle) != 0) {
+            Err_Number sysErr = ASOCK_LASTERROR();
+            ASOCKLG0(asock, "Could not set TCP_KEEPIDLE, error %d: %s\n",
+                     sysErr, Err_Errno2String(sysErr));
+            return FALSE;
+         }
+#  ifndef __APPLE__
+      {
+         /*
+          * Default TCP setting is 7200 sec idle, and 75 interval.  So let's
+          * divide keepIdle by 100 to get an interval.  For our 300 seconds
+          * default that is 3 seconds keepIdle.
+          */
+         int keepIntvl = keepIdle / 100;
+
+         if (keepIntvl < 1) {
+            keepIntvl = 1;
+         }
+         if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL,
+                        (const char *)&keepIntvl, sizeof keepIntvl) != 0) {
+            Err_Number sysErr = ASOCK_LASTERROR();
+            ASOCKLG0(asock, "Could not set TCP_KEEPIDLE, error %d: %s\n",
+                     sysErr, Err_Errno2String(sysErr));
+            return FALSE;
+         }
+      }
+#  endif /* __APPLE__ */
+      }
+      if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE,
+                     (const char *)&keepAlive, sizeof keepAlive) != 0) {
+         Err_Number sysErr = ASOCK_LASTERROR();
+         ASOCKLG0(asock, "Could not set TCP_KEEPIDLE, error %d: %s\n",
+                  sysErr, Err_Errno2String(sysErr));
+         return FALSE;
+      }
+   }
+#endif /* WIN32 */
+   return TRUE;
+}
index 36123048427a523c7219eb1a62ce3c6616dd62eb..27ce6c119bbe2b61f4869a6997a13d9d0b724ad2 100644 (file)
@@ -760,6 +760,9 @@ char *AsyncSocket_WebSocketGetHttpHeader(const char *request,
 
 unsigned AsyncSocket_WebSocketGetNumAccepted(AsyncSocket *asock);
 
+Bool AsyncSocket_SetKeepAlive(AsyncSocket *asock, int keepIdle);
+
+
 /*
  * Some logging macros for convenience
  */
index 9b1afb10c80b90edfcde5b989d75dcab5911ff42..cf491c8e1e98adc3efe5168584e901554a8603dd 100644 (file)
    LOGLEVEL_VAR(numa), \
    LOGLEVEL_VAR(numaHost), \
    LOGLEVEL_VAR(remoteDevice), \
+   LOGLEVEL_VAR(vsockProxy), \
    LOGLEVEL_VAR(vncDecode), \
    LOGLEVEL_VAR(vncEncode), \
    LOGLEVEL_VAR(vncBlit),   \