OSDN Git Service

Fix bugs of corruption on resuming downloading files larger than 4GB.
[ffftp/ffftp.git] / socketwrapper.c
index a43f5bf..612218e 100644 (file)
@@ -340,6 +340,8 @@ BOOL AttachSSL(SOCKET s, SOCKET parent)
        SSL** ppSSL;\r
        SSL** ppSSLParent;\r
        SSL_SESSION* pSession;\r
+       int Return;\r
+       int Error;\r
        if(!g_bOpenSSLLoaded)\r
                return FALSE;\r
        r = FALSE;\r
@@ -369,17 +371,21 @@ BOOL AttachSSL(SOCKET s, SOCKET parent)
                                        }\r
                                        // SSLのネゴシエーションには時間がかかる場合がある\r
                                        r = TRUE;\r
-                                       while(p_SSL_connect(*ppSSL) != 1)\r
+                                       while(r)\r
                                        {\r
-                                               LeaveCriticalSection(&g_OpenSSLLock);\r
-                                               if(g_pOpenSSLTimeoutCallback() || (g_OpenSSLTimeout > 0 && timeGetTime() - Time >= g_OpenSSLTimeout))\r
+                                               Return = p_SSL_connect(*ppSSL);\r
+                                               if(Return == 1)\r
+                                                       break;\r
+                                               Error = p_SSL_get_error(*ppSSL, Return);\r
+                                               if(Error == SSL_ERROR_WANT_READ || Error == SSL_ERROR_WANT_WRITE)\r
                                                {\r
-                                                       DetachSSL(s);\r
-                                                       r = FALSE;\r
+                                                       LeaveCriticalSection(&g_OpenSSLLock);\r
+                                                       if(g_pOpenSSLTimeoutCallback() || (g_OpenSSLTimeout > 0 && timeGetTime() - Time >= g_OpenSSLTimeout))\r
+                                                               r = FALSE;\r
                                                        EnterCriticalSection(&g_OpenSSLLock);\r
-                                                       break;\r
                                                }\r
-                                               EnterCriticalSection(&g_OpenSSLLock);\r
+                                               else\r
+                                                       r = FALSE;\r
                                        }\r
                                        if(r)\r
                                        {\r
@@ -394,6 +400,12 @@ BOOL AttachSSL(SOCKET s, SOCKET parent)
                                                        EnterCriticalSection(&g_OpenSSLLock);\r
                                                }\r
                                        }\r
+                                       else\r
+                                       {\r
+                                               LeaveCriticalSection(&g_OpenSSLLock);\r
+                                               DetachSSL(s);\r
+                                               EnterCriticalSection(&g_OpenSSLLock);\r
+                                       }\r
                                }\r
                                else\r
                                {\r