ReactOS 0.4.15-dev-8227-g32d615f
event.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Ancillary Function Driver
4 * FILE: afd/event.c
5 * PURPOSE: TDI event handlers
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * REVISIONS:
8 * CSH 01/09-2000 Created
9 */
10
11#include <afd.h>
12
14 IN PVOID TdiEventContext,
16{
17 AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
18
19 return STATUS_SUCCESS;
20}
21
22
24 IN PVOID TdiEventContext,
25 IN CONNECTION_CONTEXT ConnectionContext,
26 IN LONG DisconnectDataLength,
27 IN PVOID DisconnectData,
28 IN LONG DisconnectInformationLength,
29 IN PVOID DisconnectInformation,
30 IN ULONG DisconnectFlags)
31{
32 AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
33
34 return STATUS_SUCCESS;
35}
36
37
39 IN PVOID TdiEventContext,
40 IN CONNECTION_CONTEXT ConnectionContext,
41 IN ULONG ReceiveFlags,
42 IN ULONG BytesIndicated,
43 IN ULONG BytesAvailable,
44 OUT ULONG *BytesTaken,
45 IN PVOID Tsdu,
46 OUT PIRP *IoRequestPacket)
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}
97
98
100 IN PVOID TdiEventContext,
101 IN CONNECTION_CONTEXT ConnectionContext,
102 IN ULONG ReceiveFlags,
103 IN ULONG BytesIndicated,
104 IN ULONG BytesAvailable,
105 OUT ULONG *BytesTaken,
106 IN PVOID Tsdu,
107 OUT PIRP *IoRequestPacket)
108{
109 AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
110
111 return STATUS_SUCCESS;
112}
113
114
116 IN PVOID TdiEventContext,
117 IN CONNECTION_CONTEXT ConnectionContext,
118 IN ULONG ReceiveFlags,
119 IN ULONG ReceiveLength,
121 IN PMDL Tsdu,
122 IN PVOID TsduDescriptor)
123{
124 AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
125
126 return STATUS_SUCCESS;
127}
128
129
131 IN PVOID TdiEventContext,
132 IN LONG SourceAddressLength,
134 IN LONG OptionsLength,
136 IN ULONG ReceiveDatagramFlags,
137 IN ULONG BytesIndicated,
138 IN ULONG BytesAvailable,
139 OUT ULONG *BytesTaken,
140 IN PVOID Tsdu,
141 OUT PIRP *IoRequestPacket)
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}
219
220
222 PAFDFCB FCB)
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}
272
273
275 PAFDFCB FCB)
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}
322
323/* EOF */
unsigned char BOOLEAN
#define TAG_AFD_DATA_BUFFER
Definition: afd.h:38
LONG NTSTATUS
Definition: precomp.h:26
#define MID_TRACE
Definition: debug.h:15
#define MAX_TRACE
Definition: debug.h:16
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:291
Definition: bufpool.h:45
#define NO_ERROR
Definition: dderror.h:5
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#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 AfdDeregisterEventHandlers(PAFDFCB FCB)
Definition: event.c:274
NTSTATUS AfdEventError(IN PVOID TdiEventContext, IN NTSTATUS Status)
Definition: event.c:13
NTSTATUS AfdRegisterEventHandlers(PAFDFCB FCB)
Definition: event.c:221
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
NTSTATUS TdiSetEventHandler(PFILE_OBJECT FileObject, LONG EventType, PVOID Handler, PVOID Context)
Definition: tdi.c:546
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define SOCK_STREAM
Definition: tcpip.h:118
#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 InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
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 RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
#define NonPagedPool
Definition: env_spec_w32.h:307
Status
Definition: gdiplustypes.h:25
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
int Count
Definition: noreturn.cpp:7
#define IoCompleteRequest
Definition: irp.c:1240
long LONG
Definition: pedump.c:60
#define STATUS_SUCCESS
Definition: shellext.h:65
base of all file and directory entries
Definition: entries.h:83
Definition: cdstruc.h:902
Definition: typedefs.h:120
LONG TDI_STATUS
Definition: tdi.h:36
#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
uint32_t * PULONG
Definition: typedefs.h:59
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3534
#define SOCK_RAW
Definition: winsock.h:337
#define SOCK_DGRAM
Definition: winsock.h:336
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS SourceAddress
Definition: iotypes.h:1127
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778