[WSD] Make QP destruction asynchronous to speed up socket closure.
[mirror/winof/.git] / ulp / wsd / user / ibspdll.c
index 7933df0..e7bf41b 100644 (file)
@@ -242,7 +242,6 @@ IBSPAccept(
        struct ibsp_socket_info *socket_info = (struct ibsp_socket_info *)s;\r
        struct ibsp_socket_info *new_socket_info;\r
        int ret;\r
-       SOCKET new_socket = INVALID_SOCKET;\r
        WSABUF caller_id;\r
        WSABUF callee_id;\r
        struct listen_incoming *incoming;\r
@@ -397,45 +396,24 @@ reject:
        }\r
 \r
        /* Create a new socket here  */\r
-       new_socket_info = create_socket_info();\r
-       if( new_socket_info == NULL )\r
+       new_socket_info = create_socket_info( lpErrno );\r
+       if( !new_socket_info )\r
        {\r
                cl_spinlock_release( &socket_info->mutex );\r
 \r
-               IBSP_ERROR_EXIT( ("create_socket_info return NULL\n") );\r
-               *lpErrno = WSAENOBUFS;\r
-               return INVALID_SOCKET;\r
-       }\r
-\r
-       new_socket = g_ibsp.up_call_table.lpWPUCreateSocketHandle(\r
-               0, (DWORD_PTR)new_socket_info, lpErrno );\r
-\r
-       if( new_socket == INVALID_SOCKET )\r
-       {\r
-               cl_spinlock_release( &socket_info->mutex );\r
-\r
-               IBSP_ERROR_EXIT(\r
-                       ("WPUCreateSocketHandle() failed: %d", *lpErrno) );\r
-               deref_socket_info( new_socket_info );\r
+               IBSP_ERROR_EXIT( ("create_socket_info failed (%d)\n", *lpErrno) );\r
                return INVALID_SOCKET;\r
        }\r
 \r
-       STAT_INC( wpusocket_num );\r
-\r
-       fzprint(("%s():%d:0x%x:0x%x: new_socket_info=0x%p new_socket=0x%p \n", __FUNCTION__,\r
-                        __LINE__, GetCurrentProcessId(), GetCurrentThreadId(), new_socket_info,\r
-                        new_socket));\r
-\r
        /* Time to allocate our IB QP */\r
        new_socket_info->port = port;\r
-       ret = ib_create_socket( new_socket_info );\r
-       if( ret )\r
+       *lpErrno = ib_create_socket( new_socket_info );\r
+       if( *lpErrno )\r
        {\r
                cl_spinlock_release( &socket_info->mutex );\r
+               deref_socket_info( new_socket_info );\r
 \r
-               IBSP_ERROR_EXIT(\r
-                       ("ib_create socket failed with %d\n", ret) );\r
-               *lpErrno = WSAENOBUFS;\r
+               IBSP_ERROR_EXIT( ("ib_create socket failed with %d\n", *lpErrno) );\r
                return INVALID_SOCKET;\r
        }\r
 \r
@@ -456,11 +434,11 @@ reject:
        memcpy( addr, &incoming->params.source, sizeof(struct sockaddr_in) );\r
        *addrlen = sizeof(struct sockaddr_in);\r
 \r
-       IBSP_TRACE( IBSP_DBG_CONN, ("The socket address of connecting entity is\n") );\r
+       IBSP_TRACE( IBSP_DBG_CONN,\r
+               ("The socket address of connecting entity is\n") );\r
        DebugPrintSockAddr( IBSP_DBG_CONN, gdbg_lvl, &incoming->params.source );\r
 \r
        new_socket_info->peer_addr = incoming->params.source;\r
-       new_socket_info->switch_socket = new_socket;\r
 \r
        new_socket_info->h_event = CreateEvent( NULL, FALSE, FALSE, NULL );\r
 \r
@@ -473,10 +451,6 @@ reject:
        {\r
                IBSP_CHANGE_SOCKET_STATE( new_socket_info, IBSP_CREATE );\r
                cl_spinlock_release( &new_socket_info->mutex );\r
-               /* Free the socket descriptor */\r
-               fzprint(("%s():%d:0x%x:0x%x: socket=0x%p calling lpWPUCloseSocketHandle=0x%p\n",\r
-                                __FUNCTION__, __LINE__, GetCurrentProcessId(), GetCurrentThreadId(),\r
-                                socket_info, socket_info->switch_socket));\r
 \r
                if( g_ibsp.up_call_table.lpWPUCloseSocketHandle(\r
                        new_socket_info->switch_socket, &ret ) == SOCKET_ERROR )\r
@@ -536,8 +510,6 @@ reject:
                                /* The accept failed (by a REJ for instance). */\r
 \r
                                /* Free the socket descriptor */\r
-                               fzprint(("%s():%d:0x%x:0x%x: socket=0x%p calling lpWPUCloseSocketHandle=0x%p\n", __FUNCTION__, __LINE__, GetCurrentProcessId(), GetCurrentThreadId(), socket_info, socket_info->switch_socket));\r
-\r
                                if( g_ibsp.up_call_table.lpWPUCloseSocketHandle(\r
                                        new_socket_info->switch_socket, lpErrno ) == SOCKET_ERROR )\r
                                {\r
@@ -558,8 +530,8 @@ reject:
                                new_socket_info = (struct ibsp_socket_info *)INVALID_SOCKET;\r
                        }\r
 \r
-                       CL_TRACE_EXIT(IBSP_DBG_CONN, gdbg_lvl,\r
-                               ("returns new SocketID (0x%x)\n", new_socket) );\r
+                       IBSP_TRACE_EXIT( IBSP_DBG_CONN,\r
+                               ("returns new SocketID (0x%x)\n", new_socket_info) );\r
 \r
                        return (SOCKET) new_socket_info;\r
                }\r
@@ -2095,86 +2067,69 @@ IBSPSocket(
 \r
        if( af != AF_INET )\r
        {\r
-               IBSP_ERROR(\r
+               IBSP_ERROR_EXIT(\r
                        ("bad family %d instead of %d\n", af, AF_INET) );\r
                *lpErrno = WSAEAFNOSUPPORT;\r
-               goto error;\r
+               return INVALID_SOCKET;\r
        }\r
 \r
        if( type != SOCK_STREAM )\r
        {\r
-               IBSP_ERROR(\r
+               IBSP_ERROR_EXIT(\r
                        ("bad type %d instead of %d\n", type, SOCK_STREAM) );\r
                *lpErrno = WSAEPROTOTYPE;\r
-               goto error;\r
+               return INVALID_SOCKET;\r
        }\r
 \r
        if( protocol != IPPROTO_TCP )\r
        {\r
-               IBSP_ERROR(\r
+               IBSP_ERROR_EXIT(\r
                        ("bad protocol %d instead of %d\n", protocol, IPPROTO_TCP) );\r
                *lpErrno = WSAEPROTONOSUPPORT;\r
-               goto error;\r
+               return INVALID_SOCKET;\r
        }\r
 \r
        if( (dwFlags != WSA_FLAG_OVERLAPPED) )\r
        {\r
-               IBSP_ERROR(\r
+               IBSP_ERROR_EXIT(\r
                        ("dwFlags is not WSA_FLAG_OVERLAPPED (%x)\n", dwFlags) );\r
                *lpErrno = WSAEINVAL;\r
-               goto error;\r
+               return INVALID_SOCKET;\r
        }\r
 \r
-       socket_info = create_socket_info();\r
+       socket_info = create_socket_info( lpErrno );\r
        if( socket_info == NULL )\r
        {\r
-               IBSP_ERROR( ("create_socket_info return NULL\n") );\r
-               *lpErrno = WSAENOBUFS;\r
-               goto error;\r
+               IBSP_ERROR_EXIT( ("create_socket_info return NULL\n") );\r
+               return INVALID_SOCKET;\r
        }\r
 \r
        if( lpProtocolInfo->dwProviderReserved != 0 )\r
        {\r
                /* This is a duplicate socket. */\r
-               int ret;\r
-\r
-               ret = setup_duplicate_socket( socket_info, lpProtocolInfo->dwProviderReserved );\r
-               if( ret )\r
-               {\r
-                       IBSP_ERROR(\r
-                               ("setup_duplicate_socket failed with %d\n",ret) );\r
-                       *lpErrno = ret;\r
-                       goto error;\r
-               }\r
-       }\r
-       else\r
-       {\r
-               socket_info->switch_socket =\r
-                       g_ibsp.up_call_table.lpWPUCreateSocketHandle( 0,\r
-                                                                                                                (DWORD_PTR) socket_info,\r
-                                                                                                                lpErrno );\r
-\r
-               if( socket_info->switch_socket != INVALID_SOCKET )\r
+               *lpErrno = setup_duplicate_socket(\r
+                       socket_info, lpProtocolInfo->dwProviderReserved );\r
+               if( *lpErrno )\r
                {\r
-                       IBSP_TRACE1( IBSP_DBG_SI, ("socket_info=0x%p switch_socket=0x%p \n",\r
-                               socket_info, socket_info->switch_socket) );\r
+                       int error;\r
 \r
-                       STAT_INC( wpusocket_num );\r
-               }\r
-       }\r
+                       if( g_ibsp.up_call_table.lpWPUCloseSocketHandle(\r
+                               socket_info->switch_socket, &error ) == SOCKET_ERROR )\r
+                       {\r
+                               IBSP_ERROR( ("WPUCloseSocketHandle failed: %d\n", error) );\r
+                       }\r
+                       else\r
+                       {\r
+                               STAT_DEC( wpusocket_num );\r
+                       }\r
 \r
-       if( socket_info->switch_socket == INVALID_SOCKET )\r
-       {\r
-               IBSP_ERROR(\r
-                       ("WPUCreateSocketHandle() failed: %d\n", *lpErrno) );\r
-               /* lpErrno has just been set */\r
-               goto error;\r
-       }\r
+                       socket_info->switch_socket = INVALID_SOCKET;\r
 \r
-       /* Success */\r
-       if( lpProtocolInfo->dwProviderReserved != 0 )\r
-       {\r
-               CL_ASSERT( socket_info->socket_state == IBSP_CONNECTED );\r
+                       deref_socket_info( socket_info );\r
+                       IBSP_ERROR(\r
+                               ("setup_duplicate_socket failed with %d\n", *lpErrno) );\r
+                       return INVALID_SOCKET;\r
+               }\r
        }\r
        else\r
        {\r
@@ -2199,16 +2154,6 @@ IBSPSocket(
                ("returning socket handle %p\n", socket_info) );\r
 \r
        return (SOCKET) socket_info;\r
-\r
-error:\r
-       if( socket_info )\r
-               deref_socket_info( socket_info );\r
-\r
-       CL_ASSERT( *lpErrno != 0 );\r
-\r
-       IBSP_ERROR_EXIT( ("Returning error %d\n", *lpErrno) );\r
-\r
-       return INVALID_SOCKET;\r
 }\r
 \r
 \r