ReactOS 0.4.15-dev-7953-g1f49173
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}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS TdiSetEventHandler(PFILE_OBJECT FileObject, LONG EventType, PVOID Handler, PVOID Context)
Definition: tdi.c:546
#define SOCK_STREAM
Definition: tcpip.h:118
Status
Definition: gdiplustypes.h:25
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: cdstruc.h:902
#define TDI_EVENT_ERROR
Definition: tdikrnl.h:148
#define TDI_EVENT_RECEIVE_EXPEDITED
Definition: tdikrnl.h:151
#define TDI_EVENT_CHAINED_RECEIVE
Definition: tdikrnl.h:153
#define TDI_EVENT_DISCONNECT
Definition: tdikrnl.h:147
#define TDI_EVENT_RECEIVE
Definition: tdikrnl.h:149
#define TDI_EVENT_RECEIVE_DATAGRAM
Definition: tdikrnl.h:150
#define SOCK_RAW
Definition: winsock.h:337
#define SOCK_DGRAM
Definition: winsock.h:336

◆ 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 MAX_TRACE
Definition: debug.h:16
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60

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}

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;
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) {
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 TAG_AFD_DATA_BUFFER
Definition: afd.h:38
#define MID_TRACE
Definition: debug.h:15
Definition: bufpool.h:45
#define TRUE
Definition: types.h:120
#define InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

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;
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) {
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}
unsigned char BOOLEAN
#define NO_ERROR
Definition: dderror.h:5
#define FALSE
Definition: types.h:117
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
VOID CompleteIrp(IN PIRP Irp, IN NTSTATUS Status, IN ULONG_PTR Information)
Definition: pnp.c:12
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
int Count
Definition: noreturn.cpp:7
#define IoCompleteRequest
Definition: irp.c:1240
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120
uint32_t * PULONG
Definition: typedefs.h:59
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS SourceAddress
Definition: iotypes.h:1127

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}
#define assert(x)
Definition: debug.h:53
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
NTSTATUS AfdEventError(IN PVOID TdiEventContext, IN NTSTATUS Status)
Definition: event.c:13
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
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 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
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

◆ 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}

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}

Referenced by AfdRegisterEventHandlers().