ReactOS  0.4.14-dev-606-g14ebc0b
rostcp.c
Go to the documentation of this file.
1 #include "lwip/sys.h"
2 #include "lwip/netif.h"
3 #include "lwip/tcpip.h"
4 
5 #include "rosip.h"
6 
7 #include <debug.h>
8 
9 static const char * const tcp_state_str[] = {
10  "CLOSED",
11  "LISTEN",
12  "SYN_SENT",
13  "SYN_RCVD",
14  "ESTABLISHED",
15  "FIN_WAIT_1",
16  "FIN_WAIT_2",
17  "CLOSE_WAIT",
18  "CLOSING",
19  "LAST_ACK",
20  "TIME_WAIT"
21 };
22 
23 /* The way that lwIP does multi-threading is really not ideal for our purposes but
24  * we best go along with it unless we want another unstable TCP library. lwIP uses
25  * a thread called the "tcpip thread" which is the only one allowed to call raw API
26  * functions. Since this is the case, for each of our LibTCP* functions, we queue a request
27  * for a callback to "tcpip thread" which calls our LibTCP*Callback functions. Yes, this is
28  * a lot of unnecessary thread swapping and it could definitely be faster, but I don't want
29  * to going messing around in lwIP because I have no desire to create another mess like oskittcp */
30 
34 
35 /* Required for ERR_T to NTSTATUS translation in receive error handling */
37 
38 void
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 }
52 
53 static
54 void
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 }
75 
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 }
86 
88 {
90  PQUEUE_ENTRY qp = NULL;
91 
92  if (IsListEmpty(&Connection->PacketQueue)) return NULL;
93 
94  Entry = RemoveHeadList(&Connection->PacketQueue);
95 
96  qp = CONTAINING_RECORD(Entry, QUEUE_ENTRY, ListEntry);
97 
98  return qp;
99 }
100 
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 }
179 
180 static
181 BOOLEAN
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 }
204 
205 static
206 err_t
208 {
209  /* Make sure the socket didn't get closed */
210  if (!arg) return ERR_OK;
211 
213 
214  return ERR_OK;
215 }
216 
217 static
218 err_t
219 InternalRecvEventHandler(void *arg, PTCP_PCB pcb, struct pbuf *p, const err_t err)
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 }
268 
269 /* This function MUST return an error value that is not ERR_ABRT or ERR_OK if the connection
270  * is not accepted to avoid leaking the new PCB */
271 static
272 err_t
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 }
287 
288 static
289 err_t
291 {
292  /* Make sure the socket didn't get closed */
293  if (!arg)
294  return ERR_OK;
295 
297 
298  return ERR_OK;
299 }
300 
301 static
302 void
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 }
321 
322 static
323 void
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 }
340 
341 struct tcp_pcb *
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 }
366 
367 static
368 void
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 }
392 
393 err_t
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 }
421 
422 static
423 void
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 }
446 
447 PTCP_PCB
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 }
474 
475 static
476 void
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 }
534 
535 err_t
536 LibTCPSend(PCONNECTION_ENDPOINT Connection, void *const dataptr, const u16_t len, u32_t *sent, const int safe)
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 }
571 
572 static
573 void
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 }
599 
600 err_t
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 }
630 
631 static
632 void
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 }
681 
682 err_t
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 }
711 
712 static
713 void
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 }
762 
763 err_t
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 }
794 
795 void
796 LibTCPAccept(PTCP_PCB pcb, struct tcp_pcb *listen_pcb, void *arg)
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 }
808 
809 err_t
810 LibTCPGetHostName(PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
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 }
820 
821 err_t
822 LibTCPGetPeerName(PTCP_PCB pcb, struct ip_addr * const ipaddr, u16_t * const port)
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 }
832 
833 void
835  PTCP_PCB pcb,
836  BOOLEAN Set)
837 {
838  if (Set)
839  pcb->flags |= TF_NODELAY;
840  else
841  pcb->flags &= ~TF_NODELAY;
842 }
843 
844 void
846  PTCP_PCB pcb,
847  PULONG State)
848 {
849  /* Translate state from enum tcp_state -> MIB_TCP_STATE */
850  *State = pcb->state + 1;
851 }
struct _QUEUE_ENTRY * PQUEUE_ENTRY
err_t LibTCPClose(PCONNECTION_ENDPOINT Connection, const int safe, const int callback)
Definition: rostcp.c:764
err_t LibTCPBind(PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t port)
Definition: rostcp.c:394
static const char *const tcp_state_str[]
Definition: rostcp.c:9
struct pbuf * p
Definition: rosip.h:19
#define TRUE
Definition: types.h:120
struct LOOKASIDE_ALIGN _NPAGED_LOOKASIDE_LIST NPAGED_LOOKASIDE_LIST
NTSTATUS TCPTranslateError(const err_t err)
Definition: tcp.c:242
KSPIN_LOCK Lock
Definition: titypes.h:265
static err_t InternalRecvEventHandler(void *arg, PTCP_PCB pcb, struct pbuf *p, const err_t err)
Definition: rostcp.c:219
struct _Entry Entry
Definition: kefuncs.h:640
static void LibTCPEmptyQueue(PCONNECTION_ENDPOINT Connection)
Definition: rostcp.c:55
#define DbgPrint
Definition: loader.c:25
PTCP_PCB LibTCPListen(PCONNECTION_ENDPOINT Connection, const u8_t backlog)
Definition: rostcp.c:448
err_t LibTCPGetPeerName(PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
Definition: rostcp.c:822
STREAM tcp_recv(STREAM s, uint32 length)
Definition: tcp.c:344
ULONG Offset
Definition: rosip.h:20
#define ERR_CLSD
Definition: err.h:67
VOID TCPFinEventHandler(void *arg, const err_t err)
Definition: event.c:247
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
LIST_ENTRY ListEntry
Definition: rosip.h:21
unsigned char * PUCHAR
Definition: retypes.h:3
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
LONG NTSTATUS
Definition: precomp.h:26
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:182
struct sock * tcp_accept(struct sock *sk, int flags, int *err)
VOID TCPRecvEventHandler(void *arg)
Definition: event.c:437
_In_ PVOID _In_ ULONG _In_ PVOID _In_ ULONG PayloadLength
Definition: iotypes.h:439
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
NTSTATUS ReceiveShutdownStatus
Definition: titypes.h:286
PCONNECTION_ENDPOINT Connection
Definition: rosip.h:35
void * arg
Definition: msvc.h:10
err_t LibTCPConnect(PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t port)
Definition: rostcp.c:601
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID SocketContext
Definition: wsk.h:182
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
#define ntohs(x)
Definition: module.h:208
static BOOL Set
Definition: pageheap.c:10
#define DereferenceObject(Object)
Definition: titypes.h:24
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
VOID TCPConnectEventHandler(void *arg, const err_t err)
Definition: event.c:479
#define STATUS_WAIT_0
Definition: ntstatus.h:223
void LibTCPAccept(PTCP_PCB pcb, struct tcp_pcb *listen_pcb, void *arg)
Definition: rostcp.c:796
_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
KEVENT TerminationEvent
Definition: sys_arch.c:14
void LibTCPEnqueuePacket(PCONNECTION_ENDPOINT Connection, struct pbuf *p)
Definition: rostcp.c:76
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
unsigned char BOOLEAN
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
s8_t err_t
Definition: err.h:47
VOID TCPAcceptEventHandler(void *arg, PTCP_PCB newpcb)
Definition: event.c:297
static err_t InternalAcceptEventHandler(void *arg, PTCP_PCB newpcb, const err_t err)
Definition: rostcp.c:273
BOOLEAN SendShutdown
Definition: titypes.h:284
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 ERR_OK
Definition: err.h:52
static err_t InternalSendEventHandler(void *arg, PTCP_PCB pcb, const u16_t space)
Definition: rostcp.c:207
MmuTrapHandler callback[0x30]
Definition: mmuobject.c:44
#define SOF_REUSEADDR
Definition: ip.h:99
void LibTCPDumpPcb(PVOID SocketContext)
Definition: rostcp.c:39
static void LibTCPShutdownCallback(void *arg)
Definition: rostcp.c:633
Definition: pbuf.h:79
unsigned long u32_t
Definition: cc.h:25
#define STATUS_PENDING
Definition: ntstatus.h:82
struct tcp_pcb * PTCP_PCB
Definition: rosip.h:15
NTSTATUS LibTCPGetDataFromConnectionQueue(PCONNECTION_ENDPOINT Connection, PUCHAR RecvBuffer, UINT RecvLen, UINT *Received)
Definition: rostcp.c:101
BOOL Error
Definition: chkdsk.c:66
RD_BOOL tcp_connect(char *server)
Definition: tcp.c:717
void tcp_shutdown(struct sock *sk, int how)
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static err_t InternalConnectEventHandler(void *arg, PTCP_PCB pcb, const err_t err)
Definition: rostcp.c:290
unsigned char UCHAR
Definition: xmlstorage.h:181
int ret
GLenum const GLvoid * addr
Definition: glext.h:9621
Definition: msg.h:34
void LibTCPSetNoDelay(PTCP_PCB pcb, BOOLEAN Set)
Definition: rostcp.c:834
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
void tcp_close(struct sock *sk, long timeout)
GLenum GLsizei len
Definition: glext.h:6722
#define ReferenceObject(Object)
Definition: titypes.h:14
err_t LibTCPSend(PCONNECTION_ENDPOINT Connection, void *const dataptr, const u16_t len, u32_t *sent, const int safe)
Definition: rostcp.c:536
Definition: typedefs.h:117
#define err(...)
Status
Definition: gdiplustypes.h:24
static void LibTCPSendCallback(void *arg)
Definition: rostcp.c:477
u16_t pbuf_copy_partial(struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:918
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
BOOLEAN ReceiveShutdown
Definition: titypes.h:285
static void LibTCPSocketCallback(void *arg)
Definition: rostcp.c:324
#define ERR_MEM
Definition: fontsub.h:52
static void LibTCPCloseCallback(void *arg)
Definition: rostcp.c:714
err_t LibTCPGetHostName(PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
Definition: rostcp.c:810
unsigned char u8_t
Definition: cc.h:23
struct tcp_pcb * LibTCPSocket(void *arg)
Definition: rostcp.c:342
unsigned int * PULONG
Definition: retypes.h:1
unsigned int UINT
Definition: ndis.h:50
err_t LibTCPShutdown(PCONNECTION_ENDPOINT Connection, const int shut_rx, const int shut_tx)
Definition: rostcp.c:683
static void LibTCPListenCallback(void *arg)
Definition: rostcp.c:424
static void InternalErrorEventHandler(void *arg, const err_t err)
Definition: rostcp.c:303
#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
int const JOCTET * dataptr
Definition: jpeglib.h:1027
static void LibTCPBindCallback(void *arg)
Definition: rostcp.c:369
unsigned short u16_t
Definition: cc.h:24
VOID TCPSendEventHandler(void *arg, const u16_t space)
Definition: event.c:359
GLfloat GLfloat p
Definition: glext.h:8902
NPAGED_LOOKASIDE_LIST QueueEntryLookasideList
Definition: sys_arch.c:16
return STATUS_SUCCESS
Definition: btrfs.c:2938
USHORT port
Definition: uri.c:228
void LibTCPGetSocketStatus(PTCP_PCB pcb, PULONG State)
Definition: rostcp.c:845
UINT Received
Definition: arping.c:40
base of all file and directory entries
Definition: entries.h:82
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:518
#define ntohl(x)
Definition: module.h:203