Explorar o código

Optimizing startup time by delaying neon SSPI initialization until the first WebDAV/S3 connection

Assuming we do not need SSPI for plain HTTPS connections (like updates check)

Source commit: c9dd331a99d5fe0d0ba97aa2210e3b4e5689ad35
Martin Prikryl hai 2 meses
pai
achega
c45ae10ded
Modificáronse 2 ficheiros con 32 adicións e 30 borrados
  1. 7 10
      libs/neon/src/ne_socket.c
  2. 25 20
      source/core/WebDAVFileSystem.cpp

+ 7 - 10
libs/neon/src/ne_socket.c

@@ -345,6 +345,13 @@ int ne_sock_init(void)
     if (err != 0) {
 	return init_state = -1;
     }
+#ifndef WINSCP
+#ifdef HAVE_SSPI
+    if (ne_sspi_init() < 0) {
+        return init_state = -1;
+    }
+#endif
+#endif
 #endif
 
 #ifdef NE_HAVE_SOCKS
@@ -366,16 +373,6 @@ int ne_sock_init(void)
 #endif
 
     init_state = 1;
-
-#ifdef WIN32    
-#ifdef HAVE_SSPI
-    // This fails on Wine, and we do not want to abort
-    // whole Neon initialization because of that
-    if (ne_sspi_init() < 0) {
-        return -2;
-    }
-#endif
-#endif
     return 0;
 }
 

+ 25 - 20
source/core/WebDAVFileSystem.cpp

@@ -17,6 +17,11 @@
 #include <ne_redirect.h>
 #include <ne_xmlreq.h>
 #include <ne_locks.h>
+// ne_sspi.h is not a public interface, so it is not ready to be included from C++
+#define HAVE_SSPI
+NE_BEGIN_DECLS
+#include <ne_sspi.h>
+NE_END_DECLS
 #include <expat.h>
 
 #include "WebDAVFileSystem.h"
@@ -89,31 +94,14 @@ static UnicodeString PathUnescape(const char * Path)
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 static bool NeonInitialized = false;
-static bool NeonSspiInitialized = false;
+static int NeonSspiInitialized = -1;
 //---------------------------------------------------------------------------
 void __fastcall NeonInitialize()
 {
   // Even if this fails, we do not want to interrupt WinSCP starting for that.
   // Anyway, it can hardly fail.
-  // Though it fails on Wine on Debian VM, because of ne_sspi_init():
-  // sspi: QuerySecurityPackageInfo [failed] [80090305].
-  // sspi: Unable to get negotiate maximum packet size
   int NeonResult = ne_sock_init();
-  if (NeonResult == 0)
-  {
-    NeonInitialized = true;
-    NeonSspiInitialized = true;
-  }
-  else if (NeonResult == -2)
-  {
-    NeonInitialized = true;
-    NeonSspiInitialized = false;
-  }
-  else
-  {
-    NeonInitialized = false;
-    NeonSspiInitialized = false;
-  }
+  NeonInitialized = (NeonResult == 0);
 }
 //---------------------------------------------------------------------------
 void __fastcall NeonFinalize()
@@ -122,6 +110,7 @@ void __fastcall NeonFinalize()
   {
     ne_sock_exit();
     NeonInitialized = false;
+    NeonSspiInitialized = -1;
   }
 }
 //---------------------------------------------------------------------------
@@ -132,7 +121,23 @@ void __fastcall RequireNeon(TTerminal * Terminal)
     throw Exception(LoadStr(NEON_INIT_FAILED2));
   }
 
-  if (!NeonSspiInitialized)
+  if (NeonSspiInitialized < 0)
+  {
+    // This fails on Wine on Debian VM:
+    // sspi: QuerySecurityPackageInfo [failed] [80090305].
+    // sspi: Unable to get negotiate maximum packet size
+    // This takes about second, when debugging, that's why it is postponed until the first connection.
+    if (ne_sspi_init() < 0)
+    {
+      NeonSspiInitialized = 0;
+    }
+    else
+    {
+      NeonSspiInitialized = 1;
+    }
+  }
+
+  if (NeonSspiInitialized <= 0)
   {
     Terminal->LogEvent(L"Warning: SSPI initialization failed.");
   }