ReactOS  0.4.13-dev-1174-gdff75d7
listen.c File Reference
#include "afd.h"
Include dependency graph for listen.c:

Go to the source code of this file.

Functions

static NTSTATUS SatisfyAccept (PAFD_DEVICE_EXTENSION DeviceExt, PIRP Irp, PFILE_OBJECT NewFileObject, PAFD_TDI_OBJECT_QELT Qelt)
 
static NTSTATUS SatisfyPreAccept (PIRP Irp, PAFD_TDI_OBJECT_QELT Qelt)
 
static NTSTATUS NTAPI ListenComplete (PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
 
NTSTATUS AfdListenSocket (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS AfdWaitForListen (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS AfdAccept (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 

Variables

static IO_COMPLETION_ROUTINE ListenComplete
 

Function Documentation

◆ AfdAccept()

NTSTATUS AfdAccept ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 337 of file listen.c.

338  {
341  PAFD_DEVICE_EXTENSION DeviceExt =
343  PAFD_FCB FCB = FileObject->FsContext;
344  PAFD_ACCEPT_DATA AcceptData = Irp->AssociatedIrp.SystemBuffer;
345  PLIST_ENTRY PendingConn;
346 
347  AFD_DbgPrint(MID_TRACE,("Called\n"));
348 
349  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
350 
351  FCB->EventSelectDisabled &= ~AFD_EVENT_ACCEPT;
352 
353  for( PendingConn = FCB->PendingConnections.Flink;
354  PendingConn != &FCB->PendingConnections;
355  PendingConn = PendingConn->Flink ) {
356  PAFD_TDI_OBJECT_QELT PendingConnObj =
357  CONTAINING_RECORD( PendingConn, AFD_TDI_OBJECT_QELT, ListEntry );
358 
359  AFD_DbgPrint(MID_TRACE,("Comparing Seq %u to Q %u\n",
360  AcceptData->SequenceNumber,
361  PendingConnObj->Seq));
362 
363  if( PendingConnObj->Seq == AcceptData->SequenceNumber ) {
365 
366  RemoveEntryList( PendingConn );
367 
369  ( AcceptData->ListenHandle,
371  NULL,
372  KernelMode,
373  (PVOID *)&NewFileObject,
374  NULL );
375 
376  if( !NT_SUCCESS(Status) ) return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
377 
379  ASSERT(NewFileObject->FsContext != FCB);
380 
381  /* We have a pending connection ... complete this irp right away */
382  Status = SatisfyAccept( DeviceExt, Irp, NewFileObject, PendingConnObj );
383 
385 
386  AFD_DbgPrint(MID_TRACE,("Completed a wait for accept\n"));
387 
388  ExFreePoolWithTag(PendingConnObj, TAG_AFD_ACCEPT_QUEUE);
389 
390  if( !IsListEmpty( &FCB->PendingConnections ) )
391  {
392  FCB->PollState |= AFD_EVENT_ACCEPT;
393  FCB->PollStatus[FD_ACCEPT_BIT] = STATUS_SUCCESS;
394  PollReeval( FCB->DeviceExt, FCB->FileObject );
395  } else
396  FCB->PollState &= ~AFD_EVENT_ACCEPT;
397 
399  return Status;
400  }
401  }
402 
403  AFD_DbgPrint(MIN_TRACE,("No connection waiting\n"));
404 
406 }
VOID SocketStateUnlock(PAFD_FCB FCB)
Definition: lock.c:370
#define MID_TRACE
Definition: debug.h:15
VOID PollReeval(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: select.c:407
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
PFILE_OBJECT FileObject
Definition: ntfs.h:516
_In_ PIRP Irp
Definition: csq.h:116
Definition: cdstruc.h:908
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
_Must_inspect_result_ _In_ PFILE_OBJECT NewFileObject
Definition: fsrtlfuncs.h:1357
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define TAG_AFD_ACCEPT_QUEUE
Definition: afd.h:46
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
Definition: afd.h:161
#define AFD_EVENT_ACCEPT
Definition: shared.h:210
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static NTSTATUS SatisfyAccept(PAFD_DEVICE_EXTENSION DeviceExt, PIRP Irp, PFILE_OBJECT NewFileObject, PAFD_TDI_OBJECT_QELT Qelt)
Definition: listen.c:13
struct _AFD_DEVICE_EXTENSION * PAFD_DEVICE_EXTENSION
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define FD_ACCEPT_BIT
Definition: winsock2.h:299
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define MIN_TRACE
Definition: debug.h:14
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AfdDispatch().

◆ AfdListenSocket()

NTSTATUS AfdListenSocket ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 225 of file listen.c.

226  {
229  PAFD_FCB FCB = FileObject->FsContext;
230  PAFD_LISTEN_DATA ListenReq;
231 
233 
234  AFD_DbgPrint(MID_TRACE,("Called on %p\n", FCB));
235 
236  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
237 
238  if( !(ListenReq = LockRequest( Irp, IrpSp, FALSE, NULL )) )
240  0 );
241 
242  if( FCB->State != SOCKET_STATE_BOUND ) {
244  AFD_DbgPrint(MIN_TRACE,("Could not listen an unbound socket\n"));
245  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
246  }
247 
248  FCB->DelayedAccept = ListenReq->UseDelayedAcceptance;
249 
250  AFD_DbgPrint(MID_TRACE,("ADDRESSFILE: %p\n", FCB->AddressFile.Handle));
251 
253 
254  AFD_DbgPrint(MID_TRACE,("Status from warmsocket %x\n", Status));
255 
256  if( !NT_SUCCESS(Status) ) return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
257 
259  ( &FCB->ListenIrp.ConnectionCallInfo,
260  FCB->LocalAddress->Address[0].AddressType );
261 
263 
265  ( &FCB->ListenIrp.ConnectionReturnInfo,
266  FCB->LocalAddress->Address[0].AddressType );
267 
268  if (!NT_SUCCESS(Status))
269  {
270  ExFreePoolWithTag(FCB->ListenIrp.ConnectionCallInfo,
272 
273  FCB->ListenIrp.ConnectionCallInfo = NULL;
274  return UnlockAndMaybeComplete(FCB, Status, Irp, 0);
275  }
276 
277  FCB->State = SOCKET_STATE_LISTENING;
278 
279  Status = TdiListen( &FCB->ListenIrp.InFlightRequest,
280  FCB->Connection.Object,
281  &FCB->ListenIrp.ConnectionCallInfo,
282  &FCB->ListenIrp.ConnectionReturnInfo,
284  FCB );
285 
286  if( Status == STATUS_PENDING )
288 
289  AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
290  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
291 }
#define MID_TRACE
Definition: debug.h:15
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
#define TAG_AFD_TDI_CONNECTION_INFORMATION
Definition: afd.h:53
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
BOOLEAN UseDelayedAcceptance
Definition: shared.h:46
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
static IO_COMPLETION_ROUTINE ListenComplete
Definition: listen.c:89
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
Definition: afd.h:161
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
NTSTATUS TdiListen(PIRP *Irp, PFILE_OBJECT ConnectionObject, PTDI_CONNECTION_INFORMATION *RequestConnectionInfo, PTDI_CONNECTION_INFORMATION *ReturnConnectionInfo, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
Definition: tdi.c:489
NTSTATUS WarmSocketForConnection(PAFD_FCB FCB)
Definition: connect.c:238
* PFILE_OBJECT
Definition: iotypes.h:1955
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define SOCKET_STATE_LISTENING
Definition: afd.h:77
#define SOCKET_STATE_BOUND
Definition: afd.h:74
#define MIN_TRACE
Definition: debug.h:14
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2966
NTSTATUS TdiBuildNullConnectionInfo(PTDI_CONNECTION_INFORMATION *ConnectionInfo, ULONG Type)
Definition: tdiconn.c:171

Referenced by AfdDispatch().

◆ AfdWaitForListen()

NTSTATUS AfdWaitForListen ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 293 of file listen.c.

294  {
296  PAFD_FCB FCB = FileObject->FsContext;
298 
300 
301  AFD_DbgPrint(MID_TRACE,("Called\n"));
302 
303  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
304 
305  if( !IsListEmpty( &FCB->PendingConnections ) ) {
306  PLIST_ENTRY PendingConn = FCB->PendingConnections.Flink;
307 
308  /* We have a pending connection ... complete this irp right away */
310  ( Irp,
312  ( PendingConn, AFD_TDI_OBJECT_QELT, ListEntry ) );
313 
314  AFD_DbgPrint(MID_TRACE,("Completed a wait for accept\n"));
315 
316  if ( !IsListEmpty( &FCB->PendingConnections ) )
317  {
318  FCB->PollState |= AFD_EVENT_ACCEPT;
319  FCB->PollStatus[FD_ACCEPT_BIT] = STATUS_SUCCESS;
320  PollReeval( FCB->DeviceExt, FCB->FileObject );
321  } else
322  FCB->PollState &= ~AFD_EVENT_ACCEPT;
323 
325  return Status;
326  } else if (FCB->NonBlocking) {
327  AFD_DbgPrint(MIN_TRACE,("No connection ready on a non-blocking socket\n"));
328 
330  } else {
331  AFD_DbgPrint(MID_TRACE,("Holding\n"));
332 
334  }
335 }
VOID SocketStateUnlock(PAFD_FCB FCB)
Definition: lock.c:370
static NTSTATUS SatisfyPreAccept(PIRP Irp, PAFD_TDI_OBJECT_QELT Qelt)
Definition: listen.c:52
#define MID_TRACE
Definition: debug.h:15
VOID PollReeval(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: select.c:407
PFILE_OBJECT FileObject
Definition: ntfs.h:516
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define FUNCTION_PREACCEPT
Definition: afd.h:87
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
Definition: afd.h:161
#define AFD_EVENT_ACCEPT
Definition: shared.h:210
NTSTATUS LeaveIrpUntilLater(PAFD_FCB FCB, PIRP Irp, UINT Function)
Definition: lock.c:433
* PFILE_OBJECT
Definition: iotypes.h:1955
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define FD_ACCEPT_BIT
Definition: winsock2.h:299
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define MIN_TRACE
Definition: debug.h:14
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define STATUS_CANT_WAIT
Definition: ntstatus.h:438

Referenced by AfdDispatch().

◆ ListenComplete()

static NTSTATUS NTAPI ListenComplete ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PVOID  Context 
)
static

Definition at line 90 of file listen.c.

92  {
96  PLIST_ENTRY NextIrpEntry;
97  PIRP NextIrp;
98 
100 
101  if( !SocketAcquireStateLock( FCB ) )
102  return STATUS_FILE_CLOSED;
103 
104  ASSERT(FCB->ListenIrp.InFlightRequest == Irp);
105  FCB->ListenIrp.InFlightRequest = NULL;
106 
107  if( FCB->State == SOCKET_STATE_CLOSED ) {
108  /* Cleanup our IRP queue because the FCB is being destroyed */
109  while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_PREACCEPT] ) ) {
110  NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_PREACCEPT]);
111  NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
112  NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
113  NextIrp->IoStatus.Information = 0;
114  if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
115  (void)IoSetCancelRoutine(NextIrp, NULL);
117  }
118 
119  /* Free ConnectionReturnInfo and ConnectionCallInfo */
120  if (FCB->ListenIrp.ConnectionReturnInfo)
121  {
122  ExFreePoolWithTag(FCB->ListenIrp.ConnectionReturnInfo,
124 
125  FCB->ListenIrp.ConnectionReturnInfo = NULL;
126  }
127 
128  if (FCB->ListenIrp.ConnectionCallInfo)
129  {
130  ExFreePoolWithTag(FCB->ListenIrp.ConnectionCallInfo,
132 
133  FCB->ListenIrp.ConnectionCallInfo = NULL;
134  }
135 
137  return STATUS_FILE_CLOSED;
138  }
139 
140  AFD_DbgPrint(MID_TRACE,("Completing listen request.\n"));
141  AFD_DbgPrint(MID_TRACE,("IoStatus was %x\n", Irp->IoStatus.Status));
142 
143  if (Irp->IoStatus.Status != STATUS_SUCCESS)
144  {
146  return Irp->IoStatus.Status;
147  }
148 
150  sizeof(*Qelt),
152 
153  if( !Qelt ) {
155  } else {
156  UINT AddressType =
157  FCB->LocalAddress->Address[0].AddressType;
158 
159  Qelt->Object = FCB->Connection;
160  Qelt->Seq = FCB->ConnSeq++;
161  AFD_DbgPrint(MID_TRACE,("Address Type: %u (RA %p)\n",
162  AddressType,
163  FCB->ListenIrp.
164  ConnectionReturnInfo->RemoteAddress));
165 
166  Status = TdiBuildNullConnectionInfo( &Qelt->ConnInfo, AddressType );
167  if( NT_SUCCESS(Status) ) {
169  ( Qelt->ConnInfo->RemoteAddress,
170  FCB->ListenIrp.ConnectionReturnInfo->RemoteAddress );
171  InsertTailList( &FCB->PendingConnections, &Qelt->ListEntry );
172  }
173  }
174 
175  /* Satisfy a pre-accept request if one is available */
176  if( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_PREACCEPT] ) &&
177  !IsListEmpty( &FCB->PendingConnections ) ) {
178  PLIST_ENTRY PendingIrp =
179  RemoveHeadList( &FCB->PendingIrpList[FUNCTION_PREACCEPT] );
180  PLIST_ENTRY PendingConn = FCB->PendingConnections.Flink;
182  ( CONTAINING_RECORD( PendingIrp, IRP,
183  Tail.Overlay.ListEntry ),
185  ListEntry ) );
186  }
187 
188  /* Launch new accept socket */
190 
191  if (NT_SUCCESS(Status))
192  {
193  Status = TdiBuildNullConnectionInfoInPlace(FCB->ListenIrp.ConnectionCallInfo,
194  FCB->LocalAddress->Address[0].AddressType);
196 
197  Status = TdiBuildNullConnectionInfoInPlace(FCB->ListenIrp.ConnectionReturnInfo,
198  FCB->LocalAddress->Address[0].AddressType);
200 
201  Status = TdiListen( &FCB->ListenIrp.InFlightRequest,
202  FCB->Connection.Object,
203  &FCB->ListenIrp.ConnectionCallInfo,
204  &FCB->ListenIrp.ConnectionReturnInfo,
206  FCB );
207 
208  if (Status == STATUS_PENDING)
210  }
211 
212  /* Trigger a select return if appropriate */
213  if( !IsListEmpty( &FCB->PendingConnections ) ) {
214  FCB->PollState |= AFD_EVENT_ACCEPT;
215  FCB->PollStatus[FD_ACCEPT_BIT] = STATUS_SUCCESS;
216  PollReeval( FCB->DeviceExt, FCB->FileObject );
217  } else
218  FCB->PollState &= ~AFD_EVENT_ACCEPT;
219 
221 
222  return Status;
223 }
VOID SocketStateUnlock(PAFD_FCB FCB)
Definition: lock.c:370
static NTSTATUS SatisfyPreAccept(PIRP Irp, PAFD_TDI_OBJECT_QELT Qelt)
Definition: listen.c:52
#define MID_TRACE
Definition: debug.h:15
NTSTATUS TdiBuildNullConnectionInfoInPlace(PTDI_CONNECTION_INFORMATION ConnInfo, ULONG Type)
Definition: tdiconn.c:137
PTDI_CONNECTION_INFORMATION ConnInfo
Definition: afd.h:139
VOID PollReeval(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: select.c:407
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
PFILE_OBJECT FileObject
Definition: ntfs.h:516
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
#define TAG_AFD_TDI_CONNECTION_INFORMATION
Definition: afd.h:53
LIST_ENTRY ListEntry
Definition: afd.h:137
AFD_TDI_OBJECT Object
Definition: afd.h:140
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
IRP
Definition: iotypes.h:2463
#define InsertTailList(ListHead, Entry)
IoSetCancelRoutine(Irp, CancelRoutine)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
static IO_COMPLETION_ROUTINE ListenComplete
Definition: listen.c:89
#define FUNCTION_PREACCEPT
Definition: afd.h:87
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
#define TAG_AFD_ACCEPT_QUEUE
Definition: afd.h:46
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
Definition: afd.h:161
struct _AFD_FCB * PAFD_FCB
#define AFD_EVENT_ACCEPT
Definition: shared.h:210
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID UnlockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lock.c:180
NTSTATUS TdiListen(PIRP *Irp, PFILE_OBJECT ConnectionObject, PTDI_CONNECTION_INFORMATION *RequestConnectionInfo, PTDI_CONNECTION_INFORMATION *ReturnConnectionInfo, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
Definition: tdi.c:489
NTSTATUS WarmSocketForConnection(PAFD_FCB FCB)
Definition: connect.c:238
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID TaCopyTransportAddressInPlace(PTRANSPORT_ADDRESS Target, PTRANSPORT_ADDRESS Source)
Definition: tdiconn.c:74
#define FD_ACCEPT_BIT
Definition: winsock2.h:299
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int UINT
Definition: ndis.h:50
#define SOCKET_STATE_CLOSED
Definition: afd.h:82
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2966
NTSTATUS TdiBuildNullConnectionInfo(PTDI_CONNECTION_INFORMATION *ConnectionInfo, ULONG Type)
Definition: tdiconn.c:171
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:518

◆ SatisfyAccept()

static NTSTATUS SatisfyAccept ( PAFD_DEVICE_EXTENSION  DeviceExt,
PIRP  Irp,
PFILE_OBJECT  NewFileObject,
PAFD_TDI_OBJECT_QELT  Qelt 
)
static

Definition at line 13 of file listen.c.

16  {
17  PAFD_FCB FCB = NewFileObject->FsContext;
19 
20  UNREFERENCED_PARAMETER(DeviceExt);
21 
22  if( !SocketAcquireStateLock( FCB ) )
23  return LostSocket( Irp );
24 
25  /* Transfer the connection to the new socket, launch the opening read */
26  AFD_DbgPrint(MID_TRACE,("Completing a real accept (FCB %p)\n", FCB));
27 
28  FCB->Connection = Qelt->Object;
29 
30  if (FCB->RemoteAddress)
31  {
33  }
34 
35  FCB->RemoteAddress =
37 
38  if( !FCB->RemoteAddress )
40  else
42 
43  if (NT_SUCCESS(Status))
44  Status = TdiBuildConnectionInfo(&FCB->ConnectCallInfo, FCB->RemoteAddress);
45 
46  if (NT_SUCCESS(Status))
47  Status = TdiBuildConnectionInfo(&FCB->ConnectReturnInfo, FCB->RemoteAddress);
48 
49  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
50 }
#define MID_TRACE
Definition: debug.h:15
PTDI_CONNECTION_INFORMATION ConnInfo
Definition: afd.h:139
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
AFD_TDI_OBJECT Object
Definition: afd.h:140
LONG NTSTATUS
Definition: precomp.h:26
#define TAG_AFD_TRANSPORT_ADDRESS
Definition: afd.h:39
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
_Must_inspect_result_ _In_ PFILE_OBJECT NewFileObject
Definition: fsrtlfuncs.h:1357
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
Definition: afd.h:161
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS TdiBuildConnectionInfo(PTDI_CONNECTION_INFORMATION *ConnectionInfo, PTRANSPORT_ADDRESS Address)
Definition: tdiconn.c:237
NTSTATUS MakeSocketIntoConnection(PAFD_FCB FCB)
Definition: connect.c:259
Status
Definition: gdiplustypes.h:24
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
PTRANSPORT_ADDRESS TaCopyTransportAddress(PTRANSPORT_ADDRESS OtherAddress)
Definition: tdiconn.c:80
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by AfdAccept().

◆ SatisfyPreAccept()

static NTSTATUS SatisfyPreAccept ( PIRP  Irp,
PAFD_TDI_OBJECT_QELT  Qelt 
)
static

Definition at line 52 of file listen.c.

52  {
53  PAFD_RECEIVED_ACCEPT_DATA ListenReceive =
54  (PAFD_RECEIVED_ACCEPT_DATA)Irp->AssociatedIrp.SystemBuffer;
56 
57  ListenReceive->SequenceNumber = Qelt->Seq;
58 
59  AFD_DbgPrint(MID_TRACE,("Giving SEQ %u to userland\n", Qelt->Seq));
60  AFD_DbgPrint(MID_TRACE,("Socket Address (K) %p (U) %p\n",
61  &ListenReceive->Address,
62  Qelt->ConnInfo->RemoteAddress));
63 
64  TaCopyTransportAddressInPlace( &ListenReceive->Address,
65  Qelt->ConnInfo->RemoteAddress );
66 
67  IPAddr = (PTA_IP_ADDRESS)&ListenReceive->Address;
68 
69  AFD_DbgPrint(MID_TRACE,("IPAddr->TAAddressCount %d\n",
70  IPAddr->TAAddressCount));
71  AFD_DbgPrint(MID_TRACE,("IPAddr->Address[0].AddressType %u\n",
72  IPAddr->Address[0].AddressType));
73  AFD_DbgPrint(MID_TRACE,("IPAddr->Address[0].AddressLength %u\n",
74  IPAddr->Address[0].AddressLength));
75  AFD_DbgPrint(MID_TRACE,("IPAddr->Address[0].Address[0].sin_port %x\n",
76  IPAddr->Address[0].Address[0].sin_port));
77  AFD_DbgPrint(MID_TRACE,("IPAddr->Address[0].Address[0].sin_addr %x\n",
78  IPAddr->Address[0].Address[0].in_addr));
79 
80  if( Irp->MdlAddress ) UnlockRequest( Irp, IoGetCurrentIrpStackLocation( Irp ) );
81 
82  Irp->IoStatus.Information = ((PCHAR)&IPAddr[1]) - ((PCHAR)ListenReceive);
83  Irp->IoStatus.Status = STATUS_SUCCESS;
86  return STATUS_SUCCESS;
87 }
TRANSPORT_ADDRESS Address
Definition: shared.h:70
#define MID_TRACE
Definition: debug.h:15
PTDI_CONNECTION_INFORMATION ConnInfo
Definition: afd.h:139
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
_In_ PIRP Irp
Definition: csq.h:116
struct _TA_ADDRESS_IP * PTA_IP_ADDRESS
struct _AFD_RECEIVED_ACCEPT_DATA * PAFD_RECEIVED_ACCEPT_DATA
IoSetCancelRoutine(Irp, CancelRoutine)
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
ULONG IPAddr
Definition: pfhook.h:35
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
#define PCHAR
Definition: match.c:90
VOID UnlockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lock.c:180
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID TaCopyTransportAddressInPlace(PTRANSPORT_ADDRESS Target, PTRANSPORT_ADDRESS Source)
Definition: tdiconn.c:74
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AfdWaitForListen(), and ListenComplete().

Variable Documentation

◆ ListenComplete

IO_COMPLETION_ROUTINE ListenComplete
static

Definition at line 89 of file listen.c.

Referenced by AfdListenSocket(), and ListenComplete().