Set nonblocking on all sockets initially.
Zero flags and other junk in the ea buffer when creating a new socket.
More correct error return function (check both Errno and ReturnedBytes ptrs).
Modified: trunk/reactos/lib/msafd/misc/dllmain.c

Modified: trunk/reactos/lib/msafd/misc/dllmain.c
--- trunk/reactos/lib/msafd/misc/dllmain.c	2005-02-25 03:02:45 UTC (rev 13737)
+++ trunk/reactos/lib/msafd/misc/dllmain.c	2005-02-25 05:27:43 UTC (rev 13738)
@@ -16,8 +16,8 @@
 #include <rosrtl/string.h>
 
 #ifdef DBG
-DWORD DebugTraceLevel = DEBUG_ULTRA;
-//DWORD DebugTraceLevel = 0;
+//DWORD DebugTraceLevel = DEBUG_ULTRA;
+DWORD DebugTraceLevel = 0;
 #endif /* DBG */
 
 HANDLE GlobalHeap;
@@ -120,6 +120,7 @@
 	Socket->SharedData.GroupID = g;
 	Socket->SharedData.GroupType = 0;
 	Socket->SharedData.UseSAN = FALSE;
+        Socket->SharedData.NonBlocking = FALSE; /* Sockets start blocking */
 	Socket->SanData = NULL;
 
 	/* Ask alex about this */
@@ -137,6 +138,7 @@
 
 	/* Set up EA Buffer */
 	EABuffer = HeapAlloc(GlobalHeap, 0, SizeOfEA);
+        RtlZeroMemory(EABuffer, SizeOfEA);
 	EABuffer->NextEntryOffset = 0;
 	EABuffer->Flags = 0;
 	EABuffer->EaNameLength = AFD_PACKET_COMMAND_LENGTH;
@@ -265,19 +267,22 @@
 
 DWORD MsafdReturnWithErrno( NTSTATUS Status, LPINT Errno, DWORD Received,
 			    LPDWORD ReturnedBytes ) {
-    switch (Status) {
-    case STATUS_CANT_WAIT: *Errno = WSAEWOULDBLOCK; break;
-    case STATUS_TIMEOUT:
-    case STATUS_SUCCESS: 
-	/* Return Number of bytes Read */
-	if( ReturnedBytes ) *ReturnedBytes = Received; break;
-    case STATUS_END_OF_FILE: *Errno = WSAESHUTDOWN; *ReturnedBytes = 0; break;
-    case STATUS_PENDING: *Errno = WSA_IO_PENDING; break;
-    case STATUS_BUFFER_OVERFLOW: *Errno = WSAEMSGSIZE; break;
-    default: {
-	DbgPrint("MSAFD: Error %x is unknown\n", Status);
-	*Errno = WSAEINVAL; break;
-    } break;
+    if( ReturnedBytes ) *ReturnedBytes = 0; 
+    if( Errno ) { 
+        switch (Status) {
+        case STATUS_CANT_WAIT: *Errno = WSAEWOULDBLOCK; break;
+        case STATUS_TIMEOUT:
+        case STATUS_SUCCESS: 
+            /* Return Number of bytes Read */
+            if( ReturnedBytes ) *ReturnedBytes = Received; break;
+        case STATUS_END_OF_FILE: *Errno = WSAESHUTDOWN; *ReturnedBytes = 0; break;
+        case STATUS_PENDING: *Errno = WSA_IO_PENDING; break;
+        case STATUS_BUFFER_OVERFLOW: *Errno = WSAEMSGSIZE; break;
+        default: {
+            DbgPrint("MSAFD: Error %x is unknown\n", Status);
+            *Errno = WSAEINVAL; break;
+        } break;
+        }
     }
 
     /* Success */
@@ -588,6 +593,9 @@
     PollBufferSize = sizeof(*PollInfo) + 
 	(HandleCount * sizeof(AFD_HANDLE));
     
+    AFD_DbgPrint(MID_TRACE,("HandleCount: %d BufferSize: %d\n", 
+                            HandleCount, PollBufferSize));
+
     /* Allocate */
     PollBuffer = HeapAlloc(GlobalHeap, 0, PollBufferSize);
     PollInfo = (PAFD_POLL_INFO)PollBuffer;