ReactOS  0.4.15-dev-3181-g4acf100
event.c File Reference
#include "precomp.h"
#include "lwip/err.h"
#include "lwip/sys.h"
#include "lwip/pbuf.h"
#include "lwip/tcp.h"
#include "lwip/api.h"
#include "rosip.h"
Include dependency graph for event.c:

Go to the source code of this file.

Functions

static VOID BucketCompletionWorker (PVOID Context)
 
VOID CompleteBucket (PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
 
VOID FlushReceiveQueue (PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
 
VOID FlushSendQueue (PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
 
VOID FlushShutdownQueue (PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
 
VOID FlushConnectQueue (PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
 
VOID FlushListenQueue (PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
 
VOID FlushAllQueues (PCONNECTION_ENDPOINT Connection, NTSTATUS Status)
 
VOID TCPFinEventHandler (void *arg, const err_t err)
 
VOID TCPAcceptEventHandler (void *arg, PTCP_PCB newpcb)
 
VOID TCPSendEventHandler (void *arg, const u16_t space)
 
VOID TCPRecvEventHandler (void *arg)
 
VOID TCPConnectEventHandler (void *arg, const err_t err)
 

Variables

NPAGED_LOOKASIDE_LIST TdiBucketLookasideList
 

Function Documentation

◆ BucketCompletionWorker()

static VOID BucketCompletionWorker ( PVOID  Context)
static

Definition at line 23 of file event.c.

24 {
27 
29 
30  Complete(Bucket->Request.RequestContext, Bucket->Status, Bucket->Information);
31 
33 
34  ExFreeToNPagedLookasideList(&TdiBucketLookasideList, Bucket);
35 }
PVOID RequestContext
Definition: tdi.h:55
#define DereferenceObject(Object)
Definition: titypes.h:24
pRequest Complete(RequestStatus)
PVOID RequestNotifyObject
Definition: tdi.h:54
VOID(* PTCP_COMPLETION_ROUTINE)(PVOID Context, NTSTATUS Status, ULONG Count)
Definition: tcp.h:11
NPAGED_LOOKASIDE_LIST TdiBucketLookasideList
Definition: tcp.c:26
struct _CONNECTION_ENDPOINT * AssociatedEndpoint
Definition: titypes.h:231
NTSTATUS Status
Definition: titypes.h:233
struct _TDI_BUCKET * PTDI_BUCKET
TDI_REQUEST Request
Definition: titypes.h:232
ULONG Information
Definition: titypes.h:234

Referenced by CompleteBucket().

◆ CompleteBucket()

VOID CompleteBucket ( PCONNECTION_ENDPOINT  Connection,
PTDI_BUCKET  Bucket,
const BOOLEAN  Synchronous 
)

Definition at line 38 of file event.c.

39 {
40  ReferenceObject(Connection);
41  Bucket->AssociatedEndpoint = Connection;
42  if (Synchronous)
43  {
44  BucketCompletionWorker(Bucket);
45  }
46  else
47  {
49  }
50 }
static VOID BucketCompletionWorker(PVOID Context)
Definition: event.c:23
BOOLEAN ChewCreate(VOID(*Worker)(PVOID), PVOID WorkerContext)
Definition: workqueue.c:65
#define ReferenceObject(Object)
Definition: titypes.h:14
struct _CONNECTION_ENDPOINT * AssociatedEndpoint
Definition: titypes.h:231

Referenced by DisconnectWorker(), FlushConnectQueue(), FlushListenQueue(), FlushReceiveQueue(), FlushSendQueue(), FlushShutdownQueue(), TCPAcceptEventHandler(), TCPConnectEventHandler(), TCPRecvEventHandler(), and TCPSendEventHandler().

◆ FlushAllQueues()

VOID FlushAllQueues ( PCONNECTION_ENDPOINT  Connection,
NTSTATUS  Status 
)

Definition at line 157 of file event.c.

158 {
159  // flush receive queue
160  FlushReceiveQueue(Connection, Status);
161 
162  /* We completed the reads successfully but we need to return failure now */
163  if (Status == STATUS_SUCCESS)
164  {
166  }
167 
168  // flush listen queue
169  FlushListenQueue(Connection, Status);
170 
171  // flush send queue
172  FlushSendQueue(Connection, Status);
173 
174  // flush connect queue
175  FlushConnectQueue(Connection, Status);
176 
177  // flush shutdown queue
178  FlushShutdownQueue(Connection, Status);
179 }
VOID FlushListenQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:136
Status
Definition: gdiplustypes.h:24
VOID FlushReceiveQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:53
VOID FlushShutdownQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:95
VOID FlushConnectQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:116
VOID FlushSendQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:74
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:532

Referenced by TCPClose(), and TCPFinEventHandler().

◆ FlushConnectQueue()

VOID FlushConnectQueue ( PCONNECTION_ENDPOINT  Connection,
const NTSTATUS  Status 
)

Definition at line 116 of file event.c.

117 {
118  PTDI_BUCKET Bucket;
120 
121  ASSERT_TCPIP_OBJECT_LOCKED(Connection);
122 
123  while (!IsListEmpty(&Connection->ConnectRequest))
124  {
125  Entry = RemoveHeadList(&Connection->ConnectRequest);
126  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
127 
128  Bucket->Status = Status;
129  Bucket->Information = 0;
130 
131  CompleteBucket(Connection, Bucket, FALSE);
132  }
133 }
#define ASSERT_TCPIP_OBJECT_LOCKED(Object)
Definition: titypes.h:51
struct _Entry Entry
Definition: kefuncs.h:627
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define FALSE
Definition: types.h:117
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
Status
Definition: gdiplustypes.h:24
Definition: typedefs.h:119
LIST_ENTRY ConnectRequest
Definition: titypes.h:250
NTSTATUS Status
Definition: titypes.h:233
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:234

Referenced by FlushAllQueues().

◆ FlushListenQueue()

VOID FlushListenQueue ( PCONNECTION_ENDPOINT  Connection,
const NTSTATUS  Status 
)

Definition at line 136 of file event.c.

137 {
138  PTDI_BUCKET Bucket;
140 
141  ASSERT_TCPIP_OBJECT_LOCKED(Connection);
142 
143  while (!IsListEmpty(&Connection->ListenRequest))
144  {
145  Entry = RemoveHeadList(&Connection->ListenRequest);
146  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
147 
148  Bucket->Status = Status;
149  Bucket->Information = 0;
150 
152  CompleteBucket(Connection, Bucket, FALSE);
153  }
154 }
#define ASSERT_TCPIP_OBJECT_LOCKED(Object)
Definition: titypes.h:51
struct _Entry Entry
Definition: kefuncs.h:627
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define DereferenceObject(Object)
Definition: titypes.h:24
#define FALSE
Definition: types.h:117
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
Status
Definition: gdiplustypes.h:24
Definition: typedefs.h:119
struct _CONNECTION_ENDPOINT * AssociatedEndpoint
Definition: titypes.h:231
LIST_ENTRY ListenRequest
Definition: titypes.h:251
NTSTATUS Status
Definition: titypes.h:233
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:234

Referenced by FlushAllQueues().

◆ FlushReceiveQueue()

VOID FlushReceiveQueue ( PCONNECTION_ENDPOINT  Connection,
const NTSTATUS  Status 
)

Definition at line 53 of file event.c.

54 {
55  PTDI_BUCKET Bucket;
57 
58  ASSERT_TCPIP_OBJECT_LOCKED(Connection);
59 
60  while (!IsListEmpty(&Connection->ReceiveRequest))
61  {
62  Entry = RemoveHeadList(&Connection->ReceiveRequest);
63 
65 
66  Bucket->Information = 0;
67  Bucket->Status = Status;
68 
69  CompleteBucket(Connection, Bucket, FALSE);
70  }
71 }
#define ASSERT_TCPIP_OBJECT_LOCKED(Object)
Definition: titypes.h:51
struct _Entry Entry
Definition: kefuncs.h:627
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define FALSE
Definition: types.h:117
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
Status
Definition: gdiplustypes.h:24
LIST_ENTRY ReceiveRequest
Definition: titypes.h:252
Definition: typedefs.h:119
NTSTATUS Status
Definition: titypes.h:233
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:234

Referenced by FlushAllQueues(), and TCPDisconnect().

◆ FlushSendQueue()

VOID FlushSendQueue ( PCONNECTION_ENDPOINT  Connection,
const NTSTATUS  Status 
)

Definition at line 74 of file event.c.

75 {
76  PTDI_BUCKET Bucket;
78 
79  ASSERT_TCPIP_OBJECT_LOCKED(Connection);
80 
81  while (!IsListEmpty(&Connection->SendRequest))
82  {
83  Entry = RemoveHeadList(&Connection->SendRequest);
84 
86 
87  Bucket->Information = 0;
88  Bucket->Status = Status;
89 
90  CompleteBucket(Connection, Bucket, FALSE);
91  }
92 }
#define ASSERT_TCPIP_OBJECT_LOCKED(Object)
Definition: titypes.h:51
struct _Entry Entry
Definition: kefuncs.h:627
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define FALSE
Definition: types.h:117
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
Status
Definition: gdiplustypes.h:24
Definition: typedefs.h:119
LIST_ENTRY SendRequest
Definition: titypes.h:253
NTSTATUS Status
Definition: titypes.h:233
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:234

Referenced by FlushAllQueues(), and TCPDisconnect().

◆ FlushShutdownQueue()

VOID FlushShutdownQueue ( PCONNECTION_ENDPOINT  Connection,
const NTSTATUS  Status 
)

Definition at line 95 of file event.c.

96 {
97  PTDI_BUCKET Bucket;
99 
100  ASSERT_TCPIP_OBJECT_LOCKED(Connection);
101 
102  while (!IsListEmpty(&Connection->ShutdownRequest))
103  {
104  Entry = RemoveHeadList(&Connection->ShutdownRequest);
105 
107 
108  Bucket->Information = 0;
109  Bucket->Status = Status;
110 
111  CompleteBucket(Connection, Bucket, FALSE);
112  }
113 }
#define ASSERT_TCPIP_OBJECT_LOCKED(Object)
Definition: titypes.h:51
struct _Entry Entry
Definition: kefuncs.h:627
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define FALSE
Definition: types.h:117
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
Status
Definition: gdiplustypes.h:24
LIST_ENTRY ShutdownRequest
Definition: titypes.h:254
Definition: typedefs.h:119
NTSTATUS Status
Definition: titypes.h:233
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:234

Referenced by FlushAllQueues(), TCPDisconnect(), and TCPSendEventHandler().

◆ TCPAcceptEventHandler()

VOID TCPAcceptEventHandler ( void arg,
PTCP_PCB  newpcb 
)

Definition at line 231 of file event.c.

232 {
234  PTDI_BUCKET Bucket;
236  PIRP Irp;
238 
239  LockObject(Connection);
240 
241  while (!IsListEmpty(&Connection->ListenRequest))
242  {
244 
245  Entry = RemoveHeadList(&Connection->ListenRequest);
246 
247  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
248 
249  Irp = Bucket->Request.RequestContext;
251 
252  TI_DbgPrint(DEBUG_TCP,("[IP, TCPAcceptEventHandler] Getting the socket\n"));
253 
254  Status = TCPCheckPeerForAccept(newpcb,
256 
257  TI_DbgPrint(DEBUG_TCP,("Socket: Status: %x\n", Status));
258 
259  Bucket->Status = Status;
260  Bucket->Information = 0;
261 
262  if (Status == STATUS_SUCCESS)
263  {
265 
266  /* sanity assert...this should never be in anything else but a CLOSED state */
267  ASSERT( ((PTCP_PCB)Bucket->AssociatedEndpoint->SocketContext)->state == CLOSED );
268 
269  /* free socket context created in FileOpenConnection, as we're using a new one */
271 
272  /* free previously created socket context (we don't use it, we use newpcb) */
273  Bucket->AssociatedEndpoint->SocketContext = newpcb;
274 
276 
277  LibTCPAccept(newpcb, (PTCP_PCB)Connection->SocketContext, Bucket->AssociatedEndpoint);
278  }
279 
281 
282  CompleteBucket(Connection, Bucket, FALSE);
283 
284  if (Status == STATUS_SUCCESS)
285  {
286  break;
287  }
288  }
289 
290  UnlockObject(Connection);
291 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
PVOID RequestContext
Definition: tdi.h:55
struct _Entry Entry
Definition: kefuncs.h:627
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
struct _CONNECTION_ENDPOINT * PCONNECTION_ENDPOINT
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
NTSTATUS TCPCheckPeerForAccept(PVOID Context, PTDI_REQUEST_KERNEL Request)
Definition: accept.c:17
#define DEBUG_TCP
Definition: debug.h:28
#define DereferenceObject(Object)
Definition: titypes.h:24
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
err_t LibTCPClose(PCONNECTION_ENDPOINT Connection, const int safe, const int callback)
Definition: rostcp.c:801
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
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
struct tcp_pcb * PTCP_PCB
Definition: rosip.h:15
Definition: typedefs.h:119
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
#define UnlockObject(Object)
Definition: titypes.h:44
struct _CONNECTION_ENDPOINT * AssociatedEndpoint
Definition: titypes.h:231
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
LIST_ENTRY ListenRequest
Definition: titypes.h:251
NTSTATUS Status
Definition: titypes.h:233
void LibTCPAccept(PTCP_PCB pcb, struct tcp_pcb *listen_pcb, void *arg)
Definition: rostcp.c:833
TDI_REQUEST Request
Definition: titypes.h:232
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:234
#define LockObject(Object)
Definition: titypes.h:34

Referenced by InternalAcceptEventHandler().

◆ TCPConnectEventHandler()

VOID TCPConnectEventHandler ( void arg,
const err_t  err 
)

Definition at line 420 of file event.c.

421 {
423  PTDI_BUCKET Bucket;
425 
426  LockObject(Connection);
427 
428  while (!IsListEmpty(&Connection->ConnectRequest))
429  {
430  Entry = RemoveHeadList(&Connection->ConnectRequest);
431 
432  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
433 
434  Bucket->Status = TCPTranslateError(err);
435  Bucket->Information = 0;
436 
437  CompleteBucket(Connection, Bucket, FALSE);
438  }
439 
440  UnlockObject(Connection);
441 }
struct _Entry Entry
Definition: kefuncs.h:627
struct _CONNECTION_ENDPOINT * PCONNECTION_ENDPOINT
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define FALSE
Definition: types.h:117
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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: typedefs.h:119
#define err(...)
NTSTATUS TCPTranslateError(const INT8 err)
Definition: tcp.c:267
#define UnlockObject(Object)
Definition: titypes.h:44
LIST_ENTRY ConnectRequest
Definition: titypes.h:250
NTSTATUS Status
Definition: titypes.h:233
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:234
#define LockObject(Object)
Definition: titypes.h:34

Referenced by InternalConnectEventHandler().

◆ TCPFinEventHandler()

VOID TCPFinEventHandler ( void arg,
const err_t  err 
)

Definition at line 182 of file event.c.

183 {
184  PCONNECTION_ENDPOINT Connection = (PCONNECTION_ENDPOINT)arg, LastConnection;
186 
187  ASSERT(Connection->SocketContext == NULL);
188  ASSERT(Connection->AddressFile);
189  ASSERT(err != ERR_OK);
190 
191  LockObject(Connection);
192 
193  /* Complete all outstanding requests now */
194  FlushAllQueues(Connection, Status);
195 
196  LockObject(Connection->AddressFile);
197 
198  /* Unlink this connection from the address file */
199  if (Connection->AddressFile->Connection == Connection)
200  {
201  Connection->AddressFile->Connection = Connection->Next;
202  DereferenceObject(Connection);
203  }
204  else if (Connection->AddressFile->Listener == Connection)
205  {
206  Connection->AddressFile->Listener = NULL;
207  DereferenceObject(Connection);
208  }
209  else
210  {
211  LastConnection = Connection->AddressFile->Connection;
212  while (LastConnection->Next != Connection && LastConnection->Next != NULL)
213  LastConnection = LastConnection->Next;
214  if (LastConnection->Next == Connection)
215  {
216  LastConnection->Next = Connection->Next;
217  DereferenceObject(Connection);
218  }
219  }
220 
221  UnlockObject(Connection->AddressFile);
222 
223  /* Remove the address file from this connection */
224  DereferenceObject(Connection->AddressFile);
225  Connection->AddressFile = NULL;
226 
227  UnlockObject(Connection);
228 }
LONG NTSTATUS
Definition: precomp.h:26
struct _CONNECTION_ENDPOINT * PCONNECTION_ENDPOINT
#define DereferenceObject(Object)
Definition: titypes.h:24
struct _CONNECTION_ENDPOINT * Next
Definition: titypes.h:269
PADDRESS_FILE AddressFile
Definition: titypes.h:247
#define ERR_OK
Definition: err.h:52
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)
#define err(...)
struct _CONNECTION_ENDPOINT * Listener
Definition: titypes.h:133
VOID FlushAllQueues(PCONNECTION_ENDPOINT Connection, NTSTATUS Status)
Definition: event.c:157
NTSTATUS TCPTranslateError(const INT8 err)
Definition: tcp.c:267
#define UnlockObject(Object)
Definition: titypes.h:44
#define NULL
Definition: types.h:112
struct _CONNECTION_ENDPOINT * Connection
Definition: titypes.h:131
#define LockObject(Object)
Definition: titypes.h:34

Referenced by InternalErrorEventHandler(), InternalRecvEventHandler(), LibTCPCloseCallback(), and LibTCPShutdownCallback().

◆ TCPRecvEventHandler()

VOID TCPRecvEventHandler ( void arg)

Definition at line 380 of file event.c.

381 {
383  PTDI_BUCKET Bucket;
385  PIRP Irp;
386  PMDL Mdl;
387  UINT Received;
388  UINT RecvLen;
389  PUCHAR RecvBuffer;
391 
392  LockObject(Connection);
393 
394  while(!IsListEmpty(&Connection->ReceiveRequest))
395  {
396  Entry = RemoveHeadList(&Connection->ReceiveRequest);
397  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
398 
399  Irp = Bucket->Request.RequestContext;
400  Mdl = Irp->MdlAddress;
401 
402  NdisQueryBuffer( Mdl, &RecvBuffer, &RecvLen );
403 
404  Status = LibTCPGetDataFromConnectionQueue(Connection, RecvBuffer, RecvLen, &Received);
405  if (Status == STATUS_PENDING)
406  {
407  InsertHeadList(&Connection->ReceiveRequest, &Bucket->Entry);
408  break;
409  }
410 
411  Bucket->Status = Status;
412  Bucket->Information = Received;
413 
414  CompleteBucket(Connection, Bucket, FALSE);
415  }
416  UnlockObject(Connection);
417 }
PVOID RequestContext
Definition: tdi.h:55
struct _Entry Entry
Definition: kefuncs.h:627
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
struct _CONNECTION_ENDPOINT * PCONNECTION_ENDPOINT
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
Status
Definition: gdiplustypes.h:24
#define STATUS_PENDING
Definition: ntstatus.h:82
LIST_ENTRY ReceiveRequest
Definition: titypes.h:252
Definition: typedefs.h:119
LIST_ENTRY Entry
Definition: titypes.h:230
#define UnlockObject(Object)
Definition: titypes.h:44
NTSTATUS LibTCPGetDataFromConnectionQueue(PCONNECTION_ENDPOINT Connection, PUCHAR RecvBuffer, UINT RecvLen, UINT *Received)
Definition: rostcp.c:103
unsigned int UINT
Definition: ndis.h:50
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:955
NTSTATUS Status
Definition: titypes.h:233
TDI_REQUEST Request
Definition: titypes.h:232
UINT Received
Definition: arping.c:40
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:234
#define LockObject(Object)
Definition: titypes.h:34

Referenced by InternalErrorEventHandler(), and InternalRecvEventHandler().

◆ TCPSendEventHandler()

VOID TCPSendEventHandler ( void arg,
const u16_t  space 
)

Definition at line 294 of file event.c.

295 {
297  PTDI_BUCKET Bucket;
299  PIRP Irp;
301  PMDL Mdl;
302  ULONG BytesSent;
303 
304  ReferenceObject(Connection);
305  LockObject(Connection);
306 
307  while (!IsListEmpty(&Connection->SendRequest))
308  {
309  UINT SendLen = 0;
310  PVOID SendBuffer = 0;
311 
312  Entry = RemoveHeadList(&Connection->SendRequest);
313 
314  UnlockObject(Connection);
315 
316  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
317 
318  Irp = Bucket->Request.RequestContext;
319  Mdl = Irp->MdlAddress;
320 
322  ("Getting the user buffer from %x\n", Mdl));
323 
324  NdisQueryBuffer( Mdl, &SendBuffer, &SendLen );
325 
327  ("Writing %d bytes to %x\n", SendLen, SendBuffer));
328 
329  TI_DbgPrint(DEBUG_TCP, ("Connection: %x\n", Connection));
331  (DEBUG_TCP,
332  ("Connection->SocketContext: %x\n",
333  Connection->SocketContext));
334 
335  Status = TCPTranslateError(LibTCPSend(Connection,
336  SendBuffer,
337  SendLen, &BytesSent, TRUE));
338 
339  TI_DbgPrint(DEBUG_TCP,("TCP Bytes: %d\n", BytesSent));
340 
341  if( Status == STATUS_PENDING )
342  {
343  LockObject(Connection);
344  InsertHeadList(&Connection->SendRequest, &Bucket->Entry);
345  break;
346  }
347  else
348  {
350  ("Completing Send request: %x %x\n",
351  Bucket->Request, Status));
352 
353  Bucket->Status = Status;
354  Bucket->Information = (Bucket->Status == STATUS_SUCCESS) ? BytesSent : 0;
355 
356  CompleteBucket(Connection, Bucket, FALSE);
357  }
358 
359  LockObject(Connection);
360  }
361 
362  // If we completed all outstanding send requests then finish all pending shutdown requests,
363  // cancel the timer and dereference the connection
364  if (IsListEmpty(&Connection->SendRequest))
365  {
366  FlushShutdownQueue(Connection, STATUS_SUCCESS);
367 
368  if (KeCancelTimer(&Connection->DisconnectTimer))
369  {
370  DereferenceObject(Connection);
371  }
372  }
373 
374  UnlockObject(Connection);
375 
376  DereferenceObject(Connection);
377 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
PVOID RequestContext
Definition: tdi.h:55
struct _Entry Entry
Definition: kefuncs.h:627
#define TRUE
Definition: types.h:120
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
err_t LibTCPSend(PCONNECTION_ENDPOINT Connection, void *const dataptr, const u16_t len, u32_t *sent, const int safe)
Definition: rostcp.c:560
LONG NTSTATUS
Definition: precomp.h:26
struct _CONNECTION_ENDPOINT * PCONNECTION_ENDPOINT
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define DEBUG_TCP
Definition: debug.h:28
#define DereferenceObject(Object)
Definition: titypes.h:24
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
Status
Definition: gdiplustypes.h:24
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID FlushShutdownQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:95
KTIMER DisconnectTimer
Definition: titypes.h:259
#define ReferenceObject(Object)
Definition: titypes.h:14
Definition: typedefs.h:119
LIST_ENTRY Entry
Definition: titypes.h:230
NTSTATUS TCPTranslateError(const INT8 err)
Definition: tcp.c:267
#define UnlockObject(Object)
Definition: titypes.h:44
unsigned int UINT
Definition: ndis.h:50
LIST_ENTRY SendRequest
Definition: titypes.h:253
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:955
NTSTATUS Status
Definition: titypes.h:233
unsigned int ULONG
Definition: retypes.h:1
TDI_REQUEST Request
Definition: titypes.h:232
#define STATUS_SUCCESS
Definition: shellext.h:65
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:234
#define LockObject(Object)
Definition: titypes.h:34

Referenced by InternalSendEventHandler().

Variable Documentation

◆ TdiBucketLookasideList