Bug 1386719 - If poll returns PR_POLL_EXCEPT during ConnectEx on windows check OVERLAPPED as well. r=mcmanus r=mayhemer
authorDragana Damjanovic <dd.mozilla@gmail.com>
Fri, 25 Aug 2017 17:06:34 +0200
changeset 4753 aa88ba8082ec
parent 4752 a0c729571e27
child 4754 6a0af7609427
push id270
push userkaie@kuix.de
push date2017-08-25 15:08 +0000
reviewersmcmanus, mayhemer
bugs1386719
Bug 1386719 - If poll returns PR_POLL_EXCEPT during ConnectEx on windows check OVERLAPPED as well. r=mcmanus r=mayhemer
pr/src/io/prsocket.c
pr/src/md/windows/win32_errors.c
--- a/pr/src/io/prsocket.c
+++ b/pr/src/io/prsocket.c
@@ -299,17 +299,31 @@ static PRStatus PR_CALLBACK SocketConnec
         if (getsockopt(osfd, (int)SOL_SOCKET, SO_ERROR, (char *) &err, &len)
                 == SOCKET_ERROR) {
             _PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
             return PR_FAILURE;
         }
         if (err != 0) {
             _PR_MD_MAP_CONNECT_ERROR(err);
         } else {
-            PR_SetError(PR_UNKNOWN_ERROR, 0);
+            if (fd->secret->overlappedActive) {
+                PRInt32 rvSent;
+                if (GetOverlappedResult(osfd, &fd->secret->ol, &rvSent, FALSE) == FALSE) {
+                    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 = PR_FALSE;
+                    }
+                }
+            }
+            if (err == 0) {
+                PR_SetError(PR_UNKNOWN_ERROR, 0);
+            }
         }
         return PR_FAILURE;
     }
 
     PR_ASSERT(out_flags & PR_POLL_WRITE);
 
 #if defined(_WIN64)
     if (fd->secret->alreadyConnected) {
--- a/pr/src/md/windows/win32_errors.c
+++ b/pr/src/md/windows/win32_errors.c
@@ -161,64 +161,72 @@ void _MD_win32_map_default_error(PRInt32
             break;
         case WSAEACCES:
             prError = PR_NO_ACCESS_RIGHTS_ERROR;
             break;
         case WSAEADDRINUSE:
             prError = PR_ADDRESS_IN_USE_ERROR;
             break;
         case WSAEADDRNOTAVAIL:
+        case ERROR_INVALID_NETNAME:
             prError = PR_ADDRESS_NOT_AVAILABLE_ERROR;
             break;
         case WSAEAFNOSUPPORT:
+        case ERROR_INCORRECT_ADDRESS:
             prError = PR_ADDRESS_NOT_SUPPORTED_ERROR;
             break;
         case WSAEALREADY:
+        case ERROR_ALREADY_INITIALIZED:
             prError = PR_ALREADY_INITIATED_ERROR;
             break;
         case WSAEBADF:
             prError = PR_BAD_DESCRIPTOR_ERROR;
             break;
         case WSAECONNABORTED:
+        case ERROR_CONNECTION_ABORTED:
             prError = PR_CONNECT_ABORTED_ERROR;
             break;
         case WSAECONNREFUSED:
+        case ERROR_CONNECTION_REFUSED:
             prError = PR_CONNECT_REFUSED_ERROR;
             break;
         case WSAECONNRESET:
             prError = PR_CONNECT_RESET_ERROR;
             break;
         case WSAEDESTADDRREQ:
             prError = PR_INVALID_ARGUMENT_ERROR;
             break;
         case WSAEFAULT:
             prError = PR_ACCESS_FAULT_ERROR;
             break;
         case WSAEHOSTUNREACH:
+        case ERROR_HOST_UNREACHABLE:
             prError = PR_HOST_UNREACHABLE_ERROR;
             break;
         case WSAEINVAL:
             prError = PR_INVALID_ARGUMENT_ERROR;
             break;
         case WSAEISCONN:
             prError = PR_IS_CONNECTED_ERROR;
             break;
         case WSAEMFILE:
             prError = PR_PROC_DESC_TABLE_FULL_ERROR;
             break;
         case WSAEMSGSIZE:
             prError = PR_BUFFER_OVERFLOW_ERROR;
             break;
         case WSAENETDOWN:
+        case ERROR_NO_NETWORK:
             prError = PR_NETWORK_DOWN_ERROR;
             break;
         case WSAENETRESET:
             prError = PR_CONNECT_ABORTED_ERROR;
             break;
         case WSAENETUNREACH:
+        case ERROR_NETWORK_UNREACHABLE:
             prError = PR_NETWORK_UNREACHABLE_ERROR;
             break;
         case WSAENOBUFS:
             prError = PR_INSUFFICIENT_RESOURCES_ERROR;
             break;
         case WSAENOPROTOOPT:
             prError = PR_INVALID_ARGUMENT_ERROR;
             break;