[WINHTTP] Properly initialize winsock. Based on wine tests CORE-12104
[reactos.git] / reactos / dll / win32 / winhttp / net.c
index bdb7787..dcf6aee 100644 (file)
@@ -276,6 +276,28 @@ static BOOL ensure_cred_handle(void)
     return ret;
 }
 
     return ret;
 }
 
+#ifdef __REACTOS__
+static BOOL winsock_initialized = FALSE;
+BOOL netconn_init_winsock()
+{
+    WSADATA wsaData;
+    int error;
+    if (!winsock_initialized)
+    {
+        error = WSAStartup(MAKEWORD(1, 1), &wsaData);
+        if (error)
+        {
+            ERR("WSAStartup failed: %d\n", error);
+            return FALSE;
+        }
+        else
+            winsock_initialized = TRUE;
+    }
+    return winsock_initialized;
+}
+
+#endif
+
 BOOL netconn_init( netconn_t *conn )
 {
     memset(conn, 0, sizeof(*conn));
 BOOL netconn_init( netconn_t *conn )
 {
     memset(conn, 0, sizeof(*conn));
@@ -291,6 +313,10 @@ void netconn_unload( void )
 #ifndef HAVE_GETADDRINFO
     DeleteCriticalSection(&cs_gethostbyname);
 #endif
 #ifndef HAVE_GETADDRINFO
     DeleteCriticalSection(&cs_gethostbyname);
 #endif
+#ifdef __REACTOS__
+    if(winsock_initialized)
+        WSACleanup();
+#endif
 }
 
 BOOL netconn_connected( netconn_t *conn )
 }
 
 BOOL netconn_connected( netconn_t *conn )