@@ -33,42 +33,37 @@ static const char* tryTcpFastOpen(FFNetworkingState* state)
3333 FF_DEBUG ("Successfully set TCP_FASTOPEN option, queue length: %d" , qlen );
3434 }
3535
36- // Set non-blocking mode
37- int flags = fcntl (state -> sockfd , F_GETFL , 0 );
38- FF_DEBUG ("Current socket flags: 0x%x" , flags );
39-
40- if (fcntl (state -> sockfd , F_SETFL , flags | O_NONBLOCK ) < 0 ) {
41- FF_DEBUG ("Failed to set non-blocking mode: %s" , strerror (errno ));
42- } else {
43- FF_DEBUG ("Successfully set non-blocking mode" );
44- }
45-
4636 // Try to send data using Fast Open
4737 FF_DEBUG ("Using sendto() + MSG_FASTOPEN to send %u bytes of data" , state -> command .length );
4838 ssize_t sent = sendto (state -> sockfd ,
4939 state -> command .chars ,
5040 state -> command .length ,
51- MSG_FASTOPEN ,
41+ MSG_FASTOPEN | MSG_DONTWAIT ,
5242 state -> addr -> ai_addr ,
5343 state -> addr -> ai_addrlen );
5444
55- // Restore blocking mode
56- fcntl (state -> sockfd , F_SETFL , flags );
57-
58- if (sent >= 0 || (errno == EINPROGRESS || errno == EAGAIN || errno == EWOULDBLOCK ))
45+ if (sent >= 0 || (errno == EAGAIN || errno == EWOULDBLOCK ))
5946 {
60- FF_DEBUG ("TCP Fast Open succeeded or in progress (sent=%zd, errno=%d: %s)" ,
61- sent , errno , sent < 0 ? strerror (errno ) : "" );
47+ FF_DEBUG ("TCP Fast Open %s (sent=%zd, errno=%d: %s)" , errno == 0 ? "succeeded" : "was in progress " ,
48+ sent , errno , strerror (errno ));
6249 freeaddrinfo (state -> addr );
6350 state -> addr = NULL ;
6451 ffStrbufDestroy (& state -> host );
6552 ffStrbufDestroy (& state -> command );
6653 return NULL ;
6754 }
6855
69- // Fast Open failed
70- FF_DEBUG ("TCP Fast Open failed: %s (errno=%d)" , strerror (errno ), errno );
71- return "sendto() failed" ;
56+ if (errno == EINPROGRESS )
57+ {
58+ FF_DEBUG ("TCP Fast Open cookie is not available locally" );
59+ return "sendto() reports EINPROGRESS" ;
60+ }
61+ else
62+ {
63+ // Fast Open failed
64+ FF_DEBUG ("TCP Fast Open failed: %s (errno=%d)" , strerror (errno ), errno );
65+ return "sendto() failed" ;
66+ }
7267 #endif
7368}
7469
@@ -334,7 +329,7 @@ const char* ffNetworkingRecvHttpResponse(FFNetworkingState* state, FFstrbuf* buf
334329 FF_DEBUG ("Data reception loop #%d, current buffer size: %u, available space: %u" ,
335330 ++ recvCount , buffer -> length , ffStrbufGetFree (buffer ));
336331
337- ssize_t received = recv (state -> sockfd , buffer -> chars + buffer -> length , ffStrbufGetFree (buffer ), 0 );
332+ ssize_t received = recv (state -> sockfd , buffer -> chars + buffer -> length , ffStrbufGetFree (buffer ), MSG_WAITALL );
338333
339334 if (received <= 0 ) {
340335 if (received == 0 ) {
0 commit comments