Getting there. Smoothing out the public interface and eliminating useless

types.

svn path=/trunk/; revision=11120
This commit is contained in:
Art Yerkes 2004-09-29 06:11:27 +00:00
parent 4c30d6be10
commit a6797af759

View file

@ -17,6 +17,39 @@ LIST_ENTRY SleepingThreadsList;
FAST_MUTEX SleepingThreadsLock; FAST_MUTEX SleepingThreadsLock;
RECURSIVE_MUTEX TCPLock; RECURSIVE_MUTEX TCPLock;
PCONNECTION_ENDPOINT TCPAllocateConnectionEndpoint( PVOID ClientContext ) {
PCONNECTION_ENDPOINT Connection =
ExAllocatePool(NonPagedPool, sizeof(CONNECTION_ENDPOINT));
if (!Connection)
return Connection;
TI_DbgPrint(DEBUG_CPOINT, ("Connection point file object allocated at (0x%X).\n", Connection));
RtlZeroMemory(Connection, sizeof(CONNECTION_ENDPOINT));
/* Initialize spin lock that protects the connection endpoint file object */
KeInitializeSpinLock(&Connection->Lock);
InitializeListHead(&Connection->ConnectRequest);
InitializeListHead(&Connection->ListenRequest);
InitializeListHead(&Connection->ReceiveRequest);
/* Reference the object */
Connection->RefCount = 1;
/* Save client context pointer */
Connection->ClientContext = ClientContext;
/* Initialize received segments queue */
InitializeListHead(&Connection->ReceivedSegments);
return Connection;
}
VOID TCPFreeConnectionEndpoint( PCONNECTION_ENDPOINT Connection ) {
/* XXX Cancel all pending requests */
ExFreePool( Connection );
}
NTSTATUS TCPSocket( PCONNECTION_ENDPOINT Connection, NTSTATUS TCPSocket( PCONNECTION_ENDPOINT Connection,
UINT Family, UINT Type, UINT Proto ) { UINT Family, UINT Type, UINT Proto ) {
NTSTATUS Status; NTSTATUS Status;
@ -165,10 +198,9 @@ NTSTATUS TCPTranslateError( int OskitError ) {
#if 0 #if 0
NTSTATUS TCPBind NTSTATUS TCPBind
( PTDI_REQUEST Request, ( PCONNECTION_ENDPOINT Connection,
PTDI_CONNECTION_INFORMATION ConnInfo ) { PTDI_CONNECTION_INFORMATION ConnInfo ) {
NTSTATUS Status; NTSTATUS Status;
PCONNECTION_ENDPOINT Connection = Request->Handle.ConnectionContext;
SOCKADDR_IN AddressToConnect; SOCKADDR_IN AddressToConnect;
PIP_ADDRESS LocalAddress; PIP_ADDRESS LocalAddress;
USHORT LocalPort; USHORT LocalPort;
@ -198,12 +230,13 @@ NTSTATUS TCPBind
#endif #endif
NTSTATUS TCPConnect NTSTATUS TCPConnect
( PTDI_REQUEST Request, ( PCONNECTION_ENDPOINT Connection,
PTDI_CONNECTION_INFORMATION ConnInfo, PTDI_CONNECTION_INFORMATION ConnInfo,
PTDI_CONNECTION_INFORMATION ReturnInfo ) { PTDI_CONNECTION_INFORMATION ReturnInfo,
PTCP_COMPLETION_ROUTINE Complete,
PVOID Context ) {
NTSTATUS Status; NTSTATUS Status;
SOCKADDR_IN AddressToConnect = { 0 }, AddressToBind = { 0 }; SOCKADDR_IN AddressToConnect = { 0 }, AddressToBind = { 0 };
PCONNECTION_ENDPOINT Connection = Request->Handle.ConnectionContext;
PIP_ADDRESS RemoteAddress; PIP_ADDRESS RemoteAddress;
USHORT RemotePort; USHORT RemotePort;
PTDI_BUCKET Bucket; PTDI_BUCKET Bucket;
@ -216,7 +249,9 @@ NTSTATUS TCPConnect
RecursiveMutexEnter( &TCPLock, TRUE ); RecursiveMutexEnter( &TCPLock, TRUE );
/* Freed in TCPSocketState */ /* Freed in TCPSocketState */
Bucket->Request = *Request; Bucket->Request.RequestNotifyObject = (PVOID)Complete;
Bucket->Request.RequestContext = Context;
InsertHeadList( &Connection->ConnectRequest, &Bucket->Entry ); InsertHeadList( &Connection->ConnectRequest, &Bucket->Entry );
Status = AddrBuildAddress Status = AddrBuildAddress
@ -277,12 +312,11 @@ NTSTATUS TCPClose
} }
NTSTATUS TCPListen NTSTATUS TCPListen
( PTDI_REQUEST Request, ( PCONNECTION_ENDPOINT Connection,
UINT Backlog ) { UINT Backlog,
PCONNECTION_ENDPOINT Connection; PTCP_COMPLETION_ROUTINE Complete,
NTSTATUS Status; PVOID Context) {
NTSTATUS Status;
Connection = Request->Handle.ConnectionContext;
RecursiveMutexEnter( &TCPLock, TRUE ); RecursiveMutexEnter( &TCPLock, TRUE );
@ -301,12 +335,13 @@ NTSTATUS TCPAccept
} }
NTSTATUS TCPReceiveData NTSTATUS TCPReceiveData
( PTDI_REQUEST Request, ( PCONNECTION_ENDPOINT Connection,
PNDIS_BUFFER Buffer, PNDIS_BUFFER Buffer,
ULONG ReceiveLength, ULONG ReceiveLength,
ULONG ReceiveFlags, ULONG ReceiveFlags,
PULONG BytesReceived ) { PULONG BytesReceived,
PCONNECTION_ENDPOINT Connection; PTCP_COMPLETION_ROUTINE Complete,
PVOID Context ) {
PCHAR DataBuffer; PCHAR DataBuffer;
UINT DataLen, Received = 0; UINT DataLen, Received = 0;
NTSTATUS Status; NTSTATUS Status;
@ -314,8 +349,6 @@ NTSTATUS TCPReceiveData
TI_DbgPrint(MID_TRACE,("Called for %d bytes\n", ReceiveLength)); TI_DbgPrint(MID_TRACE,("Called for %d bytes\n", ReceiveLength));
Connection = Request->Handle.ConnectionContext;
RecursiveMutexEnter( &TCPLock, TRUE ); RecursiveMutexEnter( &TCPLock, TRUE );
NdisQueryBuffer( Buffer, &DataBuffer, &DataLen ); NdisQueryBuffer( Buffer, &DataBuffer, &DataLen );
@ -342,7 +375,8 @@ NTSTATUS TCPReceiveData
return STATUS_NO_MEMORY; return STATUS_NO_MEMORY;
} }
Bucket->Request = *Request; Bucket->Request.RequestNotifyObject = Complete;
Bucket->Request.RequestContext = Context;
*BytesReceived = 0; *BytesReceived = 0;
InsertHeadList( &Connection->ReceiveRequest, &Bucket->Entry ); InsertHeadList( &Connection->ReceiveRequest, &Bucket->Entry );
Status = STATUS_PENDING; Status = STATUS_PENDING;
@ -360,18 +394,15 @@ NTSTATUS TCPReceiveData
} }
NTSTATUS TCPSendData NTSTATUS TCPSendData
( PTDI_REQUEST Request, ( PCONNECTION_ENDPOINT Connection,
PNDIS_BUFFER Buffer, PNDIS_BUFFER Buffer,
ULONG DataSize, ULONG DataSize,
ULONG Flags, ULONG Flags,
PULONG DataUsed ) { PULONG DataUsed) {
NTSTATUS Status; NTSTATUS Status;
PCONNECTION_ENDPOINT Connection;
PCHAR BufferData; PCHAR BufferData;
ULONG PacketSize; ULONG PacketSize;
Connection = Request->Handle.ConnectionContext;
RecursiveMutexEnter( &TCPLock, TRUE ); RecursiveMutexEnter( &TCPLock, TRUE );
NdisQueryBuffer( Buffer, &BufferData, &PacketSize ); NdisQueryBuffer( Buffer, &BufferData, &PacketSize );