ReactOS  0.4.14-dev-297-g23e575c
rostcp.c File Reference
#include "lwip/sys.h"
#include "lwip/netif.h"
#include "lwip/tcpip.h"
#include "rosip.h"
#include <debug.h>
Include dependency graph for rostcp.c:

Go to the source code of this file.

Functions

NTSTATUS TCPTranslateError (const err_t err)
 
void LibTCPDumpPcb (PVOID SocketContext)
 
static void LibTCPEmptyQueue (PCONNECTION_ENDPOINT Connection)
 
void LibTCPEnqueuePacket (PCONNECTION_ENDPOINT Connection, struct pbuf *p)
 
PQUEUE_ENTRY LibTCPDequeuePacket (PCONNECTION_ENDPOINT Connection)
 
NTSTATUS LibTCPGetDataFromConnectionQueue (PCONNECTION_ENDPOINT Connection, PUCHAR RecvBuffer, UINT RecvLen, UINT *Received)
 
static BOOLEAN WaitForEventSafely (PRKEVENT Event)
 
static err_t InternalSendEventHandler (void *arg, PTCP_PCB pcb, const u16_t space)
 
static err_t InternalRecvEventHandler (void *arg, PTCP_PCB pcb, struct pbuf *p, const err_t err)
 
static err_t InternalAcceptEventHandler (void *arg, PTCP_PCB newpcb, const err_t err)
 
static err_t InternalConnectEventHandler (void *arg, PTCP_PCB pcb, const err_t err)
 
static void InternalErrorEventHandler (void *arg, const err_t err)
 
static void LibTCPSocketCallback (void *arg)
 
struct tcp_pcb * LibTCPSocket (void *arg)
 
static void LibTCPBindCallback (void *arg)
 
err_t LibTCPBind (PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t port)
 
static void LibTCPListenCallback (void *arg)
 
PTCP_PCB LibTCPListen (PCONNECTION_ENDPOINT Connection, const u8_t backlog)
 
static void LibTCPSendCallback (void *arg)
 
err_t LibTCPSend (PCONNECTION_ENDPOINT Connection, void *const dataptr, const u16_t len, u32_t *sent, const int safe)
 
static void LibTCPConnectCallback (void *arg)
 
err_t LibTCPConnect (PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t port)
 
static void LibTCPShutdownCallback (void *arg)
 
err_t LibTCPShutdown (PCONNECTION_ENDPOINT Connection, const int shut_rx, const int shut_tx)
 
static void LibTCPCloseCallback (void *arg)
 
err_t LibTCPClose (PCONNECTION_ENDPOINT Connection, const int safe, const int callback)
 
void LibTCPAccept (PTCP_PCB pcb, struct tcp_pcb *listen_pcb, void *arg)
 
err_t LibTCPGetHostName (PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
 
err_t LibTCPGetPeerName (PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
 
void LibTCPSetNoDelay (PTCP_PCB pcb, BOOLEAN Set)
 
void LibTCPGetSocketStatus (PTCP_PCB pcb, PULONG State)
 

Variables

static const char *const tcp_state_str []
 
KEVENT TerminationEvent
 
NPAGED_LOOKASIDE_LIST MessageLookasideList
 
NPAGED_LOOKASIDE_LIST QueueEntryLookasideList
 

Function Documentation

◆ InternalAcceptEventHandler()

static err_t InternalAcceptEventHandler ( void arg,
PTCP_PCB  newpcb,
const err_t  err 
)
static

Definition at line 273 of file rostcp.c.

274 {
275  /* Make sure the socket didn't get closed */
276  if (!arg)
277  return ERR_CLSD;
278 
279  TCPAcceptEventHandler(arg, newpcb);
280 
281  /* Set in LibTCPAccept (called from TCPAcceptEventHandler) */
282  if (newpcb->callback_arg)
283  return ERR_OK;
284  else
285  return ERR_CLSD;
286 }
#define ERR_CLSD
Definition: err.h:67
VOID TCPAcceptEventHandler(void *arg, PTCP_PCB newpcb)
Definition: event.c:297
#define ERR_OK
Definition: err.h:52

Referenced by LibTCPListenCallback().

◆ InternalConnectEventHandler()

static err_t InternalConnectEventHandler ( void arg,
PTCP_PCB  pcb,
const err_t  err 
)
static

Definition at line 290 of file rostcp.c.

291 {
292  /* Make sure the socket didn't get closed */
293  if (!arg)
294  return ERR_OK;
295 
297 
298  return ERR_OK;
299 }
VOID TCPConnectEventHandler(void *arg, const err_t err)
Definition: event.c:479
#define ERR_OK
Definition: err.h:52
#define err(...)

Referenced by LibTCPConnectCallback().

◆ InternalErrorEventHandler()

static void InternalErrorEventHandler ( void arg,
const err_t  err 
)
static

Definition at line 303 of file rostcp.c.

304 {
305  PCONNECTION_ENDPOINT Connection = arg;
306 
307  /* Make sure the socket didn't get closed */
308  if (!arg || Connection->SocketContext == NULL) return;
309 
310  /* The PCB is dead now */
311  Connection->SocketContext = NULL;
312 
313  /* Give them one shot to receive the remaining data */
314  Connection->ReceiveShutdown = TRUE;
316  TCPRecvEventHandler(Connection);
317 
318  /* Terminate the connection */
319  TCPFinEventHandler(Connection, err);
320 }
#define TRUE
Definition: types.h:120
NTSTATUS TCPTranslateError(const err_t err)
Definition: tcp.c:242
VOID TCPFinEventHandler(void *arg, const err_t err)
Definition: event.c:247
VOID TCPRecvEventHandler(void *arg)
Definition: event.c:437
NTSTATUS ReceiveShutdownStatus
Definition: titypes.h:286
void * arg
Definition: msvc.h:12
smooth NULL
Definition: ftsmooth.c:416
#define err(...)
BOOLEAN ReceiveShutdown
Definition: titypes.h:285

Referenced by LibTCPAccept(), and LibTCPSocketCallback().

◆ InternalRecvEventHandler()

static err_t InternalRecvEventHandler ( void arg,
PTCP_PCB  pcb,
struct pbuf p,
const err_t  err 
)
static

Definition at line 219 of file rostcp.c.

220 {
221  PCONNECTION_ENDPOINT Connection = arg;
222 
223  /* Make sure the socket didn't get closed */
224  if (!arg)
225  {
226  if (p)
227  pbuf_free(p);
228 
229  return ERR_OK;
230  }
231 
232  if (p)
233  {
234  LibTCPEnqueuePacket(Connection, p);
235 
236  tcp_recved(pcb, p->tot_len);
237 
239  }
240  else if (err == ERR_OK)
241  {
242  /* Complete pending reads with 0 bytes to indicate a graceful closure,
243  * but note that send is still possible in this state so we don't close the
244  * whole socket here (by calling tcp_close()) as that would violate TCP specs
245  */
246  Connection->ReceiveShutdown = TRUE;
248 
249  /* If we already did a send shutdown, we're in TIME_WAIT so we can't use this PCB anymore */
250  if (Connection->SendShutdown)
251  {
252  Connection->SocketContext = NULL;
253  tcp_arg(pcb, NULL);
254  }
255 
256  /* Indicate the graceful close event */
258 
259  /* If the PCB is gone, clean up the connection */
260  if (Connection->SendShutdown)
261  {
262  TCPFinEventHandler(Connection, ERR_CLSD);
263  }
264  }
265 
266  return ERR_OK;
267 }
#define TRUE
Definition: types.h:120
#define ERR_CLSD
Definition: err.h:67
VOID TCPFinEventHandler(void *arg, const err_t err)
Definition: event.c:247
VOID TCPRecvEventHandler(void *arg)
Definition: event.c:437
NTSTATUS ReceiveShutdownStatus
Definition: titypes.h:286
void * arg
Definition: msvc.h:12
void LibTCPEnqueuePacket(PCONNECTION_ENDPOINT Connection, struct pbuf *p)
Definition: rostcp.c:76
smooth NULL
Definition: ftsmooth.c:416
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:618
BOOLEAN SendShutdown
Definition: titypes.h:284
#define ERR_OK
Definition: err.h:52
#define err(...)
BOOLEAN ReceiveShutdown
Definition: titypes.h:285
GLfloat GLfloat p
Definition: glext.h:8902
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by LibTCPAccept(), and LibTCPConnectCallback().

◆ InternalSendEventHandler()

static err_t InternalSendEventHandler ( void arg,
PTCP_PCB  pcb,
const u16_t  space 
)
static

Definition at line 207 of file rostcp.c.

208 {
209  /* Make sure the socket didn't get closed */
210  if (!arg) return ERR_OK;
211 
213 
214  return ERR_OK;
215 }
#define ERR_OK
Definition: err.h:52
VOID TCPSendEventHandler(void *arg, const u16_t space)
Definition: event.c:359

Referenced by LibTCPAccept(), and LibTCPConnectCallback().

◆ LibTCPAccept()

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

Definition at line 796 of file rostcp.c.

797 {
798  ASSERT(arg);
799 
800  tcp_arg(pcb, NULL);
802  tcp_sent(pcb, InternalSendEventHandler);
803  tcp_err(pcb, InternalErrorEventHandler);
804  tcp_arg(pcb, arg);
805 
806  tcp_accepted(listen_pcb);
807 }
static err_t InternalRecvEventHandler(void *arg, PTCP_PCB pcb, struct pbuf *p, const err_t err)
Definition: rostcp.c:219
STREAM tcp_recv(STREAM s, uint32 length)
Definition: tcp.c:344
smooth NULL
Definition: ftsmooth.c:416
static err_t InternalSendEventHandler(void *arg, PTCP_PCB pcb, const u16_t space)
Definition: rostcp.c:207
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static void InternalErrorEventHandler(void *arg, const err_t err)
Definition: rostcp.c:303

Referenced by TCPAcceptEventHandler().

◆ LibTCPBind()

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

Definition at line 394 of file rostcp.c.

395 {
396  struct lwip_callback_msg *msg;
397  err_t ret;
398 
399  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
400  if (msg)
401  {
403  msg->Input.Bind.Connection = Connection;
404  msg->Input.Bind.IpAddress = ipaddr;
405  msg->Input.Bind.Port = port;
406 
408 
409  if (WaitForEventSafely(&msg->Event))
410  ret = msg->Output.Bind.Error;
411  else
412  ret = ERR_CLSD;
413 
414  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
415 
416  return ret;
417  }
418 
419  return ERR_MEM;
420 }
#define ERR_CLSD
Definition: err.h:67
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:182
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:212
PCONNECTION_ENDPOINT Connection
Definition: rosip.h:35
s8_t err_t
Definition: err.h:47
int ret
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ERR_MEM
Definition: fontsub.h:52
#define msg(x)
Definition: auth_time.c:54
static void LibTCPBindCallback(void *arg)
Definition: rostcp.c:369
USHORT port
Definition: uri.c:227
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15

Referenced by TCPConnect(), and TCPListen().

◆ LibTCPBindCallback()

static void LibTCPBindCallback ( void arg)
static

Definition at line 369 of file rostcp.c.

370 {
371  struct lwip_callback_msg *msg = arg;
372  PTCP_PCB pcb = msg->Input.Bind.Connection->SocketContext;
373 
374  ASSERT(msg);
375 
376  if (!msg->Input.Bind.Connection->SocketContext)
377  {
378  msg->Output.Bind.Error = ERR_CLSD;
379  goto done;
380  }
381 
382  /* We're guaranteed that the local address is valid to bind at this point */
383  pcb->so_options |= SOF_REUSEADDR;
384 
385  msg->Output.Bind.Error = tcp_bind(pcb,
386  msg->Input.Bind.IpAddress,
387  ntohs(msg->Input.Bind.Port));
388 
389 done:
390  KeSetEvent(&msg->Event, IO_NO_INCREMENT, FALSE);
391 }
#define ERR_CLSD
Definition: err.h:67
void * arg
Definition: msvc.h:12
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define ntohs(x)
Definition: module.h:208
#define SOF_REUSEADDR
Definition: ip.h:99
struct tcp_pcb * PTCP_PCB
Definition: rosip.h:15
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define msg(x)
Definition: auth_time.c:54
#define IO_NO_INCREMENT
Definition: iotypes.h:566

Referenced by LibTCPBind().

◆ LibTCPClose()

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

Definition at line 764 of file rostcp.c.

765 {
766  err_t ret;
767  struct lwip_callback_msg *msg;
768 
769  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
770  if (msg)
771  {
773 
774  msg->Input.Close.Connection = Connection;
775  msg->Input.Close.Callback = callback;
776 
777  if (safe)
779  else
781 
782  if (WaitForEventSafely(&msg->Event))
783  ret = msg->Output.Close.Error;
784  else
785  ret = ERR_CLSD;
786 
787  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
788 
789  return ret;
790  }
791 
792  return ERR_MEM;
793 }
#define ERR_CLSD
Definition: err.h:67
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:182
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:212
PCONNECTION_ENDPOINT Connection
Definition: rosip.h:35
s8_t err_t
Definition: err.h:47
MmuTrapHandler callback[0x30]
Definition: mmuobject.c:44
int ret
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ERR_MEM
Definition: fontsub.h:52
static void LibTCPCloseCallback(void *arg)
Definition: rostcp.c:714
#define msg(x)
Definition: auth_time.c:54
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15

Referenced by TCPAcceptEventHandler(), and TCPClose().

◆ LibTCPCloseCallback()

static void LibTCPCloseCallback ( void arg)
static

Definition at line 714 of file rostcp.c.

715 {
716  struct lwip_callback_msg *msg = arg;
717  PTCP_PCB pcb = msg->Input.Close.Connection->SocketContext;
718 
719  /* Empty the queue even if we're already "closed" */
720  LibTCPEmptyQueue(msg->Input.Close.Connection);
721 
722  /* Check if we've already been closed */
723  if (msg->Input.Close.Connection->Closing)
724  {
725  msg->Output.Close.Error = ERR_OK;
726  goto done;
727  }
728 
729  /* Enter "closing" mode if we're doing a normal close */
730  if (msg->Input.Close.Callback)
731  msg->Input.Close.Connection->Closing = TRUE;
732 
733  /* Check if the PCB was already "closed" but the client doesn't know it yet */
734  if (!msg->Input.Close.Connection->SocketContext)
735  {
736  msg->Output.Close.Error = ERR_OK;
737  goto done;
738  }
739 
740  /* Clear the PCB pointer and stop callbacks */
741  msg->Input.Close.Connection->SocketContext = NULL;
742  tcp_arg(pcb, NULL);
743 
744  /* This may generate additional callbacks but we don't care,
745  * because they're too inconsistent to rely on */
746  msg->Output.Close.Error = tcp_close(pcb);
747 
748  if (msg->Output.Close.Error)
749  {
750  /* Restore the PCB pointer */
751  msg->Input.Close.Connection->SocketContext = pcb;
752  msg->Input.Close.Connection->Closing = FALSE;
753  }
754  else if (msg->Input.Close.Callback)
755  {
756  TCPFinEventHandler(msg->Input.Close.Connection, ERR_CLSD);
757  }
758 
759 done:
760  KeSetEvent(&msg->Event, IO_NO_INCREMENT, FALSE);
761 }
#define TRUE
Definition: types.h:120
static void LibTCPEmptyQueue(PCONNECTION_ENDPOINT Connection)
Definition: rostcp.c:55
#define ERR_CLSD
Definition: err.h:67
VOID TCPFinEventHandler(void *arg, const err_t err)
Definition: event.c:247
void * arg
Definition: msvc.h:12
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
smooth NULL
Definition: ftsmooth.c:416
#define ERR_OK
Definition: err.h:52
struct tcp_pcb * PTCP_PCB
Definition: rosip.h:15
void tcp_close(struct sock *sk, long timeout)
#define msg(x)
Definition: auth_time.c:54
#define IO_NO_INCREMENT
Definition: iotypes.h:566

Referenced by LibTCPClose().

◆ LibTCPConnect()

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

Definition at line 601 of file rostcp.c.

602 {
603  struct lwip_callback_msg *msg;
604  err_t ret;
605 
606  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
607  if (msg)
608  {
610  msg->Input.Connect.Connection = Connection;
611  msg->Input.Connect.IpAddress = ipaddr;
612  msg->Input.Connect.Port = port;
613 
615 
616  if (WaitForEventSafely(&msg->Event))
617  {
618  ret = msg->Output.Connect.Error;
619  }
620  else
621  ret = ERR_CLSD;
622 
623  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
624 
625  return ret;
626  }
627 
628  return ERR_MEM;
629 }
#define ERR_CLSD
Definition: err.h:67
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:182
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:212
static void LibTCPConnectCallback(void *arg)
Definition: rostcp.c:574
PCONNECTION_ENDPOINT Connection
Definition: rosip.h:35
s8_t err_t
Definition: err.h:47
int ret
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ERR_MEM
Definition: fontsub.h:52
#define msg(x)
Definition: auth_time.c:54
USHORT port
Definition: uri.c:227
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15

Referenced by TCPConnect().

◆ LibTCPConnectCallback()

static void LibTCPConnectCallback ( void arg)
static

Definition at line 574 of file rostcp.c.

575 {
576  struct lwip_callback_msg *msg = arg;
577  err_t Error;
578 
579  ASSERT(arg);
580 
581  if (!msg->Input.Connect.Connection->SocketContext)
582  {
583  msg->Output.Connect.Error = ERR_CLSD;
584  goto done;
585  }
586 
587  tcp_recv((PTCP_PCB)msg->Input.Connect.Connection->SocketContext, InternalRecvEventHandler);
588  tcp_sent((PTCP_PCB)msg->Input.Connect.Connection->SocketContext, InternalSendEventHandler);
589 
590  Error = tcp_connect((PTCP_PCB)msg->Input.Connect.Connection->SocketContext,
591  msg->Input.Connect.IpAddress, ntohs(msg->Input.Connect.Port),
593 
594  msg->Output.Connect.Error = Error == ERR_OK ? ERR_INPROGRESS : Error;
595 
596 done:
597  KeSetEvent(&msg->Event, IO_NO_INCREMENT, FALSE);
598 }
static err_t InternalRecvEventHandler(void *arg, PTCP_PCB pcb, struct pbuf *p, const err_t err)
Definition: rostcp.c:219
STREAM tcp_recv(STREAM s, uint32 length)
Definition: tcp.c:344
#define ERR_CLSD
Definition: err.h:67
void * arg
Definition: msvc.h:12
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define ntohs(x)
Definition: module.h:208
s8_t err_t
Definition: err.h:47
#define ERR_OK
Definition: err.h:52
static err_t InternalSendEventHandler(void *arg, PTCP_PCB pcb, const u16_t space)
Definition: rostcp.c:207
struct tcp_pcb * PTCP_PCB
Definition: rosip.h:15
BOOL Error
Definition: chkdsk.c:66
RD_BOOL tcp_connect(char *server)
Definition: tcp.c:717
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static err_t InternalConnectEventHandler(void *arg, PTCP_PCB pcb, const err_t err)
Definition: rostcp.c:290
#define ERR_INPROGRESS
Definition: err.h:57
#define msg(x)
Definition: auth_time.c:54
#define IO_NO_INCREMENT
Definition: iotypes.h:566

Referenced by LibTCPConnect().

◆ LibTCPDequeuePacket()

PQUEUE_ENTRY LibTCPDequeuePacket ( PCONNECTION_ENDPOINT  Connection)

Definition at line 87 of file rostcp.c.

88 {
90  PQUEUE_ENTRY qp = NULL;
91 
92  if (IsListEmpty(&Connection->PacketQueue)) return NULL;
93 
95 
96  qp = CONTAINING_RECORD(Entry, QUEUE_ENTRY, ListEntry);
97 
98  return qp;
99 }
struct _Entry Entry
Definition: kefuncs.h:640
PCONNECTION_ENDPOINT Connection
Definition: rosip.h:35
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
LIST_ENTRY PacketQueue
Definition: titypes.h:277
Definition: rosip.h:17
smooth NULL
Definition: ftsmooth.c:416
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:117
base of all file and directory entries
Definition: entries.h:82

Referenced by LibTCPGetDataFromConnectionQueue().

◆ LibTCPDumpPcb()

void LibTCPDumpPcb ( PVOID  SocketContext)

Definition at line 39 of file rostcp.c.

40 {
41  struct tcp_pcb *pcb = (struct tcp_pcb*)SocketContext;
42  unsigned int addr = ntohl(pcb->remote_ip.addr);
43 
44  DbgPrint("\tState: %s\n", tcp_state_str[pcb->state]);
45  DbgPrint("\tRemote: (%d.%d.%d.%d, %d)\n",
46  (addr >> 24) & 0xFF,
47  (addr >> 16) & 0xFF,
48  (addr >> 8) & 0xFF,
49  addr & 0xFF,
50  pcb->remote_port);
51 }
static const char *const tcp_state_str[]
Definition: rostcp.c:9
#define DbgPrint
Definition: loader.c:25
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID SocketContext
Definition: wsk.h:182
GLenum const GLvoid * addr
Definition: glext.h:9621
#define ntohl(x)
Definition: module.h:203

Referenced by LogActiveObjects().

◆ LibTCPEmptyQueue()

static void LibTCPEmptyQueue ( PCONNECTION_ENDPOINT  Connection)
static

Definition at line 55 of file rostcp.c.

56 {
58  PQUEUE_ENTRY qp = NULL;
59 
60  ReferenceObject(Connection);
61 
62  while (!IsListEmpty(&Connection->PacketQueue))
63  {
64  Entry = RemoveHeadList(&Connection->PacketQueue);
65  qp = CONTAINING_RECORD(Entry, QUEUE_ENTRY, ListEntry);
66 
67  /* We're in the tcpip thread here so this is safe */
68  pbuf_free(qp->p);
69 
70  ExFreeToNPagedLookasideList(&QueueEntryLookasideList, qp);
71  }
72 
73  DereferenceObject(Connection);
74 }
struct pbuf * p
Definition: rosip.h:19
struct _Entry Entry
Definition: kefuncs.h:640
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
LIST_ENTRY PacketQueue
Definition: titypes.h:277
#define DereferenceObject(Object)
Definition: titypes.h:24
Definition: rosip.h:17
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:618
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 ReferenceObject(Object)
Definition: titypes.h:14
Definition: typedefs.h:117
NPAGED_LOOKASIDE_LIST QueueEntryLookasideList
Definition: sys_arch.c:16
base of all file and directory entries
Definition: entries.h:82

Referenced by LibTCPCloseCallback().

◆ LibTCPEnqueuePacket()

void LibTCPEnqueuePacket ( PCONNECTION_ENDPOINT  Connection,
struct pbuf p 
)

Definition at line 76 of file rostcp.c.

77 {
78  PQUEUE_ENTRY qp;
79 
80  qp = (PQUEUE_ENTRY)ExAllocateFromNPagedLookasideList(&QueueEntryLookasideList);
81  qp->p = p;
82  qp->Offset = 0;
83 
84  ExInterlockedInsertTailList(&Connection->PacketQueue, &qp->ListEntry, &Connection->Lock);
85 }
struct _QUEUE_ENTRY * PQUEUE_ENTRY
struct pbuf * p
Definition: rosip.h:19
KSPIN_LOCK Lock
Definition: titypes.h:265
ULONG Offset
Definition: rosip.h:20
LIST_ENTRY ListEntry
Definition: rosip.h:21
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
LIST_ENTRY PacketQueue
Definition: titypes.h:277
Definition: rosip.h:17
GLfloat GLfloat p
Definition: glext.h:8902
NPAGED_LOOKASIDE_LIST QueueEntryLookasideList
Definition: sys_arch.c:16

Referenced by InternalRecvEventHandler().

◆ LibTCPGetDataFromConnectionQueue()

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

Definition at line 101 of file rostcp.c.

102 {
103  PQUEUE_ENTRY qp;
104  struct pbuf* p;
106  UINT ReadLength, PayloadLength, Offset, Copied;
107  KIRQL OldIrql;
108 
109  (*Received) = 0;
110 
111  LockObject(Connection, &OldIrql);
112 
113  if (!IsListEmpty(&Connection->PacketQueue))
114  {
115  while ((qp = LibTCPDequeuePacket(Connection)) != NULL)
116  {
117  p = qp->p;
118 
119  /* Calculate the payload length first */
120  PayloadLength = p->tot_len;
121  PayloadLength -= qp->Offset;
122  Offset = qp->Offset;
123 
124  /* Check if we're reading the whole buffer */
125  ReadLength = MIN(PayloadLength, RecvLen);
126  ASSERT(ReadLength != 0);
127  if (ReadLength != PayloadLength)
128  {
129  /* Save this one for later */
130  qp->Offset += ReadLength;
131  InsertHeadList(&Connection->PacketQueue, &qp->ListEntry);
132  qp = NULL;
133  }
134 
135  UnlockObject(Connection, OldIrql);
136 
137  Copied = pbuf_copy_partial(p, RecvBuffer, ReadLength, Offset);
138  ASSERT(Copied == ReadLength);
139 
140  LockObject(Connection, &OldIrql);
141 
142  /* Update trackers */
143  RecvLen -= ReadLength;
144  RecvBuffer += ReadLength;
145  (*Received) += ReadLength;
146 
147  if (qp != NULL)
148  {
149  /* Use this special pbuf free callback function because we're outside tcpip thread */
150  pbuf_free_callback(qp->p);
151 
152  ExFreeToNPagedLookasideList(&QueueEntryLookasideList, qp);
153  }
154  else
155  {
156  /* If we get here, it means we've filled the buffer */
157  ASSERT(RecvLen == 0);
158  }
159 
160  ASSERT((*Received) != 0);
162 
163  if (!RecvLen)
164  break;
165  }
166  }
167  else
168  {
169  if (Connection->ReceiveShutdown)
170  Status = Connection->ReceiveShutdownStatus;
171  else
173  }
174 
175  UnlockObject(Connection, OldIrql);
176 
177  return Status;
178 }
struct pbuf * p
Definition: rosip.h:19
ULONG Offset
Definition: rosip.h:20
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
LIST_ENTRY ListEntry
Definition: rosip.h:21
LONG NTSTATUS
Definition: precomp.h:26
_In_ PVOID _In_ ULONG _In_ PVOID _In_ ULONG PayloadLength
Definition: iotypes.h:439
NTSTATUS ReceiveShutdownStatus
Definition: titypes.h:286
err_t pbuf_free_callback(struct pbuf *p)
Definition: tcpip.c:494
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
LIST_ENTRY PacketQueue
Definition: titypes.h:277
T MIN(T a, T b)
Definition: polytest.cpp:79
#define LockObject(Object, Irql)
Definition: titypes.h:34
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
Definition: rosip.h:17
#define UnlockObject(Object, OldIrql)
Definition: titypes.h:54
PQUEUE_ENTRY LibTCPDequeuePacket(PCONNECTION_ENDPOINT Connection)
Definition: rostcp.c:87
smooth NULL
Definition: ftsmooth.c:416
Definition: pbuf.h:79
#define STATUS_PENDING
Definition: ntstatus.h:82
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Status
Definition: gdiplustypes.h:24
u16_t pbuf_copy_partial(struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:918
BOOLEAN ReceiveShutdown
Definition: titypes.h:285
unsigned int UINT
Definition: ndis.h:50
GLfloat GLfloat p
Definition: glext.h:8902
NPAGED_LOOKASIDE_LIST QueueEntryLookasideList
Definition: sys_arch.c:16
return STATUS_SUCCESS
Definition: btrfs.c:2966
UINT Received
Definition: arping.c:40

Referenced by TCPReceiveData(), and TCPRecvEventHandler().

◆ LibTCPGetHostName()

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

Definition at line 810 of file rostcp.c.

811 {
812  if (!pcb)
813  return ERR_CLSD;
814 
815  *ipaddr = pcb->local_ip;
816  *port = pcb->local_port;
817 
818  return ERR_OK;
819 }
#define ERR_CLSD
Definition: err.h:67
#define ERR_OK
Definition: err.h:52
USHORT port
Definition: uri.c:227

Referenced by TCPGetSockAddress().

◆ LibTCPGetPeerName()

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

Definition at line 822 of file rostcp.c.

823 {
824  if (!pcb)
825  return ERR_CLSD;
826 
827  *ipaddr = pcb->remote_ip;
828  *port = pcb->remote_port;
829 
830  return ERR_OK;
831 }
#define ERR_CLSD
Definition: err.h:67
#define ERR_OK
Definition: err.h:52
USHORT port
Definition: uri.c:227

Referenced by TCPCheckPeerForAccept(), and TCPGetSockAddress().

◆ LibTCPGetSocketStatus()

void LibTCPGetSocketStatus ( PTCP_PCB  pcb,
PULONG  State 
)

Definition at line 845 of file rostcp.c.

848 {
849  /* Translate state from enum tcp_state -> MIB_TCP_STATE */
850  *State = pcb->state + 1;
851 }

Referenced by TCPGetSocketStatus().

◆ LibTCPListen()

PTCP_PCB LibTCPListen ( PCONNECTION_ENDPOINT  Connection,
const u8_t  backlog 
)

Definition at line 448 of file rostcp.c.

449 {
450  struct lwip_callback_msg *msg;
451  PTCP_PCB ret;
452 
453  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
454  if (msg)
455  {
457  msg->Input.Listen.Connection = Connection;
458  msg->Input.Listen.Backlog = backlog;
459 
461 
462  if (WaitForEventSafely(&msg->Event))
463  ret = msg->Output.Listen.NewPcb;
464  else
465  ret = NULL;
466 
467  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
468 
469  return ret;
470  }
471 
472  return NULL;
473 }
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:182
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:212
PCONNECTION_ENDPOINT Connection
Definition: rosip.h:35
smooth NULL
Definition: ftsmooth.c:416
struct tcp_pcb * PTCP_PCB
Definition: rosip.h:15
int ret
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static void LibTCPListenCallback(void *arg)
Definition: rostcp.c:424
#define msg(x)
Definition: auth_time.c:54
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15

Referenced by TCPListen().

◆ LibTCPListenCallback()

static void LibTCPListenCallback ( void arg)
static

Definition at line 424 of file rostcp.c.

425 {
426  struct lwip_callback_msg *msg = arg;
427 
428  ASSERT(msg);
429 
430  if (!msg->Input.Listen.Connection->SocketContext)
431  {
432  msg->Output.Listen.NewPcb = NULL;
433  goto done;
434  }
435 
436  msg->Output.Listen.NewPcb = tcp_listen_with_backlog((PTCP_PCB)msg->Input.Listen.Connection->SocketContext, msg->Input.Listen.Backlog);
437 
438  if (msg->Output.Listen.NewPcb)
439  {
440  tcp_accept(msg->Output.Listen.NewPcb, InternalAcceptEventHandler);
441  }
442 
443 done:
444  KeSetEvent(&msg->Event, IO_NO_INCREMENT, FALSE);
445 }
struct sock * tcp_accept(struct sock *sk, int flags, int *err)
void * arg
Definition: msvc.h:12
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
smooth NULL
Definition: ftsmooth.c:416
static err_t InternalAcceptEventHandler(void *arg, PTCP_PCB newpcb, const err_t err)
Definition: rostcp.c:273
struct tcp_pcb * PTCP_PCB
Definition: rosip.h:15
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define msg(x)
Definition: auth_time.c:54
#define IO_NO_INCREMENT
Definition: iotypes.h:566

Referenced by LibTCPListen().

◆ LibTCPSend()

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

Definition at line 536 of file rostcp.c.

537 {
538  err_t ret;
539  struct lwip_callback_msg *msg;
540 
541  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
542  if (msg)
543  {
545  msg->Input.Send.Connection = Connection;
546  msg->Input.Send.Data = dataptr;
547  msg->Input.Send.DataLength = len;
548 
549  if (safe)
551  else
553 
554  if (WaitForEventSafely(&msg->Event))
555  ret = msg->Output.Send.Error;
556  else
557  ret = ERR_CLSD;
558 
559  if (ret == ERR_OK)
560  *sent = msg->Output.Send.Information;
561  else
562  *sent = 0;
563 
564  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
565 
566  return ret;
567  }
568 
569  return ERR_MEM;
570 }
#define ERR_CLSD
Definition: err.h:67
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:182
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:212
PCONNECTION_ENDPOINT Connection
Definition: rosip.h:35
s8_t err_t
Definition: err.h:47
#define ERR_OK
Definition: err.h:52
int ret
Definition: msg.h:34
GLenum GLsizei len
Definition: glext.h:6722
static void LibTCPSendCallback(void *arg)
Definition: rostcp.c:477
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ERR_MEM
Definition: fontsub.h:52
#define msg(x)
Definition: auth_time.c:54
int const JOCTET * dataptr
Definition: jpeglib.h:1027
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15

Referenced by TCPSendData(), and TCPSendEventHandler().

◆ LibTCPSendCallback()

static void LibTCPSendCallback ( void arg)
static

Definition at line 477 of file rostcp.c.

478 {
479  struct lwip_callback_msg *msg = arg;
480  PTCP_PCB pcb = msg->Input.Send.Connection->SocketContext;
481  ULONG SendLength;
482  UCHAR SendFlags;
483 
484  ASSERT(msg);
485 
486  if (!msg->Input.Send.Connection->SocketContext)
487  {
488  msg->Output.Send.Error = ERR_CLSD;
489  goto done;
490  }
491 
492  if (msg->Input.Send.Connection->SendShutdown)
493  {
494  msg->Output.Send.Error = ERR_CLSD;
495  goto done;
496  }
497 
498  SendFlags = TCP_WRITE_FLAG_COPY;
499  SendLength = msg->Input.Send.DataLength;
500  if (tcp_sndbuf(pcb) == 0)
501  {
502  /* No buffer space so return pending */
503  msg->Output.Send.Error = ERR_INPROGRESS;
504  goto done;
505  }
506  else if (tcp_sndbuf(pcb) < SendLength)
507  {
508  /* We've got some room so let's send what we can */
509  SendLength = tcp_sndbuf(pcb);
510 
511  /* Don't set the push flag */
512  SendFlags |= TCP_WRITE_FLAG_MORE;
513  }
514 
515  msg->Output.Send.Error = tcp_write(pcb,
516  msg->Input.Send.Data,
517  SendLength,
518  SendFlags);
519  if (msg->Output.Send.Error == ERR_OK)
520  {
521  /* Queued successfully so try to send it */
522  tcp_output((PTCP_PCB)msg->Input.Send.Connection->SocketContext);
523  msg->Output.Send.Information = SendLength;
524  }
525  else if (msg->Output.Send.Error == ERR_MEM)
526  {
527  /* The queue is too long */
528  msg->Output.Send.Error = ERR_INPROGRESS;
529  }
530 
531 done:
532  KeSetEvent(&msg->Event, IO_NO_INCREMENT, FALSE);
533 }
#define ERR_CLSD
Definition: err.h:67
void * arg
Definition: msvc.h:12
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define ERR_OK
Definition: err.h:52
struct tcp_pcb * PTCP_PCB
Definition: rosip.h:15
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
#define ERR_MEM
Definition: fontsub.h:52
#define ERR_INPROGRESS
Definition: err.h:57
#define msg(x)
Definition: auth_time.c:54
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566

Referenced by LibTCPSend().

◆ LibTCPSetNoDelay()

void LibTCPSetNoDelay ( PTCP_PCB  pcb,
BOOLEAN  Set 
)

Definition at line 834 of file rostcp.c.

837 {
838  if (Set)
839  pcb->flags |= TF_NODELAY;
840  else
841  pcb->flags &= ~TF_NODELAY;
842 }
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 683 of file rostcp.c.

684 {
685  struct lwip_callback_msg *msg;
686  err_t ret;
687 
688  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
689  if (msg)
690  {
692 
693  msg->Input.Shutdown.Connection = Connection;
694  msg->Input.Shutdown.shut_rx = shut_rx;
695  msg->Input.Shutdown.shut_tx = shut_tx;
696 
698 
699  if (WaitForEventSafely(&msg->Event))
700  ret = msg->Output.Shutdown.Error;
701  else
702  ret = ERR_CLSD;
703 
704  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
705 
706  return ret;
707  }
708 
709  return ERR_MEM;
710 }
#define ERR_CLSD
Definition: err.h:67
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:182
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:212
PCONNECTION_ENDPOINT Connection
Definition: rosip.h:35
s8_t err_t
Definition: err.h:47
static void LibTCPShutdownCallback(void *arg)
Definition: rostcp.c:633
int ret
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ERR_MEM
Definition: fontsub.h:52
#define msg(x)
Definition: auth_time.c:54
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15

Referenced by DisconnectTimeoutDpc(), and TCPDisconnect().

◆ LibTCPShutdownCallback()

static void LibTCPShutdownCallback ( void arg)
static

Definition at line 633 of file rostcp.c.

634 {
635  struct lwip_callback_msg *msg = arg;
636  PTCP_PCB pcb = msg->Input.Shutdown.Connection->SocketContext;
637 
638  if (!msg->Input.Shutdown.Connection->SocketContext)
639  {
640  msg->Output.Shutdown.Error = ERR_CLSD;
641  goto done;
642  }
643 
644  /* LwIP makes the (questionable) assumption that SHUTDOWN_RDWR is equivalent to tcp_close().
645  * This assumption holds even if the shutdown calls are done separately (even through multiple
646  * WinSock shutdown() calls). This assumption means that lwIP has the right to deallocate our
647  * PCB without telling us if we shutdown TX and RX. To avoid these problems, we'll clear the
648  * socket context if we have called shutdown for TX and RX.
649  */
650  if (msg->Input.Shutdown.shut_rx) {
651  msg->Output.Shutdown.Error = tcp_shutdown(pcb, TRUE, FALSE);
652  }
653  if (msg->Input.Shutdown.shut_tx) {
654  msg->Output.Shutdown.Error = tcp_shutdown(pcb, FALSE, TRUE);
655  }
656 
657  if (!msg->Output.Shutdown.Error)
658  {
659  if (msg->Input.Shutdown.shut_rx)
660  {
661  msg->Input.Shutdown.Connection->ReceiveShutdown = TRUE;
662  msg->Input.Shutdown.Connection->ReceiveShutdownStatus = STATUS_FILE_CLOSED;
663  }
664 
665  if (msg->Input.Shutdown.shut_tx)
666  msg->Input.Shutdown.Connection->SendShutdown = TRUE;
667 
668  if (msg->Input.Shutdown.Connection->ReceiveShutdown &&
669  msg->Input.Shutdown.Connection->SendShutdown)
670  {
671  /* The PCB is not ours anymore */
672  msg->Input.Shutdown.Connection->SocketContext = NULL;
673  tcp_arg(pcb, NULL);
674  TCPFinEventHandler(msg->Input.Shutdown.Connection, ERR_CLSD);
675  }
676  }
677 
678 done:
679  KeSetEvent(&msg->Event, IO_NO_INCREMENT, FALSE);
680 }
#define TRUE
Definition: types.h:120
#define ERR_CLSD
Definition: err.h:67
VOID TCPFinEventHandler(void *arg, const err_t err)
Definition: event.c:247
void * arg
Definition: msvc.h:12
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
smooth NULL
Definition: ftsmooth.c:416
struct tcp_pcb * PTCP_PCB
Definition: rosip.h:15
void tcp_shutdown(struct sock *sk, int how)
#define msg(x)
Definition: auth_time.c:54
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:518

Referenced by LibTCPShutdown().

◆ LibTCPSocket()

struct tcp_pcb* LibTCPSocket ( void arg)

Definition at line 342 of file rostcp.c.

343 {
344  struct lwip_callback_msg *msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
345  struct tcp_pcb *ret;
346 
347  if (msg)
348  {
350  msg->Input.Socket.Arg = arg;
351 
353 
354  if (WaitForEventSafely(&msg->Event))
355  ret = msg->Output.Socket.NewPcb;
356  else
357  ret = NULL;
358 
359  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
360 
361  return ret;
362  }
363 
364  return NULL;
365 }
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:182
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:212
void * arg
Definition: msvc.h:12
smooth NULL
Definition: ftsmooth.c:416
int ret
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static void LibTCPSocketCallback(void *arg)
Definition: rostcp.c:324
#define msg(x)
Definition: auth_time.c:54
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15

Referenced by TCPSocket().

◆ LibTCPSocketCallback()

static void LibTCPSocketCallback ( void arg)
static

Definition at line 324 of file rostcp.c.

325 {
326  struct lwip_callback_msg *msg = arg;
327 
328  ASSERT(msg);
329 
330  msg->Output.Socket.NewPcb = tcp_new();
331 
332  if (msg->Output.Socket.NewPcb)
333  {
334  tcp_arg(msg->Output.Socket.NewPcb, msg->Input.Socket.Arg);
335  tcp_err(msg->Output.Socket.NewPcb, InternalErrorEventHandler);
336  }
337 
338  KeSetEvent(&msg->Event, IO_NO_INCREMENT, FALSE);
339 }
void * arg
Definition: msvc.h:12
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static void InternalErrorEventHandler(void *arg, const err_t err)
Definition: rostcp.c:303
#define msg(x)
Definition: auth_time.c:54
#define IO_NO_INCREMENT
Definition: iotypes.h:566

Referenced by LibTCPSocket().

◆ TCPTranslateError()

NTSTATUS TCPTranslateError ( const err_t  err)

Definition at line 242 of file tcp.c.

243 {
245 
246  switch (err)
247  {
248  case ERR_OK: Status = STATUS_SUCCESS; return Status; //0
249  case ERR_MEM: Status = STATUS_INSUFFICIENT_RESOURCES; break; //-1
250  case ERR_BUF: Status = STATUS_BUFFER_TOO_SMALL; break; //-2
251  case ERR_TIMEOUT: Status = STATUS_TIMEOUT; break; // -3
252  case ERR_RTE: Status = STATUS_NETWORK_UNREACHABLE; break; //-4
253  case ERR_INPROGRESS: Status = STATUS_PENDING; return Status; //-5
254  case ERR_VAL: Status = STATUS_INVALID_PARAMETER; break; //-6
255  case ERR_WOULDBLOCK: Status = STATUS_CANT_WAIT; break; //-7
256  case ERR_USE: Status = STATUS_ADDRESS_ALREADY_EXISTS; break; //-8
257  case ERR_ISCONN: Status = STATUS_UNSUCCESSFUL; break; //-9 (FIXME)
258  case ERR_ABRT: Status = STATUS_LOCAL_DISCONNECT; break; //-10
259  case ERR_RST: Status = STATUS_REMOTE_DISCONNECT; break; //-11
260  case ERR_CLSD: Status = STATUS_FILE_CLOSED; break; //-12
261  case ERR_CONN: Status = STATUS_INVALID_CONNECTION; break; //-13
262  case ERR_ARG: Status = STATUS_INVALID_PARAMETER; break; //-14
263  case ERR_IF: Status = STATUS_UNEXPECTED_NETWORK_ERROR; break; //-15
264  default:
265  DbgPrint("Invalid error value: %d\n", err);
266  ASSERT(FALSE);
268  break;
269  }
270 
271  TI_DbgPrint(DEBUG_TCP,("TCP operation failed: 0x%x (%d)\n", Status, err));
272 
273  return Status;
274 }
#define ERR_CONN
Definition: err.h:68
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
#define STATUS_INVALID_CONNECTION
Definition: ntstatus.h:542
#define ERR_ARG
Definition: err.h:70
#define ERR_ISCONN
Definition: err.h:61
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define ERR_RTE
Definition: err.h:56
#define DbgPrint
Definition: loader.c:25
#define ERR_CLSD
Definition: err.h:67
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define ERR_USE
Definition: err.h:60
LONG NTSTATUS
Definition: precomp.h:26
#define DEBUG_TCP
Definition: debug.h:28
#define STATUS_ADDRESS_ALREADY_EXISTS
Definition: ntstatus.h:640
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
#define ERR_TIMEOUT
Definition: err.h:55
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
#define STATUS_REMOTE_DISCONNECT
Definition: ntstatus.h:538
#define ERR_VAL
Definition: err.h:58
#define ERR_OK
Definition: err.h:52
#define STATUS_PENDING
Definition: ntstatus.h:82
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ERR_RST
Definition: err.h:66
#define err(...)
Status
Definition: gdiplustypes.h:24
#define ERR_MEM
Definition: fontsub.h:52
#define ERR_BUF
Definition: err.h:54
#define STATUS_LOCAL_DISCONNECT
Definition: ntstatus.h:537
#define ERR_INPROGRESS
Definition: err.h:57
#define ERR_WOULDBLOCK
Definition: err.h:59
#define STATUS_UNEXPECTED_NETWORK_ERROR
Definition: ntstatus.h:418
#define ERR_ABRT
Definition: err.h:65
#define ERR_IF
Definition: err.h:72
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define STATUS_NETWORK_UNREACHABLE
Definition: ntstatus.h:690
#define STATUS_CANT_WAIT
Definition: ntstatus.h:438
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:518

Referenced by DisconnectTimeoutDpc(), InternalErrorEventHandler(), TCPConnect(), TCPDisconnect(), TCPGetSockAddress(), and TCPSendData().

◆ WaitForEventSafely()

static BOOLEAN WaitForEventSafely ( PRKEVENT  Event)
static

Definition at line 182 of file rostcp.c.

183 {
184  PVOID WaitObjects[] = {Event, &TerminationEvent};
185 
187  WaitObjects,
188  WaitAny,
189  Executive,
190  KernelMode,
191  FALSE,
192  NULL,
193  NULL) == STATUS_WAIT_0)
194  {
195  /* Signalled by the caller's event */
196  return TRUE;
197  }
198  else /* if KeWaitForMultipleObjects() == STATUS_WAIT_1 */
199  {
200  /* Signalled by our termination event */
201  return FALSE;
202  }
203 }
#define TRUE
Definition: types.h:120
#define STATUS_WAIT_0
Definition: ntstatus.h:223
KEVENT TerminationEvent
Definition: sys_arch.c:14
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI KeWaitForMultipleObjects(IN ULONG Count, IN PVOID Object[], IN WAIT_TYPE WaitType, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL, OUT PKWAIT_BLOCK WaitBlockArray OPTIONAL)
Definition: wait.c:586

Referenced by LibTCPBind(), LibTCPClose(), LibTCPConnect(), LibTCPListen(), LibTCPSend(), LibTCPShutdown(), and LibTCPSocket().

Variable Documentation

◆ MessageLookasideList

◆ QueueEntryLookasideList

◆ tcp_state_str

const char* const tcp_state_str[]
static
Initial value:
= {
"CLOSED",
"LISTEN",
"SYN_SENT",
"SYN_RCVD",
"ESTABLISHED",
"FIN_WAIT_1",
"FIN_WAIT_2",
"CLOSE_WAIT",
"CLOSING",
"LAST_ACK",
"TIME_WAIT"
}

Definition at line 9 of file rostcp.c.

Referenced by LibTCPDumpPcb().

◆ TerminationEvent

KEVENT TerminationEvent