@@ -115,15 +115,6 @@ const char* ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* ho
115115    }
116116    #endif 
117117
118-     #ifdef  TCP_FASTOPEN 
119-     // Set TCP Fast Open 
120-     if  (setsockopt (state -> sockfd , IPPROTO_TCP , TCP_FASTOPEN , (char * )& flag , sizeof (flag )) !=  0 ) {
121-         FF_DEBUG ("Failed to set TCP_FASTOPEN option: %s" , ffDebugWin32Error ((DWORD ) WSAGetLastError ()));
122-     } else  {
123-         FF_DEBUG ("Successfully set TCP_FASTOPEN option" );
124-     }
125-     #endif 
126- 
127118    // Set timeout if needed 
128119    if  (state -> timeout  >  0 ) {
129120        FF_DEBUG ("Setting connection timeout: %u ms" , state -> timeout );
@@ -169,18 +160,40 @@ const char* ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* ho
169160    ffStrbufAppendS (& command , headers );
170161    ffStrbufAppendS (& command , "\r\n" );
171162
163+     #ifdef  TCP_FASTOPEN 
164+     // Set TCP Fast Open 
165+     flag  =  1 ;
166+     if  (setsockopt (state -> sockfd , IPPROTO_TCP , TCP_FASTOPEN , (char * )& flag , sizeof (flag )) !=  0 ) {
167+         FF_DEBUG ("Failed to set TCP_FASTOPEN option: %s" , ffDebugWin32Error ((DWORD ) WSAGetLastError ()));
168+     } else  {
169+         FF_DEBUG ("Successfully set TCP_FASTOPEN option" );
170+     }
171+     #endif 
172+ 
172173    FF_DEBUG ("Using ConnectEx to send %u bytes of data" , command .length );
174+     DWORD  sent  =  0 ;
173175    BOOL  result  =  ConnectEx (state -> sockfd , addr -> ai_addr , (int )addr -> ai_addrlen ,
174-                           command .chars , command .length , NULL , & state -> overlapped );
176+                           command .chars , command .length , & sent , & state -> overlapped );
175177
176178    freeaddrinfo (addr );
177179
178-     if (!result   &&   WSAGetLastError ()  !=   WSA_IO_PENDING )
180+     if (!result )
179181    {
180-         FF_DEBUG ("ConnectEx() failed: %s" , ffDebugWin32Error ((DWORD ) WSAGetLastError ()));
181-         closesocket (state -> sockfd );
182-         state -> sockfd  =  INVALID_SOCKET ;
183-         return  "ConnectEx() failed" ;
182+         if  (WSAGetLastError () !=  WSA_IO_PENDING )
183+         {
184+             FF_DEBUG ("ConnectEx() failed: %s" , ffDebugWin32Error ((DWORD ) WSAGetLastError ()));
185+             closesocket (state -> sockfd );
186+             state -> sockfd  =  INVALID_SOCKET ;
187+             return  "ConnectEx() failed" ;
188+         }
189+         else 
190+         {
191+             FF_DEBUG ("ConnectEx() pending" );
192+         }
193+     }
194+     else 
195+     {
196+         FF_DEBUG ("ConnectEx() succeeded, sent %u bytes of data" , (unsigned ) sent );
184197    }
185198
186199    // No need to cleanup state fields here since we need them in the receive function 
0 commit comments