Fixed each call to use a unique event. This is needed because send, recv,

connect, etc can complete independently even on the same socket.
Fixed connect to pass the status from afd back correctly.  Connect now
fails as expected when we couldn't make a connection.

svn path=/trunk/; revision=11061
This commit is contained in:
Art Yerkes 2004-09-26 07:55:32 +00:00
parent 97fcd66fc7
commit a3091079d6
3 changed files with 120 additions and 3 deletions

View file

@ -9,7 +9,6 @@
* CSH 01/09-2000 Created * CSH 01/09-2000 Created
* Alex 16/07/2004 - Complete Rewrite * Alex 16/07/2004 - Complete Rewrite
*/ */
#include <roscfg.h>
#include <string.h> #include <string.h>
#include <msafd.h> #include <msafd.h>
#include <helpers.h> #include <helpers.h>
@ -25,7 +24,6 @@ VOID STDCALL KeBugCheck (ULONG BugCheckCode) {}
HANDLE GlobalHeap; HANDLE GlobalHeap;
WSPUPCALLTABLE Upcalls; WSPUPCALLTABLE Upcalls;
LPWPUCOMPLETEOVERLAPPEDREQUEST lpWPUCompleteOverlappedRequest; LPWPUCOMPLETEOVERLAPPEDREQUEST lpWPUCompleteOverlappedRequest;
HANDLE SockEvent;
ULONG SocketCount; ULONG SocketCount;
PSOCKET_INFORMATION *Sockets = NULL; PSOCKET_INFORMATION *Sockets = NULL;
LIST_ENTRY SockHelpersListHead = {NULL}; LIST_ENTRY SockHelpersListHead = {NULL};
@ -297,6 +295,12 @@ WSPBind(
NTSTATUS Status; NTSTATUS Status;
UCHAR BindBuffer[0x1A]; UCHAR BindBuffer[0x1A];
SOCKADDR_INFO SocketInfo; SOCKADDR_INFO SocketInfo;
HANDLE SockEvent;
Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
NULL, 1, FALSE );
if( !NT_SUCCESS(Status) ) return -1;
/* Get the Socket Structure associate to this Socket*/ /* Get the Socket Structure associate to this Socket*/
Socket = GetSocketStructure(Handle); Socket = GetSocketStructure(Handle);
@ -345,6 +349,8 @@ WSPBind(
Socket->SharedData.State = SocketBound; Socket->SharedData.State = SocketBound;
Socket->TdiAddressHandle = (HANDLE)IOSB.Information; Socket->TdiAddressHandle = (HANDLE)IOSB.Information;
NtClose( SockEvent );
return 0; return 0;
} }
@ -358,8 +364,14 @@ WSPListen(
IO_STATUS_BLOCK IOSB; IO_STATUS_BLOCK IOSB;
AFD_LISTEN_DATA ListenData; AFD_LISTEN_DATA ListenData;
PSOCKET_INFORMATION Socket = NULL; PSOCKET_INFORMATION Socket = NULL;
HANDLE SockEvent;
NTSTATUS Status; NTSTATUS Status;
Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
NULL, 1, FALSE );
if( !NT_SUCCESS(Status) ) return -1;
/* Get the Socket Structure associate to this Socket*/ /* Get the Socket Structure associate to this Socket*/
Socket = GetSocketStructure(Handle); Socket = GetSocketStructure(Handle);
@ -383,6 +395,8 @@ WSPListen(
/* Set to Listening */ /* Set to Listening */
Socket->SharedData.Listening = TRUE; Socket->SharedData.Listening = TRUE;
NtClose( SockEvent );
return 0; return 0;
} }
@ -405,6 +419,12 @@ WSPSelect(
LARGE_INTEGER uSec; LARGE_INTEGER uSec;
PVOID PollBuffer; PVOID PollBuffer;
ULONG i, j = 0; ULONG i, j = 0;
HANDLE SockEvent;
Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
NULL, 1, FALSE );
if( !NT_SUCCESS(Status) ) return -1;
/* Find out how many sockets we have, and how large the buffer needs to be */ /* Find out how many sockets we have, and how large the buffer needs to be */
HandleCount = ( readfds ? readfds->fd_count : 0 ) + HandleCount = ( readfds ? readfds->fd_count : 0 ) +
@ -495,6 +515,8 @@ WSPSelect(
} }
} }
NtClose( SockEvent );
return 0; return 0;
} }
@ -527,6 +549,12 @@ WSPAccept(
WSAPROTOCOL_INFOW ProtocolInfo; WSAPROTOCOL_INFOW ProtocolInfo;
SOCKET AcceptSocket; SOCKET AcceptSocket;
UCHAR ReceiveBuffer[0x1A]; UCHAR ReceiveBuffer[0x1A];
HANDLE SockEvent;
Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
NULL, 1, FALSE );
if( !NT_SUCCESS(Status) ) return -1;
/* Dynamic Structure...ugh */ /* Dynamic Structure...ugh */
ListenReceiveData = (PAFD_RECEIVED_ACCEPT_DATA)ReceiveBuffer; ListenReceiveData = (PAFD_RECEIVED_ACCEPT_DATA)ReceiveBuffer;
@ -680,6 +708,8 @@ WSPAccept(
NULL, NULL,
0); 0);
NtClose( SockEvent );
if (CallBack == CF_REJECT ) { if (CallBack == CF_REJECT ) {
return WSAECONNREFUSED; return WSAECONNREFUSED;
} else { } else {
@ -721,6 +751,8 @@ WSPAccept(
&ListenReceiveData->Address.Address[0].AddressType, &ListenReceiveData->Address.Address[0].AddressType,
sizeof(RemoteAddress)); sizeof(RemoteAddress));
NtClose( SockEvent );
/* Return Socket */ /* Return Socket */
return AcceptSocket; return AcceptSocket;
} }
@ -746,6 +778,12 @@ WSPConnect(
ULONG InConnectDataLength; ULONG InConnectDataLength;
UINT BindAddressLength; UINT BindAddressLength;
PSOCKADDR BindAddress; PSOCKADDR BindAddress;
HANDLE SockEvent;
Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
NULL, 1, FALSE );
if( !NT_SUCCESS(Status) ) return -1;
AFD_DbgPrint(MID_TRACE,("Called\n")); AFD_DbgPrint(MID_TRACE,("Called\n"));
@ -839,7 +877,9 @@ WSPConnect(
AFD_DbgPrint(MID_TRACE,("Ending\n")); AFD_DbgPrint(MID_TRACE,("Ending\n"));
return STATUS_SUCCESS; NtClose( SockEvent );
return Status;
} }
int int
WSPAPI WSPAPI
@ -853,6 +893,12 @@ WSPShutdown(
AFD_DISCONNECT_INFO DisconnectInfo; AFD_DISCONNECT_INFO DisconnectInfo;
PSOCKET_INFORMATION Socket = NULL; PSOCKET_INFORMATION Socket = NULL;
NTSTATUS Status; NTSTATUS Status;
HANDLE SockEvent;
Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
NULL, 1, FALSE );
if( !NT_SUCCESS(Status) ) return -1;
AFD_DbgPrint(MID_TRACE,("Called\n")); AFD_DbgPrint(MID_TRACE,("Called\n"));
@ -900,6 +946,8 @@ WSPShutdown(
AFD_DbgPrint(MID_TRACE,("Ending\n")); AFD_DbgPrint(MID_TRACE,("Ending\n"));
NtClose( SockEvent );
return 0; return 0;
} }
@ -1032,6 +1080,12 @@ GetSocketInformation(
IO_STATUS_BLOCK IOSB; IO_STATUS_BLOCK IOSB;
AFD_INFO InfoData; AFD_INFO InfoData;
NTSTATUS Status; NTSTATUS Status;
HANDLE SockEvent;
Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
NULL, 1, FALSE );
if( !NT_SUCCESS(Status) ) return -1;
/* Set Info Class */ /* Set Info Class */
InfoData.InformationClass = AfdInformationClass; InfoData.InformationClass = AfdInformationClass;
@ -1059,6 +1113,8 @@ GetSocketInformation(
*LargeInteger = InfoData.Information.LargeInteger; *LargeInteger = InfoData.Information.LargeInteger;
} }
NtClose( SockEvent );
return 0; return 0;
} }
@ -1074,6 +1130,12 @@ SetSocketInformation(
IO_STATUS_BLOCK IOSB; IO_STATUS_BLOCK IOSB;
AFD_INFO InfoData; AFD_INFO InfoData;
NTSTATUS Status; NTSTATUS Status;
HANDLE SockEvent;
Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
NULL, 1, FALSE );
if( !NT_SUCCESS(Status) ) return -1;
/* Set Info Class */ /* Set Info Class */
InfoData.InformationClass = AfdInformationClass; InfoData.InformationClass = AfdInformationClass;
@ -1101,6 +1163,8 @@ SetSocketInformation(
WaitForSingleObject(SockEvent, 0); WaitForSingleObject(SockEvent, 0);
} }
NtClose( SockEvent );
return 0; return 0;
} }
@ -1124,6 +1188,12 @@ int CreateContext(PSOCKET_INFORMATION Socket)
IO_STATUS_BLOCK IOSB; IO_STATUS_BLOCK IOSB;
SOCKET_CONTEXT ContextData; SOCKET_CONTEXT ContextData;
NTSTATUS Status; NTSTATUS Status;
HANDLE SockEvent;
Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
NULL, 1, FALSE );
if( !NT_SUCCESS(Status) ) return -1;
/* Create Context */ /* Create Context */
ContextData.SharedData = Socket->SharedData; ContextData.SharedData = Socket->SharedData;
@ -1147,6 +1217,13 @@ int CreateContext(PSOCKET_INFORMATION Socket)
NULL, NULL,
0); 0);
/* Wait for Completition */
if (Status == STATUS_PENDING) {
WaitForSingleObject(SockEvent, 0);
}
NtClose( SockEvent );
return 0; return 0;
} }

View file

@ -25,6 +25,12 @@ WSPEventSelect(
PSOCKET_INFORMATION Socket = NULL; PSOCKET_INFORMATION Socket = NULL;
NTSTATUS Status; NTSTATUS Status;
ULONG BlockMode; ULONG BlockMode;
HANDLE SockEvent;
Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
NULL, 1, FALSE );
if( !NT_SUCCESS(Status) ) return -1;
/* Get the Socket Structure associate to this Socket*/ /* Get the Socket Structure associate to this Socket*/
Socket = GetSocketStructure(Handle); Socket = GetSocketStructure(Handle);
@ -93,6 +99,8 @@ WSPEventSelect(
WaitForSingleObject(SockEvent, 0); WaitForSingleObject(SockEvent, 0);
} }
NtClose( SockEvent );
/* Set Socket Data*/ /* Set Socket Data*/
Socket->EventObject = hEventObject; Socket->EventObject = hEventObject;
Socket->NetworkEvents = lNetworkEvents; Socket->NetworkEvents = lNetworkEvents;

View file

@ -47,6 +47,12 @@ WSPRecv(
PVOID APCContext; PVOID APCContext;
PVOID APCFunction; PVOID APCFunction;
HANDLE Event; HANDLE Event;
HANDLE SockEvent;
Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
NULL, 1, FALSE );
if( !NT_SUCCESS(Status) ) return -1;
/* Set up the Receive Structure */ /* Set up the Receive Structure */
RecvInfo.BufferArray = (PAFD_WSABUF)lpBuffers; RecvInfo.BufferArray = (PAFD_WSABUF)lpBuffers;
@ -126,6 +132,8 @@ WSPRecv(
Status = IOSB->Status; Status = IOSB->Status;
} }
NtClose( SockEvent );
/* Return the Flags */ /* Return the Flags */
*ReceiveFlags = 0; *ReceiveFlags = 0;
switch (Status) { switch (Status) {
@ -181,6 +189,12 @@ WSPRecvFrom(
PVOID APCContext; PVOID APCContext;
PVOID APCFunction; PVOID APCFunction;
HANDLE Event; HANDLE Event;
HANDLE SockEvent;
Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
NULL, 1, FALSE );
if( !NT_SUCCESS(Status) ) return -1;
/* Set up the Receive Structure */ /* Set up the Receive Structure */
RecvInfo.BufferArray = (PAFD_WSABUF)lpBuffers; RecvInfo.BufferArray = (PAFD_WSABUF)lpBuffers;
@ -262,6 +276,8 @@ WSPRecvFrom(
Status = IOSB->Status; Status = IOSB->Status;
} }
NtClose( SockEvent );
/* Return the Flags */ /* Return the Flags */
*ReceiveFlags = 0; *ReceiveFlags = 0;
switch (Status) { switch (Status) {
@ -316,6 +332,12 @@ WSPSend(
PVOID APCContext; PVOID APCContext;
PVOID APCFunction; PVOID APCFunction;
HANDLE Event; HANDLE Event;
HANDLE SockEvent;
Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
NULL, 1, FALSE );
if( !NT_SUCCESS(Status) ) return -1;
AFD_DbgPrint(MID_TRACE,("Called\n")); AFD_DbgPrint(MID_TRACE,("Called\n"));
@ -385,6 +407,8 @@ WSPSend(
Status = IOSB->Status; Status = IOSB->Status;
} }
NtClose( SockEvent );
if (Status == STATUS_PENDING) { if (Status == STATUS_PENDING) {
AFD_DbgPrint(MID_TRACE,("Leaving (Pending)\n")); AFD_DbgPrint(MID_TRACE,("Leaving (Pending)\n"));
return WSA_IO_PENDING; return WSA_IO_PENDING;
@ -426,6 +450,12 @@ WSPSendTo(
UCHAR TdiBuffer[0x16]; UCHAR TdiBuffer[0x16];
PSOCKADDR BindAddress; PSOCKADDR BindAddress;
INT BindAddressLength; INT BindAddressLength;
HANDLE SockEvent;
Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
NULL, 1, FALSE );
if( !NT_SUCCESS(Status) ) return -1;
/* Get the Socket Structure associate to this Socket*/ /* Get the Socket Structure associate to this Socket*/
Socket = GetSocketStructure(Handle); Socket = GetSocketStructure(Handle);
@ -505,6 +535,8 @@ WSPSendTo(
Status = IOSB->Status; Status = IOSB->Status;
} }
NtClose( SockEvent );
if (Status == STATUS_PENDING) { if (Status == STATUS_PENDING) {
return WSA_IO_PENDING; return WSA_IO_PENDING;
} }