[WSD] Make QP destruction asynchronous to speed up socket closure.
[mirror/winof/.git] / ulp / wsd / user / ibsp_duplicate.c
index e7108f5..9258da4 100644 (file)
@@ -79,19 +79,17 @@ setup_duplicate_socket(
                                                  fname );      // name of map object\r
        if( h == NULL )\r
        {\r
-               IBSP_ERROR(\r
-                       ("CreateFileMapping failed with %d\n", GetLastError()) );\r
+               IBSP_ERROR( ("CreateFileMapping failed with %d\n", GetLastError()) );\r
                ret = WSAENETDOWN;\r
-               goto done;\r
+               goto err1;\r
        }\r
 \r
        /* Make sure this file already existed. */\r
        if( GetLastError() != ERROR_ALREADY_EXISTS )\r
        {\r
-               CloseHandle( h );\r
                IBSP_ERROR( ("not mapping for socket duplicate info\n") );\r
                ret = WSAENETDOWN;\r
-               goto done;\r
+               goto err1;\r
        }\r
 \r
        /* Get a pointer to the file-mapped shared memory. */\r
@@ -102,34 +100,9 @@ setup_duplicate_socket(
                                                         0 );   // default: map entire file\r
        if( dup_info == NULL )\r
        {\r
-               IBSP_ERROR(\r
-                       ("MapViewOfFile failed with %d\n", GetLastError()) );\r
+               IBSP_ERROR( ("MapViewOfFile failed with %d\n", GetLastError()) );\r
                ret = WSAENETDOWN;\r
-               goto done;\r
-       }\r
-\r
-       /* Check if we already have a switch socket handle. We can have both cases \r
-        * if the two processes are calling IBSPDuplicate back and forth. */\r
-       if( socket_info->switch_socket == INVALID_SOCKET )\r
-       {\r
-               socket_info->switch_socket =\r
-                       g_ibsp.up_call_table.lpWPUCreateSocketHandle(0,\r
-                                                                                                                (DWORD_PTR) socket_info, &ret );\r
-\r
-               if( socket_info->switch_socket == INVALID_SOCKET )\r
-               {\r
-                       IBSP_ERROR(\r
-                               ("WPUCreateSocketHandle() failed: %d", ret) );\r
-                       goto done;\r
-               }\r
-               else\r
-               {\r
-                       fzprint(("%s():%d:0x%x:0x%x: socket_info=0x%p switch_socket=0x%p \n",\r
-                                        __FUNCTION__, __LINE__, GetCurrentProcessId(), GetCurrentThreadId(),\r
-                                        socket_info, socket_info->switch_socket));\r
-\r
-                       STAT_INC( wpusocket_num );\r
-               }\r
+               goto err1;\r
        }\r
 \r
        socket_info->peer_addr = dup_info->peer_addr;\r
@@ -143,32 +116,21 @@ setup_duplicate_socket(
        socket_info->port = get_port_from_ip_address( dup_info->local_addr.sin_addr );\r
        if( socket_info->port == NULL )\r
        {\r
-               IBSP_ERROR(\r
-                       ("incoming destination IP address not local (%s)\n",\r
+               IBSP_ERROR( ("incoming destination IP address not local (%s)\n",\r
                        inet_ntoa( dup_info->local_addr.sin_addr )) );\r
                ret = WSAENETDOWN;\r
-               goto done;\r
-       }\r
-\r
-       ret = ib_create_socket( socket_info );\r
-       if( ret )\r
-       {\r
-               IBSP_ERROR_EXIT(\r
-                       ("ib_create socket failed with %d\n", ret) );\r
-               ret = WSAENOBUFS;\r
-               goto done;\r
+               goto err1;\r
        }\r
 \r
        /* Get the GUID for the remote IP address. */\r
        ret = query_guid_address( socket_info->port,\r
-                                                        socket_info->peer_addr.sin_addr.S_un.S_addr,\r
-                                                        &dest_port_guid );\r
+               socket_info->peer_addr.sin_addr.S_un.S_addr, &dest_port_guid );\r
        if( ret )\r
        {\r
                IBSP_ERROR( ("query_guid_address failed for IP %08x\n",\r
                        socket_info->peer_addr.sin_addr.s_addr) );\r
-               ret = WSAEHOSTUNREACH;\r
-               goto done;\r
+               ret = WSAENETDOWN;\r
+               goto err1;\r
        }\r
 \r
        /* Get the path record */\r
@@ -177,39 +139,51 @@ setup_duplicate_socket(
        {\r
                IBSP_ERROR( ("query_pr failed for IP %08x\n",\r
                        socket_info->peer_addr.sin_addr.s_addr) );\r
-               ret = WSAEHOSTUNREACH;\r
-               goto done;\r
+               ret = WSAENETDOWN;\r
+               goto err1;\r
        }\r
 \r
        IBSP_CHANGE_SOCKET_STATE( socket_info, IBSP_DUPLICATING_NEW );\r
        socket_info->h_event = CreateEvent( NULL, FALSE, FALSE, NULL );\r
+       if( !socket_info->h_event )\r
+       {\r
+               IBSP_ERROR( ("CreateEvent failed (%d)\n", GetLastError()) );\r
+               goto err1;\r
+       }\r
+\r
+       ret = ib_create_socket( socket_info );\r
+       if( ret )\r
+       {\r
+               IBSP_ERROR( ("ib_create socket failed with %d\n", ret) );\r
+               goto err1;\r
+       }\r
 \r
        /* Connects the QP. */\r
        ret = ib_connect( socket_info, &path_rec );\r
        if( ret != WSAEWOULDBLOCK )\r
        {\r
                IBSP_ERROR( ("ib_connect failed (%d)\n", ret) );\r
-               goto done;\r
+               goto err2;\r
        }\r
 \r
        if( WaitForSingleObject( socket_info->h_event, INFINITE ) != WAIT_OBJECT_0 )\r
-       {\r
                IBSP_ERROR( ("WaitForSingleObject failed\n") );\r
-       }\r
 \r
        cl_spinlock_acquire( &socket_info->mutex );\r
        if( socket_info->socket_state != IBSP_CONNECTED )\r
        {\r
                cl_spinlock_release( &socket_info->mutex );\r
                IBSP_ERROR( ("Failed to connect\n") );\r
-               ret = WSAEHOSTUNREACH;\r
-               goto done;\r
+               ret = WSAENETDOWN;\r
+err2:\r
+               ib_destroy_socket( socket_info );\r
+       }\r
+       else\r
+       {\r
+               cl_spinlock_release( &socket_info->mutex );\r
        }\r
-       cl_spinlock_release( &socket_info->mutex );\r
-\r
-       ret = 0;\r
 \r
-done:\r
+err1:\r
        if( h )\r
                CloseHandle( h );\r
 \r
@@ -220,7 +194,6 @@ done:
        }\r
 \r
        IBSP_EXIT( IBSP_DBG_CONN );\r
-\r
        return ret;\r
 }\r
 \r