Index: dll/win32/msafd/misc/dllmain.c =================================================================== --- dll/win32/msafd/misc/dllmain.c (revision 73093) +++ dll/win32/msafd/misc/dllmain.c (working copy) @@ -202,6 +202,8 @@ Socket->SharedData->ProviderFlags = lpProtocolInfo->dwProviderFlags; Socket->SharedData->UseSAN = FALSE; Socket->SharedData->NonBlocking = FALSE; /* Sockets start blocking */ + Socket->SharedData->RecvTimeout = INFINITE; + Socket->SharedData->SendTimeout = INFINITE; /* Ask alex about this */ if( Socket->SharedData->SocketType == SOCK_DGRAM || @@ -210,7 +212,7 @@ TRACE("Connectionless socket\n"); Socket->SharedData->ServiceFlags1 |= XP1_CONNECTIONLESS; } - Socket->Handle = -1; + Socket->Handle = INVALID_SOCKET; } Socket->HelperContext = HelperDLLContext; @@ -579,6 +581,9 @@ case STATUS_ACCESS_DENIED: return WSAEACCES; + case STATUS_NOT_IMPLEMENTED: + return WSAEOPNOTSUPP; + default: ERR("MSAFD: Unhandled NTSTATUS value: 0x%x\n", Status); return WSAENETDOWN; @@ -607,6 +612,14 @@ LONG LingerWait = -1; DWORD References; + /* Get the Socket Structure associate to this Socket*/ + Socket = GetSocketStructure(Handle); + if (!Socket) + { + if (lpErrno) *lpErrno = WSAENOTSOCK; + return SOCKET_ERROR; + } + /* Create the Wait Event */ Status = NtCreateEvent(&SockEvent, EVENT_ALL_ACCESS, @@ -619,14 +632,6 @@ ERR("NtCreateEvent failed: 0x%08x", Status); return SOCKET_ERROR; } - /* Get the Socket Structure associate to this Socket*/ - Socket = GetSocketStructure(Handle); - if (!Socket) - { - NtClose(SockEvent); - if (lpErrno) *lpErrno = WSAENOTSOCK; - return SOCKET_ERROR; - } if (Socket->HelperEvents & WSH_NOTIFY_CLOSE) { @@ -829,11 +834,12 @@ SOCKADDR_INFO SocketInfo; HANDLE SockEvent; - /* See below */ - BindData = HeapAlloc(GlobalHeap, 0, 0xA + SocketAddressLength); - if (!BindData) + /* Get the Socket Structure associate to this Socket*/ + Socket = GetSocketStructure(Handle); + if (!Socket) { - return MsafdReturnWithErrno(STATUS_INSUFFICIENT_RESOURCES, lpErrno, 0, NULL); + if (lpErrno) *lpErrno = WSAENOTSOCK; + return SOCKET_ERROR; } Status = NtCreateEvent(&SockEvent, @@ -844,17 +850,14 @@ if (!NT_SUCCESS(Status)) { - HeapFree(GlobalHeap, 0, BindData); return SOCKET_ERROR; } - /* Get the Socket Structure associate to this Socket*/ - Socket = GetSocketStructure(Handle); - if (!Socket) + /* See below */ + BindData = HeapAlloc(GlobalHeap, 0, 0xA + SocketAddressLength); + if (!BindData) { - HeapFree(GlobalHeap, 0, BindData); - *lpErrno = WSAENOTSOCK; - return SOCKET_ERROR; + return MsafdReturnWithErrno(STATUS_INSUFFICIENT_RESOURCES, lpErrno, 0, NULL); } /* Set up Address in TDI Format */ @@ -951,12 +954,12 @@ Socket = GetSocketStructure(Handle); if (!Socket) { - *lpErrno = WSAENOTSOCK; + if (lpErrno) *lpErrno = WSAENOTSOCK; return SOCKET_ERROR; } if (Socket->SharedData->Listening) - return 0; + return NO_ERROR; Status = NtCreateEvent(&SockEvent, EVENT_ALL_ACCESS, @@ -965,7 +968,7 @@ FALSE); if( !NT_SUCCESS(Status) ) - return -1; + return SOCKET_ERROR; /* Set Up Listen Structure */ ListenData.UseSAN = FALSE; @@ -1340,6 +1343,14 @@ UCHAR ReceiveBuffer[0x1A]; HANDLE SockEvent; + /* Get the Socket Structure associate to this Socket*/ + Socket = GetSocketStructure(Handle); + if (!Socket) + { + if (lpErrno) *lpErrno = WSAENOTSOCK; + return SOCKET_ERROR; + } + Status = NtCreateEvent(&SockEvent, EVENT_ALL_ACCESS, NULL, @@ -1348,22 +1359,12 @@ if( !NT_SUCCESS(Status) ) { - MsafdReturnWithErrno( Status, lpErrno, 0, NULL ); - return INVALID_SOCKET; + return SOCKET_ERROR; } /* Dynamic Structure...ugh */ ListenReceiveData = (PAFD_RECEIVED_ACCEPT_DATA)ReceiveBuffer; - /* Get the Socket Structure associate to this Socket*/ - Socket = GetSocketStructure(Handle); - if (!Socket) - { - NtClose(SockEvent); - *lpErrno = WSAENOTSOCK; - return INVALID_SOCKET; - } - /* If this is non-blocking, make sure there's something for us to accept */ FD_ZERO(&ReadSet); FD_SET(Socket->Handle, &ReadSet); @@ -1373,14 +1374,14 @@ if (WSPSelect(0, &ReadSet, NULL, NULL, &Timeout, lpErrno) == SOCKET_ERROR) { NtClose(SockEvent); - return INVALID_SOCKET; + return SOCKET_ERROR; } if (ReadSet.fd_array[0] != Socket->Handle) { NtClose(SockEvent); - *lpErrno = WSAEWOULDBLOCK; - return INVALID_SOCKET; + if (lpErrno) *lpErrno = WSAEWOULDBLOCK; + return SOCKET_ERROR; } /* Send IOCTL */ @@ -1405,8 +1406,7 @@ if (!NT_SUCCESS(Status)) { NtClose( SockEvent ); - MsafdReturnWithErrno( Status, lpErrno, 0, NULL ); - return INVALID_SOCKET; + return MsafdReturnWithErrno( Status, lpErrno, 0, NULL ); } if (lpfnCondition != NULL) @@ -1439,8 +1439,7 @@ if (!NT_SUCCESS(Status)) { NtClose( SockEvent ); - MsafdReturnWithErrno( Status, lpErrno, 0, NULL ); - return INVALID_SOCKET; + return MsafdReturnWithErrno( Status, lpErrno, 0, NULL ); } /* How much data to allocate */ @@ -1452,8 +1451,7 @@ PendingData = HeapAlloc(GlobalHeap, 0, PendingDataLength); if (!PendingData) { - MsafdReturnWithErrno( STATUS_INSUFFICIENT_RESOURCES, lpErrno, 0, NULL ); - return INVALID_SOCKET; + return MsafdReturnWithErrno( STATUS_INSUFFICIENT_RESOURCES, lpErrno, 0, NULL ); } /* We want the data now */ @@ -1481,8 +1479,7 @@ if (!NT_SUCCESS(Status)) { NtClose( SockEvent ); - MsafdReturnWithErrno( Status, lpErrno, 0, NULL ); - return INVALID_SOCKET; + return MsafdReturnWithErrno( Status, lpErrno, 0, NULL ); } } } @@ -1499,8 +1496,7 @@ RemoteAddress = HeapAlloc(GlobalHeap, 0, sizeof(*RemoteAddress)); if (!RemoteAddress) { - MsafdReturnWithErrno(STATUS_INSUFFICIENT_RESOURCES, lpErrno, 0, NULL); - return INVALID_SOCKET; + return MsafdReturnWithErrno(STATUS_INSUFFICIENT_RESOURCES, lpErrno, 0, NULL); } /* Set up Address in SOCKADDR Format */ @@ -1522,8 +1518,7 @@ /* Allocate Buffer for Callee Data */ CalleeDataBuffer = HeapAlloc(GlobalHeap, 0, 4096); if (!CalleeDataBuffer) { - MsafdReturnWithErrno( STATUS_INSUFFICIENT_RESOURCES, lpErrno, 0, NULL ); - return INVALID_SOCKET; + return MsafdReturnWithErrno( STATUS_INSUFFICIENT_RESOURCES, lpErrno, 0, NULL ); } CalleeData.buf = CalleeDataBuffer; CalleeData.len = 4096; @@ -1590,19 +1585,18 @@ if (!NT_SUCCESS(Status)) { - MsafdReturnWithErrno( Status, lpErrno, 0, NULL ); - return INVALID_SOCKET; + return MsafdReturnWithErrno( Status, lpErrno, 0, NULL ); } if (CallBack == CF_REJECT ) { - *lpErrno = WSAECONNREFUSED; - return INVALID_SOCKET; + if (lpErrno) *lpErrno = WSAECONNREFUSED; + return SOCKET_ERROR; } else { - *lpErrno = WSAECONNREFUSED; - return INVALID_SOCKET; + if (lpErrno) *lpErrno = WSAECONNREFUSED; + return SOCKET_ERROR; } } } @@ -1616,7 +1610,7 @@ Socket->SharedData->CreateFlags, lpErrno); if (AcceptSocket == INVALID_SOCKET) - return INVALID_SOCKET; + return SOCKET_ERROR; /* Set up the Accept Structure */ AcceptData.ListenHandle = (HANDLE)AcceptSocket; @@ -1645,8 +1639,7 @@ { NtClose(SockEvent); WSPCloseSocket( AcceptSocket, lpErrno ); - MsafdReturnWithErrno( Status, lpErrno, 0, NULL ); - return INVALID_SOCKET; + return MsafdReturnWithErrno( Status, lpErrno, 0, NULL ); } AcceptSocketInfo = GetSocketStructure(AcceptSocket); @@ -1654,8 +1647,7 @@ { NtClose(SockEvent); WSPCloseSocket( AcceptSocket, lpErrno ); - MsafdReturnWithErrno( STATUS_PROTOCOL_NOT_SUPPORTED, lpErrno, 0, NULL ); - return INVALID_SOCKET; + return MsafdReturnWithErrno( STATUS_PROTOCOL_NOT_SUPPORTED, lpErrno, 0, NULL ); } AcceptSocketInfo->SharedData->State = SocketConnected; @@ -1688,11 +1680,11 @@ if (Status) { if (lpErrno) *lpErrno = Status; - return INVALID_SOCKET; + return SOCKET_ERROR; } } - *lpErrno = 0; + if (lpErrno) *lpErrno = 0; /* Return Socket */ return AcceptSocket; @@ -1721,26 +1713,25 @@ HANDLE SockEvent; int SocketDataLength; - Status = NtCreateEvent(&SockEvent, - EVENT_ALL_ACCESS, - NULL, - 1, - FALSE); + TRACE("Called (%lx) %lx:%d\n", Handle, ((const struct sockaddr_in *)SocketAddress)->sin_addr, ((const struct sockaddr_in *)SocketAddress)->sin_port); - if (!NT_SUCCESS(Status)) - return MsafdReturnWithErrno(Status, lpErrno, 0, NULL); - - TRACE("Called\n"); - /* Get the Socket Structure associate to this Socket*/ Socket = GetSocketStructure(Handle); if (!Socket) { - NtClose(SockEvent); if (lpErrno) *lpErrno = WSAENOTSOCK; return SOCKET_ERROR; } + Status = NtCreateEvent(&SockEvent, + EVENT_ALL_ACCESS, + NULL, + 1, + FALSE); + + if (!NT_SUCCESS(Status)) + return SOCKET_ERROR; + /* Bind us First */ if (Socket->SharedData->State == SocketOpen) { @@ -1899,7 +1890,7 @@ } } - TRACE("Ending\n"); + TRACE("Ending %lx\n", IOSB.Status); notify: if (ConnectInfo) HeapFree(GetProcessHeap(), 0, ConnectInfo); @@ -1956,15 +1947,6 @@ NTSTATUS Status; HANDLE SockEvent; - Status = NtCreateEvent(&SockEvent, - EVENT_ALL_ACCESS, - NULL, - 1, - FALSE); - - if( !NT_SUCCESS(Status) ) - return -1; - TRACE("Called\n"); /* Get the Socket Structure associate to this Socket*/ @@ -1971,11 +1953,19 @@ Socket = GetSocketStructure(Handle); if (!Socket) { - NtClose(SockEvent); - *lpErrno = WSAENOTSOCK; + if (lpErrno) *lpErrno = WSAENOTSOCK; return SOCKET_ERROR; } + Status = NtCreateEvent(&SockEvent, + EVENT_ALL_ACCESS, + NULL, + 1, + FALSE); + + if( !NT_SUCCESS(Status) ) + return SOCKET_ERROR; + /* Set AFD Disconnect Type */ switch (HowTo) { @@ -2038,31 +2028,29 @@ NTSTATUS Status; HANDLE SockEvent; - Status = NtCreateEvent(&SockEvent, - EVENT_ALL_ACCESS, - NULL, - 1, - FALSE); - - if( !NT_SUCCESS(Status) ) - return SOCKET_ERROR; - /* Get the Socket Structure associate to this Socket*/ Socket = GetSocketStructure(Handle); if (!Socket) { - NtClose(SockEvent); - *lpErrno = WSAENOTSOCK; + if (lpErrno) *lpErrno = WSAENOTSOCK; return SOCKET_ERROR; } if (!Name || !NameLength) { - NtClose(SockEvent); - *lpErrno = WSAEFAULT; + if (lpErrno) *lpErrno = WSAEFAULT; return SOCKET_ERROR; } + Status = NtCreateEvent(&SockEvent, + EVENT_ALL_ACCESS, + NULL, + 1, + FALSE); + + if( !NT_SUCCESS(Status) ) + return SOCKET_ERROR; + /* Allocate a buffer for the address */ TdiAddressSize = sizeof(TRANSPORT_ADDRESS) + Socket->SharedData->SizeOfLocalAddress; @@ -2071,7 +2059,7 @@ if ( TdiAddress == NULL ) { NtClose( SockEvent ); - *lpErrno = WSAENOBUFS; + if (lpErrno) *lpErrno = WSAENOBUFS; return SOCKET_ERROR; } @@ -2116,7 +2104,7 @@ else { HeapFree(GlobalHeap, 0, TdiAddress); - *lpErrno = WSAEFAULT; + if (lpErrno) *lpErrno = WSAEFAULT; return SOCKET_ERROR; } } @@ -2141,38 +2129,35 @@ NTSTATUS Status; HANDLE SockEvent; - Status = NtCreateEvent(&SockEvent, - EVENT_ALL_ACCESS, - NULL, - 1, - FALSE); - - if( !NT_SUCCESS(Status) ) - return SOCKET_ERROR; - /* Get the Socket Structure associate to this Socket*/ Socket = GetSocketStructure(s); if (!Socket) { - NtClose(SockEvent); - *lpErrno = WSAENOTSOCK; - return SOCKET_ERROR; + if (lpErrno) *lpErrno = WSAENOTSOCK; + return SOCKET_ERROR; } if (Socket->SharedData->State != SocketConnected) { - NtClose(SockEvent); - *lpErrno = WSAENOTCONN; + if (lpErrno) *lpErrno = WSAENOTCONN; return SOCKET_ERROR; } if (!Name || !NameLength) { - NtClose(SockEvent); - *lpErrno = WSAEFAULT; + if (lpErrno) *lpErrno = WSAEFAULT; return SOCKET_ERROR; } + Status = NtCreateEvent(&SockEvent, + EVENT_ALL_ACCESS, + NULL, + 1, + FALSE); + + if( !NT_SUCCESS(Status) ) + return SOCKET_ERROR; + /* Allocate a buffer for the address */ TdiAddressSize = sizeof(TRANSPORT_ADDRESS) + Socket->SharedData->SizeOfRemoteAddress; SocketAddress = HeapAlloc(GlobalHeap, 0, TdiAddressSize); @@ -2180,7 +2165,7 @@ if ( SocketAddress == NULL ) { NtClose( SockEvent ); - *lpErrno = WSAENOBUFS; + if (lpErrno) *lpErrno = WSAENOBUFS; return SOCKET_ERROR; } @@ -2223,7 +2208,7 @@ else { HeapFree(GlobalHeap, 0, SocketAddress); - *lpErrno = WSAEFAULT; + if (lpErrno) *lpErrno = WSAEFAULT; return SOCKET_ERROR; } } @@ -2413,12 +2398,13 @@ INT BufferSize; BOOL BoolBuffer; INT IntBuffer; + INT Errno; /* Get the Socket Structure associate to this Socket*/ Socket = GetSocketStructure(Handle); if (Socket == NULL) { - *lpErrno = WSAENOTSOCK; + if (lpErrno) *lpErrno = WSAENOTSOCK; return SOCKET_ERROR; } @@ -2471,7 +2457,7 @@ case SO_LINGER: if (Socket->SharedData->SocketType == SOCK_DGRAM) { - *lpErrno = WSAENOPROTOOPT; + if (lpErrno) *lpErrno = WSAENOPROTOOPT; return SOCKET_ERROR; } Buffer = &Socket->SharedData->LingerData; @@ -2534,13 +2520,13 @@ default: DbgPrint("MSAFD: Get unknown optname %x\n", OptionName); - *lpErrno = WSAENOPROTOOPT; + if (lpErrno) *lpErrno = WSAENOPROTOOPT; return SOCKET_ERROR; } if (*OptionLength < BufferSize) { - *lpErrno = WSAEFAULT; + if (lpErrno) *lpErrno = WSAEFAULT; *OptionLength = BufferSize; return SOCKET_ERROR; } @@ -2549,20 +2535,21 @@ return 0; default: - *lpErrno = WSAEINVAL; + if (lpErrno) *lpErrno = WSAEINVAL; return SOCKET_ERROR; } SendToHelper: - *lpErrno = Socket->HelperData->WSHGetSocketInformation(Socket->HelperContext, - Handle, - Socket->TdiAddressHandle, - Socket->TdiConnectionHandle, - Level, - OptionName, - OptionValue, - (LPINT)OptionLength); - return (*lpErrno == 0) ? 0 : SOCKET_ERROR; + Errno = Socket->HelperData->WSHGetSocketInformation(Socket->HelperContext, + Handle, + Socket->TdiAddressHandle, + Socket->TdiConnectionHandle, + Level, + OptionName, + OptionValue, + (LPINT)OptionLength); + if (lpErrno) *lpErrno = Errno; + return (Errno == 0) ? 0 : SOCKET_ERROR; } INT @@ -2576,12 +2563,13 @@ OUT LPINT lpErrno) { PSOCKET_INFORMATION Socket; + INT Errno; /* Get the Socket Structure associate to this Socket*/ Socket = GetSocketStructure(s); if (Socket == NULL) { - *lpErrno = WSAENOTSOCK; + if (lpErrno) *lpErrno = WSAENOTSOCK; return SOCKET_ERROR; } @@ -2594,16 +2582,25 @@ case SO_BROADCAST: if (optlen < sizeof(BOOL)) { - *lpErrno = WSAEFAULT; + if (lpErrno) *lpErrno = WSAEFAULT; return SOCKET_ERROR; } Socket->SharedData->Broadcast = (*optval != 0) ? 1 : 0; return 0; + case SO_OOBINLINE: + if (optlen < sizeof(BOOL)) + { + if (lpErrno) *lpErrno = WSAEFAULT; + return SOCKET_ERROR; + } + Socket->SharedData->OobInline = (*optval != 0) ? 1 : 0; + return 0; + case SO_DONTLINGER: if (optlen < sizeof(BOOL)) { - *lpErrno = WSAEFAULT; + if (lpErrno) *lpErrno = WSAEFAULT; return SOCKET_ERROR; } Socket->SharedData->LingerData.l_onoff = (*optval != 0) ? 0 : 1; @@ -2612,7 +2609,7 @@ case SO_REUSEADDR: if (optlen < sizeof(BOOL)) { - *lpErrno = WSAEFAULT; + if (lpErrno) *lpErrno = WSAEFAULT; return SOCKET_ERROR; } Socket->SharedData->ReuseAddresses = (*optval != 0) ? 1 : 0; @@ -2621,7 +2618,7 @@ case SO_EXCLUSIVEADDRUSE: if (optlen < sizeof(BOOL)) { - *lpErrno = WSAEFAULT; + if (lpErrno) *lpErrno = WSAEFAULT; return SOCKET_ERROR; } Socket->SharedData->ExclusiveAddressUse = (*optval != 0) ? 1 : 0; @@ -2630,7 +2627,7 @@ case SO_LINGER: if (optlen < sizeof(struct linger)) { - *lpErrno = WSAEFAULT; + if (lpErrno) *lpErrno = WSAEFAULT; return SOCKET_ERROR; } RtlCopyMemory(&Socket->SharedData->LingerData, @@ -2641,7 +2638,7 @@ case SO_SNDBUF: if (optlen < sizeof(DWORD)) { - *lpErrno = WSAEFAULT; + if (lpErrno) *lpErrno = WSAEFAULT; return SOCKET_ERROR; } @@ -2652,7 +2649,7 @@ case SO_SNDTIMEO: if (optlen < sizeof(DWORD)) { - *lpErrno = WSAEFAULT; + if (lpErrno) *lpErrno = WSAEFAULT; return SOCKET_ERROR; } @@ -2664,7 +2661,7 @@ case SO_RCVTIMEO: if (optlen < sizeof(DWORD)) { - *lpErrno = WSAEFAULT; + if (lpErrno) *lpErrno = WSAEFAULT; return SOCKET_ERROR; } @@ -2686,15 +2683,16 @@ } SendToHelper: - *lpErrno = Socket->HelperData->WSHSetSocketInformation(Socket->HelperContext, - s, - Socket->TdiAddressHandle, - Socket->TdiConnectionHandle, - level, - optname, - (PCHAR)optval, - optlen); - return (*lpErrno == 0) ? 0 : SOCKET_ERROR; + Errno = Socket->HelperData->WSHSetSocketInformation(Socket->HelperContext, + s, + Socket->TdiAddressHandle, + Socket->TdiConnectionHandle, + level, + optname, + (PCHAR)optval, + optlen); + if (lpErrno) *lpErrno = Errno; + return (Errno == 0) ? 0 : SOCKET_ERROR; } /* @@ -2788,7 +2786,7 @@ if (!lpsaAddress || !lpszAddressString || !lpdwAddressStringLength) { - *lpErrno = WSAEFAULT; + if (lpErrno) *lpErrno = WSAEFAULT; return SOCKET_ERROR; } @@ -2797,7 +2795,7 @@ case AF_INET: if (dwAddressLength < sizeof(SOCKADDR_IN)) { - *lpErrno = WSAEINVAL; + if (lpErrno) *lpErrno = WSAEINVAL; return SOCKET_ERROR; } swprintf(buffer, @@ -2815,7 +2813,7 @@ } break; default: - *lpErrno = WSAEINVAL; + if (lpErrno) *lpErrno = WSAEINVAL; return SOCKET_ERROR; } @@ -2824,7 +2822,7 @@ if (*lpdwAddressStringLength < size) { *lpdwAddressStringLength = size; - *lpErrno = WSAEFAULT; + if (lpErrno) *lpErrno = WSAEFAULT; return SOCKET_ERROR; } @@ -2849,7 +2847,7 @@ if (!lpAddressLength || !lpAddress || !AddressString) { - *lpErrno = WSAEINVAL; + if (lpErrno) *lpErrno = WSAEINVAL; return SOCKET_ERROR; } @@ -2871,7 +2869,7 @@ if (*lpAddressLength < (INT)sizeof(SOCKADDR_IN)) { *lpAddressLength = sizeof(SOCKADDR_IN); - *lpErrno = WSAEFAULT; + if (lpErrno) *lpErrno = WSAEFAULT; } else { @@ -2908,13 +2906,13 @@ pos += wcscspn(&AddressString[pos], L".") + 1; } - *lpErrno = 0; + if (lpErrno) *lpErrno = 0; sockaddr->sin_addr.s_addr = inetaddr; } } - if (!*lpErrno) + if (lpErrno && !*lpErrno) { return 0; } @@ -2935,8 +2933,9 @@ { TRACE("Leaving.\n"); - *lpErrno = NO_ERROR; + if (lpErrno) *lpErrno = NO_ERROR; + return 0; } @@ -2965,7 +2964,7 @@ IO_STATUS_BLOCK DummyIOSB; AFD_INFO InfoData; NTSTATUS Status; - PVOID APCContext; + PAFDAPCCONTEXT APCContext; PIO_APC_ROUTINE APCFunction; HANDLE Event = NULL; HANDLE SockEvent; @@ -2977,7 +2976,7 @@ FALSE); if( !NT_SUCCESS(Status) ) - return -1; + return SOCKET_ERROR; /* Set Info Class */ InfoData.InformationClass = AfdInformationClass; @@ -3002,7 +3001,7 @@ if (CompletionRoutine == NULL) { /* Using Overlapped Structure, but no Completition Routine, so no need for APC */ - APCContext = Overlapped; + APCContext = (PAFDAPCCONTEXT)Overlapped; APCFunction = NULL; Event = Overlapped->hEvent; } @@ -3016,9 +3015,9 @@ ERR("Not enough memory for APC Context\n"); return WSAEFAULT; } - ((PAFDAPCCONTEXT)APCContext)->lpCompletionRoutine = CompletionRoutine; - ((PAFDAPCCONTEXT)APCContext)->lpOverlapped = Overlapped; - ((PAFDAPCCONTEXT)APCContext)->lpSocket = Socket; + APCContext->lpCompletionRoutine = CompletionRoutine; + APCContext->lpOverlapped = Overlapped; + APCContext->lpSocket = Socket; } IOSB = (PIO_STATUS_BLOCK)&Overlapped->Internal; @@ -3054,7 +3053,7 @@ } if (Status != STATUS_SUCCESS) - return -1; + return SOCKET_ERROR; /* Return Information */ if (Ulong != NULL) @@ -3072,7 +3071,7 @@ NtClose( SockEvent ); - return 0; + return NO_ERROR; } @@ -3090,7 +3089,7 @@ IO_STATUS_BLOCK DummyIOSB; AFD_INFO InfoData; NTSTATUS Status; - PVOID APCContext; + PAFDAPCCONTEXT APCContext; PIO_APC_ROUTINE APCFunction; HANDLE Event = NULL; HANDLE SockEvent; @@ -3102,7 +3101,7 @@ FALSE); if( !NT_SUCCESS(Status) ) - return -1; + return SOCKET_ERROR; /* Set Info Class */ InfoData.InformationClass = AfdInformationClass; @@ -3141,7 +3140,7 @@ if (CompletionRoutine == NULL) { /* Using Overlapped Structure, but no Completition Routine, so no need for APC */ - APCContext = Overlapped; + APCContext = (PAFDAPCCONTEXT)Overlapped; APCFunction = NULL; Event = Overlapped->hEvent; } @@ -3155,9 +3154,9 @@ ERR("Not enough memory for APC Context\n"); return WSAEFAULT; } - ((PAFDAPCCONTEXT)APCContext)->lpCompletionRoutine = CompletionRoutine; - ((PAFDAPCCONTEXT)APCContext)->lpOverlapped = Overlapped; - ((PAFDAPCCONTEXT)APCContext)->lpSocket = Socket; + APCContext->lpCompletionRoutine = CompletionRoutine; + APCContext->lpOverlapped = Overlapped; + APCContext->lpSocket = Socket; } IOSB = (PIO_STATUS_BLOCK)&Overlapped->Internal; @@ -3194,7 +3193,7 @@ return WSA_IO_PENDING; } - return Status == STATUS_SUCCESS ? 0 : -1; + return Status == STATUS_SUCCESS ? NO_ERROR : SOCKET_ERROR; } @@ -3236,7 +3235,7 @@ FALSE); if( !NT_SUCCESS(Status) ) - return -1; + return SOCKET_ERROR; /* Create Context */ ContextData.SharedData = *Socket->SharedData; @@ -3269,7 +3268,7 @@ NtClose( SockEvent ); - return Status == STATUS_SUCCESS ? 0 : -1; + return Status == STATUS_SUCCESS ? NO_ERROR : SOCKET_ERROR; } BOOLEAN SockCreateOrReferenceAsyncThread(VOID) Index: dll/win32/msafd/misc/event.c =================================================================== --- dll/win32/msafd/misc/event.c (revision 73093) +++ dll/win32/msafd/misc/event.c (working copy) @@ -30,20 +30,19 @@ BOOLEAN BlockMode; HANDLE SockEvent; - Status = NtCreateEvent( &SockEvent, EVENT_ALL_ACCESS, - NULL, 1, FALSE ); - - if( !NT_SUCCESS(Status) ) return -1; - /* Get the Socket Structure associate to this Socket*/ Socket = GetSocketStructure(Handle); if (!Socket) { - NtClose(SockEvent); - *lpErrno = WSAENOTSOCK; + if (lpErrno) *lpErrno = WSAENOTSOCK; return SOCKET_ERROR; } + Status = NtCreateEvent( &SockEvent, EVENT_ALL_ACCESS, + NULL, 1, FALSE ); + + if( !NT_SUCCESS(Status) ) return SOCKET_ERROR; + /* Set Socket to Non-Blocking */ BlockMode = TRUE; SetSocketInformation(Socket, AFD_INFO_BLOCKING_MODE, &BlockMode, NULL, NULL, NULL, NULL); @@ -157,7 +156,7 @@ if( !NT_SUCCESS(Status) ) { ERR("Could not make an event %x\n", Status); - return -1; + return SOCKET_ERROR; } /* Get the Socket Structure associate to this Socket*/ @@ -165,7 +164,7 @@ if (!Socket) { NtClose(SockEvent); - *lpErrno = WSAENOTSOCK; + if (lpErrno) *lpErrno = WSAENOTSOCK; return SOCKET_ERROR; }