[ros-diffs] [cgutman] 47643: [MSAFD] - Fix many times where we wait for an operation but don't update our status and return if it failed - Fix the overlapped pending case in writing which was completely broken (callers would detect an error but GetLastError would return 0 because we didn't store the error in the lpErrno variable) - Fix many times where we pass a pointer to an event that we close without waiting - Fix a bug in WSPEnumNetworkEvents when we would set WSAEINVAL in the lpErrno variable but not return SOCKET_ERROR so the error got ignored

cgutman at svn.reactos.org cgutman at svn.reactos.org
Mon Jun 7 01:07:27 CEST 2010


Author: cgutman
Date: Mon Jun  7 01:07:26 2010
New Revision: 47643

URL: http://svn.reactos.org/svn/reactos?rev=47643&view=rev
Log:
[MSAFD]
- Fix many times where we wait for an operation but don't update our status and return if it failed
- Fix the overlapped pending case in writing which was completely broken (callers would detect an error but GetLastError would return 0 because we didn't store the error in the lpErrno variable)
- Fix many times where we pass a pointer to an event that we close without waiting
- Fix a bug in WSPEnumNetworkEvents when we would set WSAEINVAL in the lpErrno variable but not return SOCKET_ERROR so the error got ignored

Modified:
    trunk/reactos/dll/win32/msafd/misc/dllmain.c
    trunk/reactos/dll/win32/msafd/misc/event.c
    trunk/reactos/dll/win32/msafd/misc/sndrcv.c

Modified: trunk/reactos/dll/win32/msafd/misc/dllmain.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msafd/misc/dllmain.c?rev=47643&r1=47642&r2=47643&view=diff
==============================================================================
--- trunk/reactos/dll/win32/msafd/misc/dllmain.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/msafd/misc/dllmain.c [iso-8859-1] Mon Jun  7 01:07:26 2010
@@ -566,7 +566,7 @@
     NtClose((HANDLE)Handle);
     NtClose(SockEvent);
 
-    return NO_ERROR;
+    return MsafdReturnWithErrno(Status, lpErrno, 0, NULL);
 }
 
 
@@ -666,13 +666,17 @@
         Status = IOSB.Status;
     }
 
+    NtClose( SockEvent );
+    HeapFree(GlobalHeap, 0, BindData);
+
+    if (Status != STATUS_SUCCESS)
+        return MsafdReturnWithErrno ( Status, lpErrno, 0, NULL );
+
     /* Set up Socket Data */
     Socket->SharedData.State = SocketBound;
     Socket->TdiAddressHandle = (HANDLE)IOSB.Information;
 
-    NtClose( SockEvent );
-    HeapFree(GlobalHeap, 0, BindData);
-    if (Status == STATUS_SUCCESS && (Socket->HelperEvents & WSH_NOTIFY_BIND))
+    if (Socket->HelperEvents & WSH_NOTIFY_BIND)
     {
         Status = Socket->HelperData->WSHNotify(Socket->HelperContext,
                                                Socket->Handle,
@@ -739,14 +743,17 @@
     {
         WaitForSingleObject(SockEvent, INFINITE);
         Status = IOSB.Status;
-    }         
+    }
+
+    NtClose( SockEvent );
+
+    if (Status != STATUS_SUCCESS)
+       return MsafdReturnWithErrno ( Status, lpErrno, 0, NULL );
 
     /* Set to Listening */
     Socket->SharedData.Listening = TRUE;
 
-    NtClose( SockEvent );
-
-    if (Status == STATUS_SUCCESS && (Socket->HelperEvents & WSH_NOTIFY_LISTEN))
+    if (Socket->HelperEvents & WSH_NOTIFY_LISTEN)
     {
         Status = Socket->HelperData->WSHNotify(Socket->HelperContext,
                                                Socket->Handle,
@@ -907,6 +914,7 @@
     if (Status == STATUS_PENDING)
     {
         WaitForSingleObject(SockEvent, INFINITE);
+        Status = IOSB.Status;
     }
 
     /* Clear the Structures */
@@ -1440,6 +1448,9 @@
             WaitForSingleObject(SockEvent, INFINITE);
             Status = IOSB.Status;
         }
+
+        if (Status != STATUS_SUCCESS)
+            goto notify;
     }
 
     /* Dynamic Structure...ugh */
@@ -1485,6 +1496,9 @@
             WaitForSingleObject(SockEvent, INFINITE);
             Status = IOSB.Status;
         }
+
+        if (Status != STATUS_SUCCESS)
+            goto notify;
     }
 
     /* AFD doesn't seem to care if these are invalid, but let's 0 them anyways */
@@ -1515,6 +1529,9 @@
         WaitForSingleObject(SockEvent, INFINITE);
         Status = IOSB.Status;
     }
+
+    if (Status != STATUS_SUCCESS)
+        goto notify;
 
     Socket->TdiConnectionHandle = (HANDLE)IOSB.Information;
 
@@ -1539,13 +1556,14 @@
         }
     }
 
+    AFD_DbgPrint(MID_TRACE,("Ending\n"));
+
+notify:
     /* Re-enable Async Event */
     SockReenableAsyncSelectEvent(Socket, FD_WRITE);
 
     /* FIXME: THIS IS NOT RIGHT!!! HACK HACK HACK! */
     SockReenableAsyncSelectEvent(Socket, FD_CONNECT);
-
-    AFD_DbgPrint(MID_TRACE,("Ending\n"));
 
     NtClose( SockEvent );
 
@@ -2139,7 +2157,11 @@
     if (Status == STATUS_PENDING)
     {
         WaitForSingleObject(SockEvent, INFINITE);
-    }
+        Status = IOSB.Status;
+    }
+
+    if (Status != STATUS_SUCCESS)
+        return -1;
 
     /* Return Information */
     if (Ulong != NULL)
@@ -2210,11 +2232,12 @@
     if (Status == STATUS_PENDING)
     {
         WaitForSingleObject(SockEvent, INFINITE);
+        Status = IOSB.Status;
     }
 
     NtClose( SockEvent );
 
-    return 0;
+    return Status == STATUS_SUCCESS ? 0 : -1;
 
 }
 
@@ -2275,11 +2298,12 @@
     if (Status == STATUS_PENDING)
     {
         WaitForSingleObject(SockEvent, INFINITE);
+        Status = IOSB.Status;
     }
 
     NtClose( SockEvent );
 
-    return 0;
+    return Status == STATUS_SUCCESS ? 0 : -1;
 }
 
 BOOLEAN SockCreateOrReferenceAsyncThread(VOID)

Modified: trunk/reactos/dll/win32/msafd/misc/event.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msafd/misc/event.c?rev=47643&r1=47642&r2=47643&view=diff
==============================================================================
--- trunk/reactos/dll/win32/msafd/misc/event.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/msafd/misc/event.c [iso-8859-1] Mon Jun  7 01:07:26 2010
@@ -104,11 +104,15 @@
     /* Wait for return */
     if (Status == STATUS_PENDING) {
 	WaitForSingleObject(SockEvent, INFINITE);
+        Status = IOSB.Status;
     }
 
     AFD_DbgPrint(MID_TRACE,("Waited\n"));
 
     NtClose( SockEvent );
+
+    if (Status != STATUS_SUCCESS)
+        return MsafdReturnWithErrno(Status, lpErrno, 0, NULL);
 
     AFD_DbgPrint(MID_TRACE,("Closed event\n"));
 
@@ -168,12 +172,15 @@
     /* Wait for return */
     if (Status == STATUS_PENDING) {
 	WaitForSingleObject(SockEvent, INFINITE);
-	Status = STATUS_SUCCESS;
+	Status = IOSB.Status;
     }
 
     AFD_DbgPrint(MID_TRACE,("Waited\n"));
 
     NtClose( SockEvent );
+
+    if (Status != STATUS_SUCCESS)
+        return MsafdReturnWithErrno(Status, lpErrno, 0, NULL);
 
     AFD_DbgPrint(MID_TRACE,("Closed event\n"));
     AFD_DbgPrint(MID_TRACE,("About to touch struct at %x (%d)\n", 
@@ -226,12 +233,9 @@
 	lpNetworkEvents->iErrorCode[FD_GROUP_QOS_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_GROUP_QOS_BIT]);
     }
 
-    if( NT_SUCCESS(Status) ) *lpErrno = 0;
-    else *lpErrno = WSAEINVAL;
-
     AFD_DbgPrint(MID_TRACE,("Leaving\n"));
 
-    return 0;
+    return MsafdReturnWithErrno(STATUS_SUCCESS, lpErrno, 0, NULL);
 }
 
 /* EOF */

Modified: trunk/reactos/dll/win32/msafd/misc/sndrcv.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msafd/misc/sndrcv.c?rev=47643&r1=47642&r2=47643&view=diff
==============================================================================
--- trunk/reactos/dll/win32/msafd/misc/sndrcv.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/msafd/misc/sndrcv.c [iso-8859-1] Mon Jun  7 01:07:26 2010
@@ -182,7 +182,7 @@
 
     /* Send IOCTL */
     Status = NtDeviceIoControlFile((HANDLE)Handle,
-        Event ? Event : SockEvent,
+        Event,
         APCFunction,
         APCContext,
         IOSB,
@@ -208,6 +208,9 @@
 
     /* Return the Flags */
     *ReceiveFlags = 0;
+
+    if (Status == STATUS_PENDING)
+        return MsafdReturnWithErrno(Status, lpErrno, IOSB->Information, lpNumberOfBytesRead);
 
     switch (Status)
     {
@@ -223,7 +226,7 @@
     }
 
     /* Re-enable Async Event */
-    if (*ReceiveFlags == MSG_OOB)
+    if (*ReceiveFlags & MSG_OOB)
     {
         SockReenableAsyncSelectEvent(Socket, FD_OOB);
     }
@@ -334,7 +337,7 @@
 
     /* Send IOCTL */
     Status = NtDeviceIoControlFile((HANDLE)Handle,
-                                    Event ? Event : SockEvent,
+                                    Event,
                                     APCFunction,
                                     APCContext,
                                     IOSB,
@@ -355,6 +358,9 @@
 
     /* Return the Flags */
     *ReceiveFlags = 0;
+
+    if (Status == STATUS_PENDING)
+        return MsafdReturnWithErrno(Status, lpErrno, IOSB->Information, lpNumberOfBytesRead);
 
     switch (Status)
     {
@@ -461,7 +467,7 @@
 
     /* Send IOCTL */
     Status = NtDeviceIoControlFile((HANDLE)Handle,
-                                    Event ? Event : SockEvent,
+                                    Event,
                                     APCFunction,
                                     APCContext,
                                     IOSB,
@@ -483,7 +489,7 @@
     if (Status == STATUS_PENDING)
     {
         AFD_DbgPrint(MID_TRACE,("Leaving (Pending)\n"));
-        return WSA_IO_PENDING;
+        return MsafdReturnWithErrno(Status, lpErrno, IOSB->Information, lpNumberOfBytesSent);
     }
 
     /* Re-enable Async Event */
@@ -613,7 +619,7 @@
 
     /* Send IOCTL */
     Status = NtDeviceIoControlFile((HANDLE)Handle,
-                                   Event ? Event : SockEvent,
+                                   Event,
                                    APCFunction,
                                    APCContext,
                                    IOSB,
@@ -638,11 +644,8 @@
         HeapFree(GlobalHeap, 0, BindAddress);
     }
 
-    if (Status == STATUS_PENDING)
-        return WSA_IO_PENDING;
-
-    /* Re-enable Async Event */
-    SockReenableAsyncSelectEvent(Socket, FD_WRITE);
+    if (Status != STATUS_PENDING)
+       SockReenableAsyncSelectEvent(Socket, FD_WRITE);
 
     return MsafdReturnWithErrno(Status, lpErrno, IOSB->Information, lpNumberOfBytesSent);
 }




More information about the Ros-diffs mailing list