[MSAFD/AFD]

- Pass the non-blocking information as a boolean (mswsock_new does this too)
[AFD]
- Don't block waiting for a connection to accept on a non-blocking listener

svn path=/trunk/; revision=52537
This commit is contained in:
Cameron Gutman 2011-07-04 17:37:45 +00:00
parent c19f9ab75c
commit 0e8f87ff82
9 changed files with 44 additions and 22 deletions

View file

@ -264,7 +264,7 @@ WSPSocket(int AddressFamily,
/* Save Group Info */
if (g != 0)
{
GetSocketInformation(Socket, AFD_INFO_GROUP_ID_TYPE, 0, &GroupData);
GetSocketInformation(Socket, AFD_INFO_GROUP_ID_TYPE, NULL, NULL, &GroupData);
Socket->SharedData.GroupID = GroupData.u.LowPart;
Socket->SharedData.GroupType = GroupData.u.HighPart;
}
@ -272,11 +272,13 @@ WSPSocket(int AddressFamily,
/* Get Window Sizes and Save them */
GetSocketInformation (Socket,
AFD_INFO_SEND_WINDOW_SIZE,
NULL,
&Socket->SharedData.SizeOfSendBuffer,
NULL);
GetSocketInformation (Socket,
AFD_INFO_RECEIVE_WINDOW_SIZE,
NULL,
&Socket->SharedData.SizeOfRecvBuffer,
NULL);
@ -467,6 +469,7 @@ WSPCloseSocket(IN SOCKET Handle,
/* Find out how many Sends are in Progress */
if (GetSocketInformation(Socket,
AFD_INFO_SENDS_IN_PROGRESS,
NULL,
&SendsInProgress,
NULL))
{
@ -1951,6 +1954,7 @@ WSPIoctl(IN SOCKET Handle,
{
PSOCKET_INFORMATION Socket = NULL;
BOOLEAN NeedsCompletion;
BOOLEAN NonBlocking;
/* Get the Socket Structure associate to this Socket*/
Socket = GetSocketStructure(Handle);
@ -1970,8 +1974,9 @@ WSPIoctl(IN SOCKET Handle,
*lpErrno = WSAEFAULT;
return SOCKET_ERROR;
}
Socket->SharedData.NonBlocking = *((PULONG)lpvInBuffer) ? 1 : 0;
*lpErrno = SetSocketInformation(Socket, AFD_INFO_BLOCKING_MODE, (PULONG)lpvInBuffer, NULL);
NonBlocking = *((PULONG)lpvInBuffer) ? TRUE : FALSE;
Socket->SharedData.NonBlocking = NonBlocking ? 1 : 0;
*lpErrno = SetSocketInformation(Socket, AFD_INFO_BLOCKING_MODE, &NonBlocking, NULL, NULL);
if (*lpErrno != NO_ERROR)
return SOCKET_ERROR;
else
@ -1982,7 +1987,7 @@ WSPIoctl(IN SOCKET Handle,
*lpErrno = WSAEFAULT;
return SOCKET_ERROR;
}
*lpErrno = GetSocketInformation(Socket, AFD_INFO_RECEIVE_CONTENT_SIZE, (PULONG)lpvOutBuffer, NULL);
*lpErrno = GetSocketInformation(Socket, AFD_INFO_RECEIVE_CONTENT_SIZE, NULL, (PULONG)lpvOutBuffer, NULL);
if (*lpErrno != NO_ERROR)
return SOCKET_ERROR;
else
@ -2258,6 +2263,7 @@ WSPCleanup(OUT LPINT lpErrno)
int
GetSocketInformation(PSOCKET_INFORMATION Socket,
ULONG AfdInformationClass,
PBOOLEAN Boolean OPTIONAL,
PULONG Ulong OPTIONAL,
PLARGE_INTEGER LargeInteger OPTIONAL)
{
@ -2309,6 +2315,10 @@ GetSocketInformation(PSOCKET_INFORMATION Socket,
{
*LargeInteger = InfoData.Information.LargeInteger;
}
if (Boolean != NULL)
{
*Boolean = InfoData.Information.Boolean;
}
NtClose( SockEvent );
@ -2319,7 +2329,8 @@ GetSocketInformation(PSOCKET_INFORMATION Socket,
int
SetSocketInformation(PSOCKET_INFORMATION Socket,
ULONG AfdInformationClass,
ULONG AfdInformationClass,
PBOOLEAN Boolean OPTIONAL,
PULONG Ulong OPTIONAL,
PLARGE_INTEGER LargeInteger OPTIONAL)
{
@ -2349,6 +2360,10 @@ SetSocketInformation(PSOCKET_INFORMATION Socket,
{
InfoData.Information.LargeInteger = *LargeInteger;
}
if (Boolean != NULL)
{
InfoData.Information.Boolean = *Boolean;
}
AFD_DbgPrint(MID_TRACE,("XXX Info %x (Data %x)\n",
AfdInformationClass, *Ulong));

View file

@ -26,7 +26,7 @@ WSPEventSelect(
AFD_EVENT_SELECT_INFO EventSelectInfo;
PSOCKET_INFORMATION Socket = NULL;
NTSTATUS Status;
ULONG BlockMode;
BOOLEAN BlockMode;
HANDLE SockEvent;
Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
@ -44,8 +44,8 @@ WSPEventSelect(
}
/* Set Socket to Non-Blocking */
BlockMode = 1;
SetSocketInformation(Socket, AFD_INFO_BLOCKING_MODE, &BlockMode, NULL);
BlockMode = TRUE;
SetSocketInformation(Socket, AFD_INFO_BLOCKING_MODE, &BlockMode, NULL, NULL);
Socket->SharedData.NonBlocking = TRUE;
/* Deactivate Async Select if there is one */

View file

@ -25,7 +25,7 @@ WSPAsyncSelect(IN SOCKET Handle,
PSOCKET_INFORMATION Socket = NULL;
PASYNC_DATA AsyncData;
NTSTATUS Status;
ULONG BlockMode;
BOOLEAN BlockMode;
/* Get the Socket Structure associated to this Socket */
Socket = GetSocketStructure(Handle);
@ -44,8 +44,8 @@ WSPAsyncSelect(IN SOCKET Handle,
}
/* Change the Socket to Non Blocking */
BlockMode = 1;
SetSocketInformation(Socket, AFD_INFO_BLOCKING_MODE, &BlockMode, NULL);
BlockMode = TRUE;
SetSocketInformation(Socket, AFD_INFO_BLOCKING_MODE, &BlockMode, NULL, NULL);
Socket->SharedData.NonBlocking = TRUE;
/* Deactive WSPEventSelect */

View file

@ -417,14 +417,16 @@ VOID DeleteSocketStructure( SOCKET Handle );
int GetSocketInformation(
PSOCKET_INFORMATION Socket,
ULONG AfdInformationClass,
PULONG Ulong OPTIONAL,
PBOOLEAN Boolean OPTIONAL,
PULONG Ulong OPTIONAL,
PLARGE_INTEGER LargeInteger OPTIONAL
);
int SetSocketInformation(
PSOCKET_INFORMATION Socket,
ULONG AfdInformationClass,
PULONG Ulong OPTIONAL,
PBOOLEAN Boolean OPTIONAL,
PULONG Ulong OPTIONAL,
PLARGE_INTEGER LargeInteger OPTIONAL
);

View file

@ -48,7 +48,7 @@ AfdGetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp,
break;
case AFD_INFO_BLOCKING_MODE:
InfoReq->Information.Ulong = FCB->BlockingMode;
InfoReq->Information.Boolean = FCB->NonBlocking;
break;
case AFD_INFO_RECEIVE_CONTENT_SIZE:
@ -115,8 +115,8 @@ AfdSetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp,
_SEH2_TRY {
switch (InfoReq->InformationClass) {
case AFD_INFO_BLOCKING_MODE:
AFD_DbgPrint(MID_TRACE,("Blocking mode set to %d\n", InfoReq->Information.Ulong));
FCB->BlockingMode = InfoReq->Information.Ulong;
AFD_DbgPrint(MID_TRACE,("Blocking mode set to %d\n", InfoReq->Information.Boolean));
FCB->NonBlocking = InfoReq->Information.Boolean;
break;
default:
AFD_DbgPrint(MIN_TRACE,("Unknown request %d\n", InfoReq->InformationClass));

View file

@ -315,6 +315,10 @@ NTSTATUS AfdWaitForListen( PDEVICE_OBJECT DeviceObject, PIRP Irp,
SocketStateUnlock( FCB );
return Status;
} else if (FCB->NonBlocking) {
AFD_DbgPrint(MID_TRACE,("No connection ready on a non-blocking socket\n"));
return UnlockAndMaybeComplete(FCB, STATUS_CANT_WAIT, Irp, 0);
} else {
AFD_DbgPrint(MID_TRACE,("Holding\n"));

View file

@ -346,7 +346,8 @@ AfdConnectedSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
Status = ReceiveActivity( FCB, Irp );
if( Status == STATUS_PENDING && (RecvReq->AfdFlags & AFD_IMMEDIATE) ) {
if( Status == STATUS_PENDING &&
((RecvReq->AfdFlags & AFD_IMMEDIATE) || (FCB->NonBlocking)) ) {
AFD_DbgPrint(MID_TRACE,("Nonblocking\n"));
Status = STATUS_CANT_WAIT;
TotalBytesCopied = 0;
@ -690,7 +691,7 @@ AfdPacketSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
return UnlockAndMaybeComplete
( FCB, Status, Irp, Irp->IoStatus.Information );
}
} else if( RecvReq->AfdFlags & AFD_IMMEDIATE ) {
} else if( (RecvReq->AfdFlags & AFD_IMMEDIATE) || (FCB->NonBlocking) ) {
AFD_DbgPrint(MID_TRACE,("Nonblocking\n"));
Status = STATUS_CANT_WAIT;
FCB->PollState &= ~AFD_EVENT_RECEIVE;

View file

@ -340,7 +340,7 @@ AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
AFD_DbgPrint(MID_TRACE,("Socket state %d\n", FCB->State));
if( FCB->State != SOCKET_STATE_CONNECTED ) {
if( SendReq->AfdFlags & AFD_IMMEDIATE ) {
if( (SendReq->AfdFlags & AFD_IMMEDIATE) || (FCB->NonBlocking) ) {
AFD_DbgPrint(MID_TRACE,("Nonblocking\n"));
UnlockBuffers( SendReq->BufferArray, SendReq->BufferCount, FALSE );
return UnlockAndMaybeComplete
@ -404,7 +404,7 @@ AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
else
{
FCB->PollState &= ~AFD_EVENT_SEND;
if( SendReq->AfdFlags & AFD_IMMEDIATE ) {
if( (SendReq->AfdFlags & AFD_IMMEDIATE) || (FCB->NonBlocking) ) {
AFD_DbgPrint(MID_TRACE,("Nonblocking\n"));
UnlockBuffers( SendReq->BufferArray, SendReq->BufferCount, FALSE );
return UnlockAndMaybeComplete

View file

@ -173,8 +173,8 @@ typedef struct _AFD_STORED_DATAGRAM {
} AFD_STORED_DATAGRAM, *PAFD_STORED_DATAGRAM;
typedef struct _AFD_FCB {
BOOLEAN Locked, Critical, Overread;
UINT State, Flags, BlockingMode, GroupID, GroupType;
BOOLEAN Locked, Critical, Overread, NonBlocking;
UINT State, Flags, GroupID, GroupType;
KIRQL OldIrql;
UINT LockCount;
PVOID CurrentThread;