ReactOS 0.4.15-dev-7907-g95bf896
lwip_glue.h File Reference
#include <lwip/tcp.h>
#include <lwip/pbuf.h>
#include <lwip/ip_addr.h>
#include <tcpip.h>
Include dependency graph for lwip_glue.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _QUEUE_ENTRY
 
struct  lwip_callback_msg
 

Macros

#define LWIP_TAG   'PIwl'
 
#define LWIP_MESSAGE_TAG   'sMwl'
 
#define LWIP_QUEUE_TAG   'uQwl'
 

Typedefs

typedef struct tcp_pcb * PTCP_PCB
 
typedef struct _QUEUE_ENTRY QUEUE_ENTRY
 
typedef struct _QUEUE_ENTRYPQUEUE_ENTRY
 

Functions

NTSTATUS LibTCPGetDataFromConnectionQueue (PCONNECTION_ENDPOINT Connection, PUCHAR RecvBuffer, UINT RecvLen, UINT *Received)
 
void TCPConnectEventHandler (void *arg, const err_t err)
 
void TCPAcceptEventHandler (void *arg, PTCP_PCB newpcb)
 
void TCPSendEventHandler (void *arg, const u16_t space)
 
void TCPFinEventHandler (void *arg, const err_t err)
 
void TCPRecvEventHandler (void *arg)
 
PTCP_PCB LibTCPSocket (void *arg)
 
VOID LibTCPFreeSocket (PTCP_PCB pcb)
 
err_t LibTCPBind (PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t port)
 
PTCP_PCB LibTCPListen (PCONNECTION_ENDPOINT Connection, const u8_t backlog)
 
err_t LibTCPSend (PCONNECTION_ENDPOINT Connection, void *const dataptr, const u16_t len, u32_t *sent, const int safe)
 
err_t LibTCPConnect (PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t port)
 
err_t LibTCPShutdown (PCONNECTION_ENDPOINT Connection, const int shut_rx, const int shut_tx)
 
err_t LibTCPClose (PCONNECTION_ENDPOINT Connection, const int safe, const int callback)
 
err_t LibTCPGetPeerName (PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
 
err_t LibTCPGetHostName (PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
 
void LibTCPAccept (PTCP_PCB pcb, struct tcp_pcb *listen_pcb, void *arg)
 
void LibTCPSetNoDelay (PTCP_PCB pcb, BOOLEAN Set)
 
void LibTCPGetSocketStatus (PTCP_PCB pcb, PULONG State)
 
void LibIPInsertPacket (void *ifarg, const void *const data, const u32_t size)
 
void LibIPInitialize (void)
 
void LibIPShutdown (void)
 

Macro Definition Documentation

◆ LWIP_MESSAGE_TAG

#define LWIP_MESSAGE_TAG   'sMwl'

Definition at line 11 of file lwip_glue.h.

◆ LWIP_QUEUE_TAG

#define LWIP_QUEUE_TAG   'uQwl'

Definition at line 12 of file lwip_glue.h.

◆ LWIP_TAG

#define LWIP_TAG   'PIwl'

Definition at line 10 of file lwip_glue.h.

Typedef Documentation

◆ PQUEUE_ENTRY

◆ PTCP_PCB

typedef struct tcp_pcb* PTCP_PCB

Definition at line 15 of file lwip_glue.h.

◆ QUEUE_ENTRY

Function Documentation

◆ LibIPInitialize()

void LibIPInitialize ( void  )

Definition at line 33 of file ip.c.

34{
35 /* This completes asynchronously */
37}
#define NULL
Definition: types.h:112
void tcpip_init(tcpip_init_done_fn initfunc, void *arg)
Definition: tcpip.c:458

Referenced by TCPStartup().

◆ LibIPInsertPacket()

void LibIPInsertPacket ( void ifarg,
const void *const  data,
const u32_t  size 
)

Definition at line 10 of file ip.c.

13{
14 struct pbuf *p;
15
16 ASSERT(ifarg);
17 ASSERT(data);
18 ASSERT(size > 0);
19
21 if (p)
22 {
23 ASSERT(p->tot_len == p->len);
24 ASSERT(p->len == size);
25
26 RtlCopyMemory(p->payload, data, p->len);
27
28 ((PNETIF)ifarg)->input(p, (PNETIF)ifarg);
29 }
30}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
GLfloat GLfloat p
Definition: glext.h:8902
struct netif * PNETIF
Definition: ip.c:4
#define ASSERT(a)
Definition: mode.c:44
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
Definition: pbuf.c:207
@ PBUF_RAM
Definition: pbuf.h:58
@ PBUF_RAW
Definition: pbuf.h:54
Definition: netif.h:136
Definition: pbuf.h:79
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

Referenced by TCPReceive().

◆ LibIPShutdown()

void LibIPShutdown ( void  )

Definition at line 40 of file ip.c.

41{
42 /* This is synchronous */
44}
void sys_shutdown(void)
Definition: sys_arch.c:332

Referenced by TCPShutdown().

◆ LibTCPAccept()

void LibTCPAccept ( PTCP_PCB  pcb,
struct tcp_pcb *  listen_pcb,
void arg 
)

Definition at line 830 of file tcp.c.

831{
832 ASSERT(arg);
833
834 tcp_arg(pcb, NULL);
836 tcp_sent(pcb, InternalSendEventHandler);
837 tcp_err(pcb, InternalErrorEventHandler);
838 tcp_arg(pcb, arg);
839
840 tcp_accepted(listen_pcb);
841}
STREAM tcp_recv(STREAM s, uint32 length)
Definition: tcp.c:344
static err_t InternalRecvEventHandler(void *arg, PTCP_PCB pcb, struct pbuf *p, const err_t err)
Definition: tcp.c:213
static err_t InternalSendEventHandler(void *arg, PTCP_PCB pcb, const u16_t space)
Definition: tcp.c:201
static void InternalErrorEventHandler(void *arg, const err_t err)
Definition: tcp.c:297

Referenced by TCPAcceptEventHandler().

◆ LibTCPBind()

err_t LibTCPBind ( PCONNECTION_ENDPOINT  Connection,
struct ip_addr *const  ipaddr,
const u16_t  port 
)

Definition at line 415 of file tcp.c.

416{
417 struct lwip_callback_msg *msg;
418 err_t ret;
419
420 msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
421 if (msg)
422 {
424 msg->Input.Bind.Connection = Connection;
425 msg->Input.Bind.IpAddress = ipaddr;
426 msg->Input.Bind.Port = port;
427
429
430 if (WaitForEventSafely(&msg->Event))
431 ret = msg->Output.Bind.Error;
432 else
433 ret = ERR_CLSD;
434
435 ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
436
437 return ret;
438 }
439
440 return ERR_MEM;
441}
#define msg(x)
Definition: auth_time.c:54
#define FALSE
Definition: types.h:117
USHORT port
Definition: uri.c:228
static void LibTCPBindCallback(void *arg)
Definition: tcp.c:390
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:10
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: tcp.c:176
#define ERR_MEM
Definition: err.h:53
s8_t err_t
Definition: err.h:47
#define ERR_CLSD
Definition: err.h:67
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
@ NotificationEvent
PCONNECTION_ENDPOINT Connection
Definition: lwip_glue.h:38
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:214
int ret

Referenced by TCPConnect(), and TCPListen().

◆ LibTCPClose()

err_t LibTCPClose ( PCONNECTION_ENDPOINT  Connection,
const int  safe,
const int  callback 
)

Definition at line 798 of file tcp.c.

799{
800 err_t ret;
801 struct lwip_callback_msg *msg;
802
803 msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
804 if (msg)
805 {
807
808 msg->Input.Close.Connection = Connection;
809 msg->Input.Close.Callback = callback;
810
811 if (safe)
813 else
815
816 if (WaitForEventSafely(&msg->Event))
817 ret = msg->Output.Close.Error;
818 else
819 ret = ERR_CLSD;
820
821 ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
822
823 return ret;
824 }
825
826 return ERR_MEM;
827}
static void LibTCPCloseCallback(void *arg)
Definition: tcp.c:748
static IPrintDialogCallback callback
Definition: printdlg.c:326

Referenced by TCPAcceptEventHandler(), and TCPClose().

◆ LibTCPConnect()

err_t LibTCPConnect ( PCONNECTION_ENDPOINT  Connection,
struct ip_addr *const  ipaddr,
const u16_t  port 
)

Definition at line 622 of file tcp.c.

623{
624 struct lwip_callback_msg *msg;
625 err_t ret;
626
627 msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
628 if (msg)
629 {
631 msg->Input.Connect.Connection = Connection;
632 msg->Input.Connect.IpAddress = ipaddr;
633 msg->Input.Connect.Port = port;
634
636
637 if (WaitForEventSafely(&msg->Event))
638 {
639 ret = msg->Output.Connect.Error;
640 }
641 else
642 ret = ERR_CLSD;
643
644 ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
645
646 return ret;
647 }
648
649 return ERR_MEM;
650}
static void LibTCPConnectCallback(void *arg)
Definition: tcp.c:595

Referenced by TCPConnect().

◆ LibTCPFreeSocket()

VOID LibTCPFreeSocket ( PTCP_PCB  pcb)

Definition at line 375 of file tcp.c.

376{
377 struct lwip_callback_msg msg;
378
380 msg.Input.FreeSocket.pcb = pcb;
381
383
384 WaitForEventSafely(&msg.Event);
385}
static void LibTCPFreeSocketCallback(void *arg)
Definition: tcp.c:363
struct tcp_pcb * pcb
Definition: lwip_glue.h:35

◆ LibTCPGetDataFromConnectionQueue()

NTSTATUS LibTCPGetDataFromConnectionQueue ( PCONNECTION_ENDPOINT  Connection,
PUCHAR  RecvBuffer,
UINT  RecvLen,
UINT Received 
)

Definition at line 100 of file tcp.c.

101{
102 PQUEUE_ENTRY qp;
103 struct pbuf* p;
106
107 (*Received) = 0;
108
109 LockObject(Connection);
110
111 if (!IsListEmpty(&Connection->PacketQueue))
112 {
113 while ((qp = LibTCPDequeuePacket(Connection)) != NULL)
114 {
115 p = qp->p;
116
117 /* Calculate the payload length first */
118 PayloadLength = p->tot_len;
119 PayloadLength -= qp->Offset;
120 Offset = qp->Offset;
121
122 /* Check if we're reading the whole buffer */
123 ReadLength = MIN(PayloadLength, RecvLen);
124 ASSERT(ReadLength != 0);
126 {
127 /* Save this one for later */
128 qp->Offset += ReadLength;
129 InsertHeadList(&Connection->PacketQueue, &qp->ListEntry);
130 qp = NULL;
131 }
132
133 Copied = pbuf_copy_partial(p, RecvBuffer, ReadLength, Offset);
134 ASSERT(Copied == ReadLength);
135
136 /* Update trackers */
137 RecvLen -= ReadLength;
138 RecvBuffer += ReadLength;
139 (*Received) += ReadLength;
140
141 if (qp != NULL)
142 {
143 /* Use this special pbuf free callback function because we're outside tcpip thread */
145
146 ExFreeToNPagedLookasideList(&QueueEntryLookasideList, qp);
147 }
148 else
149 {
150 /* If we get here, it means we've filled the buffer */
151 ASSERT(RecvLen == 0);
152 }
153
154 ASSERT((*Received) != 0);
156
157 if (!RecvLen)
158 break;
159 }
160 }
161 else
162 {
163 if (Connection->ReceiveShutdown)
164 Status = Connection->ReceiveShutdownStatus;
165 else
167 }
168
169 UnlockObject(Connection);
170
171 return Status;
172}
ULONG ReadLength
UINT Received
Definition: arping.c:40
LONG NTSTATUS
Definition: precomp.h:26
#define MIN(x, y)
Definition: rdesktop.h:171
NPAGED_LOOKASIDE_LIST QueueEntryLookasideList
Definition: sys_arch.c:11
PQUEUE_ENTRY LibTCPDequeuePacket(PCONNECTION_ENDPOINT Connection)
Definition: tcp.c:86
#define InsertHeadList(ListHead, Entry)
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
Status
Definition: gdiplustypes.h:25
unsigned int UINT
Definition: ndis.h:50
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define STATUS_PENDING
Definition: ntstatus.h:82
u16_t pbuf_copy_partial(struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:918
#define STATUS_SUCCESS
Definition: shellext.h:65
LIST_ENTRY PacketQueue
Definition: titypes.h:256
NTSTATUS ReceiveShutdownStatus
Definition: titypes.h:266
BOOLEAN ReceiveShutdown
Definition: titypes.h:265
Definition: lwip_glue.h:18
struct pbuf * p
Definition: lwip_glue.h:19
LIST_ENTRY ListEntry
Definition: lwip_glue.h:21
ULONG Offset
Definition: lwip_glue.h:20
err_t pbuf_free_callback(struct pbuf *p)
Definition: tcpip.c:496
#define UnlockObject(Object)
Definition: titypes.h:44
#define LockObject(Object)
Definition: titypes.h:34
_In_ PVOID _In_ ULONG _In_ PVOID _In_ ULONG PayloadLength
Definition: iotypes.h:471

Referenced by TCPReceiveData(), and TCPRecvEventHandler().

◆ LibTCPGetHostName()

err_t LibTCPGetHostName ( PTCP_PCB  pcb,
struct ip_addr *const  ipaddr,
u16_t *const  port 
)

Definition at line 844 of file tcp.c.

845{
846 if (!pcb)
847 return ERR_CLSD;
848
849 *ipaddr = pcb->local_ip;
850 *port = pcb->local_port;
851
852 return ERR_OK;
853}
#define ERR_OK
Definition: err.h:52

Referenced by TCPGetSockAddress().

◆ LibTCPGetPeerName()

err_t LibTCPGetPeerName ( PTCP_PCB  pcb,
struct ip_addr *const  ipaddr,
u16_t *const  port 
)

Definition at line 856 of file tcp.c.

857{
858 if (!pcb)
859 return ERR_CLSD;
860
861 *ipaddr = pcb->remote_ip;
862 *port = pcb->remote_port;
863
864 return ERR_OK;
865}

Referenced by TCPCheckPeerForAccept(), and TCPGetSockAddress().

◆ LibTCPGetSocketStatus()

void LibTCPGetSocketStatus ( PTCP_PCB  pcb,
PULONG  State 
)

Definition at line 879 of file tcp.c.

882{
883 /* Translate state from enum tcp_state -> MIB_TCP_STATE */
884 *State = pcb->state + 1;
885}

Referenced by TCPGetSocketStatus().

◆ LibTCPListen()

PTCP_PCB LibTCPListen ( PCONNECTION_ENDPOINT  Connection,
const u8_t  backlog 
)

Definition at line 469 of file tcp.c.

470{
471 struct lwip_callback_msg *msg;
473
474 msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
475 if (msg)
476 {
478 msg->Input.Listen.Connection = Connection;
479 msg->Input.Listen.Backlog = backlog;
480
482
483 if (WaitForEventSafely(&msg->Event))
484 ret = msg->Output.Listen.NewPcb;
485 else
486 ret = NULL;
487
488 ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
489
490 return ret;
491 }
492
493 return NULL;
494}
static void LibTCPListenCallback(void *arg)
Definition: tcp.c:445
struct tcp_pcb * PTCP_PCB
Definition: lwip_glue.h:15

Referenced by TCPListen().

◆ LibTCPSend()

err_t LibTCPSend ( PCONNECTION_ENDPOINT  Connection,
void *const  dataptr,
const u16_t  len,
u32_t sent,
const int  safe 
)

Definition at line 557 of file tcp.c.

558{
559 err_t ret;
560 struct lwip_callback_msg *msg;
561
562 msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
563 if (msg)
564 {
566 msg->Input.Send.Connection = Connection;
567 msg->Input.Send.Data = dataptr;
568 msg->Input.Send.DataLength = len;
569
570 if (safe)
572 else
574
575 if (WaitForEventSafely(&msg->Event))
576 ret = msg->Output.Send.Error;
577 else
578 ret = ERR_CLSD;
579
580 if (ret == ERR_OK)
581 *sent = msg->Output.Send.Information;
582 else
583 *sent = 0;
584
585 ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
586
587 return ret;
588 }
589
590 return ERR_MEM;
591}
@ sent
Definition: SystemMenu.c:27
static void LibTCPSendCallback(void *arg)
Definition: tcp.c:498
GLenum GLsizei len
Definition: glext.h:6722
int const JOCTET * dataptr
Definition: jpeglib.h:1031

Referenced by TCPSendData(), and TCPSendEventHandler().

◆ LibTCPSetNoDelay()

void LibTCPSetNoDelay ( PTCP_PCB  pcb,
BOOLEAN  Set 
)

Definition at line 868 of file tcp.c.

871{
872 if (Set)
873 pcb->flags |= TF_NODELAY;
874 else
875 pcb->flags &= ~TF_NODELAY;
876}
static BOOL Set
Definition: pageheap.c:10

Referenced by TCPSetNoDelay().

◆ LibTCPShutdown()

err_t LibTCPShutdown ( PCONNECTION_ENDPOINT  Connection,
const int  shut_rx,
const int  shut_tx 
)

Definition at line 717 of file tcp.c.

718{
719 struct lwip_callback_msg *msg;
720 err_t ret;
721
722 msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
723 if (msg)
724 {
726
727 msg->Input.Shutdown.Connection = Connection;
728 msg->Input.Shutdown.shut_rx = shut_rx;
729 msg->Input.Shutdown.shut_tx = shut_tx;
730
732
733 if (WaitForEventSafely(&msg->Event))
734 ret = msg->Output.Shutdown.Error;
735 else
736 ret = ERR_CLSD;
737
738 ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
739
740 return ret;
741 }
742
743 return ERR_MEM;
744}
static void LibTCPShutdownCallback(void *arg)
Definition: tcp.c:654

Referenced by DisconnectWorker(), and TCPDisconnect().

◆ LibTCPSocket()

PTCP_PCB LibTCPSocket ( void arg)

Definition at line 336 of file tcp.c.

337{
338 struct lwip_callback_msg *msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
339 struct tcp_pcb *ret;
340
341 if (msg)
342 {
344 msg->Input.Socket.Arg = arg;
345
347
348 if (WaitForEventSafely(&msg->Event))
349 ret = msg->Output.Socket.NewPcb;
350 else
351 ret = NULL;
352
353 ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
354
355 return ret;
356 }
357
358 return NULL;
359}
static void LibTCPSocketCallback(void *arg)
Definition: tcp.c:318
void * arg
Definition: msvc.h:10

Referenced by TCPSocket().

◆ 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
248
249 Irp = Bucket->Request.RequestContext;
251
252 TI_DbgPrint(DEBUG_TCP,("[IP, TCPAcceptEventHandler] Getting the socket\n"));
253
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}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define DEBUG_TCP
Definition: debug.h:28
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
NTSTATUS TCPCheckPeerForAccept(PVOID Context, PTDI_REQUEST_KERNEL Request)
Definition: accept.c:17
err_t LibTCPClose(PCONNECTION_ENDPOINT Connection, const int safe, const int callback)
Definition: tcp.c:798
void LibTCPAccept(PTCP_PCB pcb, struct tcp_pcb *listen_pcb, void *arg)
Definition: tcp.c:830
base of all file and directory entries
Definition: entries.h:83
LIST_ENTRY ListenRequest
Definition: titypes.h:251
union _IO_STACK_LOCATION::@1564 Parameters
Definition: typedefs.h:120
NTSTATUS Status
Definition: titypes.h:233
ULONG Information
Definition: titypes.h:234
TDI_REQUEST Request
Definition: titypes.h:232
struct _CONNECTION_ENDPOINT * AssociatedEndpoint
Definition: titypes.h:231
PVOID RequestContext
Definition: tdi.h:55
#define DereferenceObject(Object)
Definition: titypes.h:24
struct _CONNECTION_ENDPOINT * PCONNECTION_ENDPOINT
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

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
433
434 Bucket->Status = TCPTranslateError(err);
435 Bucket->Information = 0;
436
437 CompleteBucket(Connection, Bucket, FALSE);
438 }
439
440 UnlockObject(Connection);
441}
NTSTATUS TCPTranslateError(const INT8 err)
Definition: tcp.c:267
#define err(...)
LIST_ENTRY ConnectRequest
Definition: titypes.h:250

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}
VOID FlushAllQueues(PCONNECTION_ENDPOINT Connection, NTSTATUS Status)
Definition: event.c:157
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)
struct _CONNECTION_ENDPOINT * Connection
Definition: titypes.h:131
struct _CONNECTION_ENDPOINT * Listener
Definition: titypes.h:133
PADDRESS_FILE AddressFile
Definition: titypes.h:247
struct _CONNECTION_ENDPOINT * Next
Definition: titypes.h:269

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;
388 UINT RecvLen;
389 PUCHAR RecvBuffer;
391
392 LockObject(Connection);
393
394 while(!IsListEmpty(&Connection->ReceiveRequest))
395 {
396 Entry = RemoveHeadList(&Connection->ReceiveRequest);
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}
NTSTATUS LibTCPGetDataFromConnectionQueue(PCONNECTION_ENDPOINT Connection, PUCHAR RecvBuffer, UINT RecvLen, UINT *Received)
Definition: tcp.c:100
#define NdisQueryBuffer(_Buffer, _VirtualAddress, _Length)
Definition: ndis.h:3029
LIST_ENTRY ReceiveRequest
Definition: titypes.h:252
LIST_ENTRY Entry
Definition: titypes.h:230
unsigned char * PUCHAR
Definition: typedefs.h:53
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl

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
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
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 {
367
368 if (KeCancelTimer(&Connection->DisconnectTimer))
369 {
370 DereferenceObject(Connection);
371 }
372 }
373
374 UnlockObject(Connection);
375
376 DereferenceObject(Connection);
377}
VOID FlushShutdownQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:95
err_t LibTCPSend(PCONNECTION_ENDPOINT Connection, void *const dataptr, const u16_t len, u32_t *sent, const int safe)
Definition: tcp.c:557
LIST_ENTRY SendRequest
Definition: titypes.h:253
KTIMER DisconnectTimer
Definition: titypes.h:259
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206
#define ReferenceObject(Object)
Definition: titypes.h:14
uint32_t ULONG
Definition: typedefs.h:59

Referenced by InternalSendEventHandler().