Bug 1380612, Minor changes to tcp fast open. r=mayhemer r=kaie NSPR_4_16_BETA2
authorKai Engert <kaie@kuix.de>
Fri, 14 Jul 2017 16:20:42 +0200
changeset 4745 6bbe01dd9325
parent 4744 17303e0dde44
child 4746 5c8f7661fb7e
push id263
push userkaie@kuix.de
push date2017-07-14 14:20 +0000
reviewersmayhemer, kaie
bugs1380612
Bug 1380612, Minor changes to tcp fast open. r=mayhemer r=kaie
pr/src/io/prsocket.c
pr/src/md/windows/w95sock.c
--- a/pr/src/io/prsocket.c
+++ b/pr/src/io/prsocket.c
@@ -317,17 +317,17 @@ static PRStatus PR_CALLBACK SocketConnec
     }
     /* TCP Fast Open on Windows must use ConnectEx, which uses overlapped
      * input/output.
      * To get result we need to use GetOverlappedResult. */
     if (fd->secret->overlappedActive) {
         PR_ASSERT(fd->secret->nonblocking);
         PRInt32 rvSent;
         if (GetOverlappedResult(osfd, &fd->secret->ol, &rvSent, FALSE) == TRUE) {
-            fd->secret->overlappedActive = FALSE;
+            fd->secret->overlappedActive = PR_FALSE;
             PR_LOG(_pr_io_lm, PR_LOG_MIN,
                ("SocketConnectContinue GetOverlappedResult succeeded\n"));
             /* When ConnectEx is used, all previously set socket options and
              * property are not enabled and to enable them
              * SO_UPDATE_CONNECT_CONTEXT option need to be set. */
             if (setsockopt((SOCKET)osfd, SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, NULL, 0) != 0) {
                 err = WSAGetLastError();
                 PR_LOG(_pr_io_lm, PR_LOG_MIN,
@@ -337,17 +337,17 @@ static PRStatus PR_CALLBACK SocketConnec
             }
             return PR_SUCCESS;
         } else {
             err = WSAGetLastError();
             PR_LOG(_pr_io_lm, PR_LOG_MIN,
                ("SocketConnectContinue GetOverlappedResult failed %d\n", err));
             if (err != ERROR_IO_INCOMPLETE) {
                 _PR_MD_MAP_CONNECT_ERROR(err);
-                fd->secret->overlappedActive = FALSE;
+                fd->secret->overlappedActive = PR_FALSE;
                 return PR_FAILURE;
             } else {
                 PR_SetError(PR_IN_PROGRESS_ERROR, 0);
                 return PR_FAILURE;
             }
         }
     }
 #endif
--- a/pr/src/md/windows/w95sock.c
+++ b/pr/src/md/windows/w95sock.c
@@ -328,33 +328,36 @@ PRInt32
         }
     } while(bytesSent < amount);
     return bytesSent;
 }
 
 #if defined(_WIN64)
 
 static PRCallOnceType _pr_has_connectex_once;
-typedef BOOL (WINAPI *_pr_win_connectex_ptr)(SOCKET, const struct sockaddr *, int, PVOID, DWORD, LPDWORD, LPOVERLAPPED);
+typedef BOOL (PASCAL FAR * _pr_win_connectex_ptr)(_In_ SOCKET s, _In_reads_bytes_(namelen) const struct sockaddr FAR *name, _In_ int namelen, _In_reads_bytes_opt_(dwSendDataLength) PVOID lpSendBuffer, _In_ DWORD dwSendDataLength, _Out_ LPDWORD lpdwBytesSent, _Inout_ LPOVERLAPPED lpOverlapped);
+
+
+
 #ifndef WSAID_CONNECTEX
 #define WSAID_CONNECTEX \
   {0x25a207b9,0xddf3,0x4660,{0x8e,0xe9,0x76,0xe5,0x8c,0x74,0x06,0x3e}}
 #endif
 #ifndef SIO_GET_EXTENSION_FUNCTION_POINTER
 #define SIO_GET_EXTENSION_FUNCTION_POINTER 0xC8000006
 #endif
 #ifndef TCP_FASTOPEN
 #define TCP_FASTOPEN 15
 #endif
 
 #ifndef SO_UPDATE_CONNECT_CONTEXT
 #define SO_UPDATE_CONNECT_CONTEXT 0x7010
 #endif
 
-static _pr_win_connectex_ptr _pr_win_connectex;
+static _pr_win_connectex_ptr _pr_win_connectex = NULL;
 
 static PRStatus PR_CALLBACK _pr_set_connectex(void)
 {
     _pr_win_connectex = NULL;
     SOCKET sock;
     PRInt32 dwBytes;
     int rc;
 
@@ -453,24 +456,29 @@ PRInt32
     } else {
         err = WSAGetLastError();
         PR_LOG(_pr_io_lm, PR_LOG_MIN,
                ("_PR_MD_TCPSENDTO error _pr_win_connectex failed %d\n", err));
         if (err != ERROR_IO_PENDING) {
             _PR_MD_MAP_CONNECT_ERROR(err);
             return -1;
         } else if (fd->secret->nonblocking) {
-            /* Remember that overlapped structure is set. We will neede to get
+            /* Remember that overlapped structure is set. We will need to get
              * the final result of ConnectEx call. */
             fd->secret->overlappedActive = PR_TRUE;
-            _PR_MD_MAP_CONNECT_ERROR(WSAEWOULDBLOCK);
+
             /* ConnectEx will copy supplied data to a internal buffer and send
              * them during Fast Open or after connect. Therefore we can assumed
              * this data already send. */
-            return amount;
+            if (amount > 0) {
+              return amount;
+            }
+
+            _PR_MD_MAP_CONNECT_ERROR(WSAEWOULDBLOCK);
+            return -1;
         }
         // err is ERROR_IO_PENDING and socket is blocking, so query
         // GetOverlappedResult.
         err = ERROR_IO_INCOMPLETE;
         while (err == ERROR_IO_INCOMPLETE) {
             rv = socket_io_wait(osfd, WRITE_FD, timeout);
             if ( rv < 0 ) {
                 return -1;