ReactOS  0.4.13-dev-1149-g95dd1c6
event.c File Reference
#include <afd.h>
Include dependency graph for event.c:

Go to the source code of this file.

Functions

NTSTATUS AfdEventError (IN PVOID TdiEventContext, IN NTSTATUS Status)
 
NTSTATUS AfdEventDisconnect (IN PVOID TdiEventContext, IN CONNECTION_CONTEXT ConnectionContext, IN LONG DisconnectDataLength, IN PVOID DisconnectData, IN LONG DisconnectInformationLength, IN PVOID DisconnectInformation, IN ULONG DisconnectFlags)
 
NTSTATUS AfdEventReceive (IN PVOID TdiEventContext, IN CONNECTION_CONTEXT ConnectionContext, IN ULONG ReceiveFlags, IN ULONG BytesIndicated, IN ULONG BytesAvailable, OUT ULONG *BytesTaken, IN PVOID Tsdu, OUT PIRP *IoRequestPacket)
 
TDI_STATUS ClientEventReceiveExpedited (IN PVOID TdiEventContext, IN CONNECTION_CONTEXT ConnectionContext, IN ULONG ReceiveFlags, IN ULONG BytesIndicated, IN ULONG BytesAvailable, OUT ULONG *BytesTaken, IN PVOID Tsdu, OUT PIRP *IoRequestPacket)
 
NTSTATUS ClientEventChainedReceive (IN PVOID TdiEventContext, IN CONNECTION_CONTEXT ConnectionContext, IN ULONG ReceiveFlags, IN ULONG ReceiveLength, IN ULONG StartingOffset, IN PMDL Tsdu, IN PVOID TsduDescriptor)
 
NTSTATUS AfdEventReceiveDatagramHandler (IN PVOID TdiEventContext, IN LONG SourceAddressLength, IN PVOID SourceAddress, IN LONG OptionsLength, IN PVOID Options, IN ULONG ReceiveDatagramFlags, IN ULONG BytesIndicated, IN ULONG BytesAvailable, OUT ULONG *BytesTaken, IN PVOID Tsdu, OUT PIRP *IoRequestPacket)
 
NTSTATUS AfdRegisterEventHandlers (PAFDFCB FCB)
 
NTSTATUS AfdDeregisterEventHandlers (PAFDFCB FCB)
 

Function Documentation

◆ AfdDeregisterEventHandlers()

NTSTATUS AfdDeregisterEventHandlers ( PAFDFCB  FCB)

Definition at line 274 of file event.c.

276 {
278 
279  Status = TdiSetEventHandler(FCB->TdiAddressObject,
281  NULL,
282  NULL);
283  if (!NT_SUCCESS(Status)) { return Status; }
284 
285  switch (FCB->SocketType) {
286  case SOCK_STREAM:
287  Status = TdiSetEventHandler(FCB->TdiAddressObject,
289  NULL,
290  NULL);
291  if (!NT_SUCCESS(Status)) { return Status; }
292 
293  Status = TdiSetEventHandler(FCB->TdiAddressObject,
295  NULL,
296  NULL);
297  if (!NT_SUCCESS(Status)) { return Status; }
298 
299  Status = TdiSetEventHandler(FCB->TdiAddressObject,
301  NULL,
302  NULL);
303  if (!NT_SUCCESS(Status)) { return Status; }
304 
305  Status = TdiSetEventHandler(FCB->TdiAddressObject,
307  NULL,
308  NULL);
309  if (!NT_SUCCESS(Status)) { return Status; }
310  break;
311 
312  case SOCK_DGRAM:
313  case SOCK_RAW:
314  Status = TdiSetEventHandler(FCB->TdiAddressObject,
316  NULL,
317  NULL);
318  if (!NT_SUCCESS(Status)) { return Status; }
319  }
320  return STATUS_SUCCESS;
321 }
Definition: cdstruc.h:908
LONG NTSTATUS
Definition: precomp.h:26
#define TDI_EVENT_RECEIVE_EXPEDITED
Definition: tdikrnl.h:151
#define TDI_EVENT_DISCONNECT
Definition: tdikrnl.h:147
#define SOCK_RAW
Definition: winsock.h:337
#define TDI_EVENT_RECEIVE
Definition: tdikrnl.h:149
NTSTATUS TdiSetEventHandler(PFILE_OBJECT FileObject, LONG EventType, PVOID Handler, PVOID Context)
Definition: tdi.c:546
smooth NULL
Definition: ftsmooth.c:416
#define TDI_EVENT_CHAINED_RECEIVE
Definition: tdikrnl.h:153
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define TDI_EVENT_RECEIVE_DATAGRAM
Definition: tdikrnl.h:150
Status
Definition: gdiplustypes.h:24
#define SOCK_STREAM
Definition: tcpip.h:118
#define SOCK_DGRAM
Definition: winsock.h:336
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define TDI_EVENT_ERROR
Definition: tdikrnl.h:148

◆ AfdEventDisconnect()

NTSTATUS AfdEventDisconnect ( IN PVOID  TdiEventContext,
IN CONNECTION_CONTEXT  ConnectionContext,
IN LONG  DisconnectDataLength,
IN PVOID  DisconnectData,
IN LONG  DisconnectInformationLength,
IN PVOID  DisconnectInformation,
IN ULONG  DisconnectFlags 
)

Definition at line 23 of file event.c.

31 {
32  AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
33 
34  return STATUS_SUCCESS;
35 }
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define MAX_TRACE
Definition: debug.h:16
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AfdRegisterEventHandlers().

◆ AfdEventError()

NTSTATUS AfdEventError ( IN PVOID  TdiEventContext,
IN NTSTATUS  Status 
)

Definition at line 13 of file event.c.

16 {
17  AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
18 
19  return STATUS_SUCCESS;
20 }
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define MAX_TRACE
Definition: debug.h:16
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AfdRegisterEventHandlers().

◆ AfdEventReceive()

NTSTATUS AfdEventReceive ( IN PVOID  TdiEventContext,
IN CONNECTION_CONTEXT  ConnectionContext,
IN ULONG  ReceiveFlags,
IN ULONG  BytesIndicated,
IN ULONG  BytesAvailable,
OUT ULONG BytesTaken,
IN PVOID  Tsdu,
OUT PIRP IoRequestPacket 
)

Definition at line 38 of file event.c.

47 {
48  PAFDFCB FCB = (PAFDFCB)TdiEventContext;
49  PVOID ReceiveBuffer;
50  PAFD_BUFFER Buffer;
51  KIRQL OldIrql;
52 
53  AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
54 
55  AFD_DbgPrint(MID_TRACE, ("Receiving (%d) bytes on socket\n",
56  BytesAvailable));
57 
58  ReceiveBuffer = ExAllocatePoolWithTag(NonPagedPool,
59  BytesAvailable,
61 
62  if (!ReceiveBuffer)
64 
65  /*Buffer = (PAFD_BUFFER)ExAllocateFromNPagedLookasideList(
66  &BufferLookasideList);*/
68  sizeof(AFD_BUFFER),
70 
71  if (!Buffer) {
72  ExFreePoolWithTag(ReceiveBuffer, TAG_AFD_DATA_BUFFER);
74  }
75 
76  /* Copy the data to a local buffer */
77  RtlCopyMemory(ReceiveBuffer, Tsdu, BytesAvailable);
78 
79  Buffer->Buffer.len = BytesAvailable;
80  Buffer->Buffer.buf = ReceiveBuffer;
81  Buffer->Offset = 0;
82 
83  KeAcquireSpinLock(&FCB->ReceiveQueueLock, &OldIrql);
84 
85  InsertTailList( &FCB->ReceiveQueue, &Buffer->ListEntry );
86 
87  TryToSatisfyRecvRequest( FCB, TRUE );
88 
89  KeReleaseSpinLock(&FCB->ReceiveQueueLock, OldIrql);
90 
91  *BytesTaken = BytesAvailable;
92 
93  AFD_DbgPrint(MAX_TRACE, ("Leaving.\n"));
94 
95  return STATUS_SUCCESS;
96 }
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define MID_TRACE
Definition: debug.h:15
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
Definition: cdstruc.h:908
#define InsertTailList(ListHead, Entry)
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
Definition: bufpool.h:45
#define TAG_AFD_DATA_BUFFER
Definition: afd.h:38
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define MAX_TRACE
Definition: debug.h:16
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AfdRegisterEventHandlers().

◆ AfdEventReceiveDatagramHandler()

NTSTATUS AfdEventReceiveDatagramHandler ( IN PVOID  TdiEventContext,
IN LONG  SourceAddressLength,
IN PVOID  SourceAddress,
IN LONG  OptionsLength,
IN PVOID  Options,
IN ULONG  ReceiveDatagramFlags,
IN ULONG  BytesIndicated,
IN ULONG  BytesAvailable,
OUT ULONG BytesTaken,
IN PVOID  Tsdu,
OUT PIRP IoRequestPacket 
)

Definition at line 130 of file event.c.

142 {
143  PAFDFCB FCB = (PAFDFCB)TdiEventContext;
144  PAFD_READ_REQUEST ReadRequest;
145  PVOID ReceiveBuffer;
146  PAFD_BUFFER Buffer;
149  KIRQL OldIrql;
150  ULONG Count;
152 
153  AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
154 
155  AFD_DbgPrint(MID_TRACE, ("Receiving (%d) bytes from (0x%X).\n",
156  BytesAvailable, *(PULONG)SourceAddress));
157 
158  ReceiveBuffer = ExAllocatePoolWithTag(NonPagedPool,
159  BytesAvailable,
161 
162  if (!ReceiveBuffer)
164 
165  /*Buffer = (PAFD_BUFFER)ExAllocateFromNPagedLookasideList(
166  &BufferLookasideList);*/
168  sizeof(AFD_BUFFER),
170 
171  if (!Buffer) {
172  ExFreePoolWithTag(ReceiveBuffer, TAG_AFD_DATA_BUFFER);
174  }
175 
176  /* Copy the data to a local buffer */
177  RtlCopyMemory(ReceiveBuffer, Tsdu, BytesAvailable);
178 
179  Buffer->Buffer.len = BytesAvailable;
180  Buffer->Buffer.buf = ReceiveBuffer;
181  Buffer->Offset = 0;
182 
183  ExInterlockedInsertTailList(&FCB->ReceiveQueue,
184  &Buffer->ListEntry,
185  &FCB->ReceiveQueueLock);
186 
187  KeAcquireSpinLock(&FCB->ReceiveQueueLock, &OldIrql);
188 
189  if (CompleteIrp = !IsListEmpty(&FCB->ReadRequestQueue)) {
190  AFD_DbgPrint(MAX_TRACE, ("Satisfying read request.\n"));
191 
192  Entry = RemoveHeadList(&FCB->ReceiveQueue);
193  ReadRequest = CONTAINING_RECORD(Entry, AFD_READ_REQUEST, ListEntry);
194 
195  Status = FillWSABuffers(FCB,
196  ReadRequest->RecvFromRequest->Buffers,
197  ReadRequest->RecvFromRequest->BufferCount,
198  &Count,
199  FALSE); /* Packet oriented */
200  ReadRequest->RecvFromReply->NumberOfBytesRecvd = Count;
201  ReadRequest->RecvFromReply->Status = NO_ERROR;
202 
203  ReadRequest->Irp->IoStatus.Information = 0;
204  ReadRequest->Irp->IoStatus.Status = Status;
205  }
206 
207  KeReleaseSpinLock(&FCB->ReceiveQueueLock, OldIrql);
208 
209  if (CompleteIrp) {
210  AFD_DbgPrint(MAX_TRACE, ("Completing IRP at (0x%X).\n", ReadRequest->Irp));
211  IoCompleteRequest(ReadRequest->Irp, IO_NETWORK_INCREMENT);
212  *BytesTaken = BytesAvailable;
213  }
214 
215  AFD_DbgPrint(MAX_TRACE, ("Leaving.\n"));
216 
217  return STATUS_SUCCESS;
218 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define MID_TRACE
Definition: debug.h:15
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _Entry Entry
Definition: kefuncs.h:640
Definition: cdstruc.h:908
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
LONG NTSTATUS
Definition: precomp.h:26
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define NO_ERROR
Definition: dderror.h:5
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
VOID CompleteIrp(IN PIRP Irp, IN NTSTATUS Status, IN ULONG_PTR Information)
Definition: pnp.c:12
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
unsigned char BOOLEAN
#define IoCompleteRequest
Definition: irp.c:1240
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
Definition: bufpool.h:45
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
#define TAG_AFD_DATA_BUFFER
Definition: afd.h:38
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
#define MAX_TRACE
Definition: debug.h:16
unsigned int * PULONG
Definition: retypes.h:1
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS SourceAddress
Definition: iotypes.h:1090
base of all file and directory entries
Definition: entries.h:82

Referenced by AfdRegisterEventHandlers().

◆ AfdRegisterEventHandlers()

NTSTATUS AfdRegisterEventHandlers ( PAFDFCB  FCB)

Definition at line 221 of file event.c.

223 {
225 
226  assert(FCB->TdiAddressObject);
227 
228  /* Report errors for all types of sockets */
229  Status = TdiSetEventHandler(FCB->TdiAddressObject,
232  (PVOID)FCB);
233  if (!NT_SUCCESS(Status)) { return Status; }
234 
235  switch (FCB->SocketType) {
236  case SOCK_STREAM:
237  Status = TdiSetEventHandler(FCB->TdiAddressObject,
240  (PVOID)FCB);
241  if (!NT_SUCCESS(Status)) { return Status; }
242 
243  Status = TdiSetEventHandler(FCB->TdiAddressObject,
246  (PVOID)FCB);
247  if (!NT_SUCCESS(Status)) { return Status; }
248 
249  Status = TdiSetEventHandler(FCB->TdiAddressObject,
252  (PVOID)FCB);
253  if (!NT_SUCCESS(Status)) { return Status; }
254 
255  Status = TdiSetEventHandler(FCB->TdiAddressObject,
258  (PVOID)FCB);
259  if (!NT_SUCCESS(Status)) { return Status; }
260  break;
261 
262  case SOCK_DGRAM:
263  case SOCK_RAW:
264  Status = TdiSetEventHandler(FCB->TdiAddressObject,
267  (PVOID)FCB);
268  if (!NT_SUCCESS(Status)) { return Status; }
269  }
270  return STATUS_SUCCESS;
271 }
Definition: cdstruc.h:908
LONG NTSTATUS
Definition: precomp.h:26
#define TDI_EVENT_RECEIVE_EXPEDITED
Definition: tdikrnl.h:151
#define TDI_EVENT_DISCONNECT
Definition: tdikrnl.h:147
#define assert(x)
Definition: debug.h:53
NTSTATUS AfdEventDisconnect(IN PVOID TdiEventContext, IN CONNECTION_CONTEXT ConnectionContext, IN LONG DisconnectDataLength, IN PVOID DisconnectData, IN LONG DisconnectInformationLength, IN PVOID DisconnectInformation, IN ULONG DisconnectFlags)
Definition: event.c:23
TDI_STATUS ClientEventReceiveExpedited(IN PVOID TdiEventContext, IN CONNECTION_CONTEXT ConnectionContext, IN ULONG ReceiveFlags, IN ULONG BytesIndicated, IN ULONG BytesAvailable, OUT ULONG *BytesTaken, IN PVOID Tsdu, OUT PIRP *IoRequestPacket)
Definition: event.c:99
#define SOCK_RAW
Definition: winsock.h:337
NTSTATUS AfdEventReceive(IN PVOID TdiEventContext, IN CONNECTION_CONTEXT ConnectionContext, IN ULONG ReceiveFlags, IN ULONG BytesIndicated, IN ULONG BytesAvailable, OUT ULONG *BytesTaken, IN PVOID Tsdu, OUT PIRP *IoRequestPacket)
Definition: event.c:38
#define TDI_EVENT_RECEIVE
Definition: tdikrnl.h:149
NTSTATUS TdiSetEventHandler(PFILE_OBJECT FileObject, LONG EventType, PVOID Handler, PVOID Context)
Definition: tdi.c:546
NTSTATUS AfdEventError(IN PVOID TdiEventContext, IN NTSTATUS Status)
Definition: event.c:13
#define TDI_EVENT_CHAINED_RECEIVE
Definition: tdikrnl.h:153
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define TDI_EVENT_RECEIVE_DATAGRAM
Definition: tdikrnl.h:150
Status
Definition: gdiplustypes.h:24
NTSTATUS AfdEventReceiveDatagramHandler(IN PVOID TdiEventContext, IN LONG SourceAddressLength, IN PVOID SourceAddress, IN LONG OptionsLength, IN PVOID Options, IN ULONG ReceiveDatagramFlags, IN ULONG BytesIndicated, IN ULONG BytesAvailable, OUT ULONG *BytesTaken, IN PVOID Tsdu, OUT PIRP *IoRequestPacket)
Definition: event.c:130
NTSTATUS ClientEventChainedReceive(IN PVOID TdiEventContext, IN CONNECTION_CONTEXT ConnectionContext, IN ULONG ReceiveFlags, IN ULONG ReceiveLength, IN ULONG StartingOffset, IN PMDL Tsdu, IN PVOID TsduDescriptor)
Definition: event.c:115
#define SOCK_STREAM
Definition: tcpip.h:118
#define SOCK_DGRAM
Definition: winsock.h:336
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define TDI_EVENT_ERROR
Definition: tdikrnl.h:148

◆ ClientEventChainedReceive()

NTSTATUS ClientEventChainedReceive ( IN PVOID  TdiEventContext,
IN CONNECTION_CONTEXT  ConnectionContext,
IN ULONG  ReceiveFlags,
IN ULONG  ReceiveLength,
IN ULONG  StartingOffset,
IN PMDL  Tsdu,
IN PVOID  TsduDescriptor 
)

Definition at line 115 of file event.c.

123 {
124  AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
125 
126  return STATUS_SUCCESS;
127 }
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define MAX_TRACE
Definition: debug.h:16
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AfdRegisterEventHandlers().

◆ ClientEventReceiveExpedited()

TDI_STATUS ClientEventReceiveExpedited ( IN PVOID  TdiEventContext,
IN CONNECTION_CONTEXT  ConnectionContext,
IN ULONG  ReceiveFlags,
IN ULONG  BytesIndicated,
IN ULONG  BytesAvailable,
OUT ULONG BytesTaken,
IN PVOID  Tsdu,
OUT PIRP IoRequestPacket 
)

Definition at line 99 of file event.c.

108 {
109  AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
110 
111  return STATUS_SUCCESS;
112 }
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define MAX_TRACE
Definition: debug.h:16
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AfdRegisterEventHandlers().