Author: cmihail
Date: Thu Jul 21 20:58:54 2011
New Revision: 52767
URL:
http://svn.reactos.org/svn/reactos?rev=52767&view=rev
Log:
[lwIP]
- Modify the signatures of the lwIP wrapper interfaces. This is the first step toward
fixing some nasty crashes related to race conditions.
[TCPIP]
- Call the new lwIP wrapper interfaces appropriately.
Modified:
branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/accept.c
branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/event.c
branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/tcp.c
branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/CMakeLists.txt
branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/include/rosip.h
branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c
Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/accept.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/drive…
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/accept.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/accept.c [iso-8859-1] Thu
Jul 21 20:58:54 2011
@@ -67,7 +67,7 @@
AddressToBind.addr = Connection->AddressFile->Address.Address.IPv4Address;
- Status = TCPTranslateError(LibTCPBind(Connection->SocketContext,
+ Status = TCPTranslateError(LibTCPBind(Connection,
&AddressToBind,
Connection->AddressFile->Port));
@@ -91,7 +91,7 @@
if (NT_SUCCESS(Status))
{
- Connection->SocketContext = LibTCPListen(Connection->SocketContext,
Backlog);
+ Connection->SocketContext = LibTCPListen(Connection, Backlog);
if (!Connection->SocketContext)
Status = STATUS_UNSUCCESSFUL;
}
Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/event.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/drive…
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/event.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/event.c [iso-8859-1] Thu
Jul 21 20:58:54 2011
@@ -143,30 +143,32 @@
VOID
TCPFinEventHandler(void *arg, err_t err)
{
- PCONNECTION_ENDPOINT Connection = arg;
+ PCONNECTION_ENDPOINT Connection = (PCONNECTION_ENDPOINT)arg;
+
+ DbgPrint("[IP, TCPFinEventHandler] Called for Connection( 0x%x )->
SocketContext = pcb (0x%x)\n", Connection, Connection->SocketContext);
/* Only clear the pointer if the shutdown was caused by an error */
if (err != ERR_OK)
{
/* We're already closed by the error so we don't want to call lwip_close
*/
+ DbgPrint("[IP, TCPFinEventHandler] MAKING Connection( 0x%x )->
SocketContext = pcb (0x%x) NULL\n", Connection, Connection->SocketContext);
Connection->SocketContext = NULL;
}
-
- DbgPrint("[IP, TCPFinEventHandler] Called for Connection( 0x%x )->
SocketContext = pcb (0x%x)\n", Connection, Connection->SocketContext);
FlushAllQueues(Connection, TCPTranslateError(err));
+
+ DbgPrint("[IP, TCPFinEventHandler] Done\n");
}
VOID
TCPAcceptEventHandler(void *arg, struct tcp_pcb *newpcb)
{
- PCONNECTION_ENDPOINT Connection = arg;
+ PCONNECTION_ENDPOINT Connection = (PCONNECTION_ENDPOINT)arg;
PTDI_BUCKET Bucket;
PLIST_ENTRY Entry;
PIRP Irp;
NTSTATUS Status;
KIRQL OldIrql;
- struct tcp_pcb* OldSocketContext;
DbgPrint("[IP, TCPAcceptEventHandler] Called\n");
@@ -202,22 +204,19 @@
LockObject(Bucket->AssociatedEndpoint, &OldIrql);
+ /* sanity assert...this should never be in anything else but a CLOSED state
*/
+ ASSERT(((struct
tcp_pcb*)Bucket->AssociatedEndpoint->SocketContext)->state == CLOSED);
+
+ /* free socket context created in FileOpenConnection, as we're using a
new one */
+ LibTCPClose(Bucket->AssociatedEndpoint, TRUE);
+
/* free previously created socket context (we don't use it, we use
newpcb) */
- OldSocketContext = Bucket->AssociatedEndpoint->SocketContext;
Bucket->AssociatedEndpoint->SocketContext = newpcb;
- LibTCPAccept(newpcb,
- (struct tcp_pcb*)Connection->SocketContext,
- Bucket->AssociatedEndpoint);
+ LibTCPAccept(newpcb, (PTCP_PCB)Connection->SocketContext,
Bucket->AssociatedEndpoint);
DbgPrint("[IP, TCPAcceptEventHandler] Trying to unlock
Bucket->AssociatedEndpoint\n");
UnlockObject(Bucket->AssociatedEndpoint, OldIrql);
-
- /* sanity assert...this should never be in anything else but a CLOSED state
*/
- ASSERT(((struct tcp_pcb*)OldSocketContext)->state == CLOSED);
-
- /* free socket context created in FileOpenConnection, as we're using a
new one */
- LibTCPClose(OldSocketContext, TRUE);
}
DereferenceObject(Bucket->AssociatedEndpoint);
@@ -270,7 +269,7 @@
("Connection->SocketContext: %x\n",
Connection->SocketContext));
- Status = TCPTranslateError(LibTCPSend(Connection->SocketContext,
+ Status = TCPTranslateError(LibTCPSend(Connection,
SendBuffer,
SendLen, TRUE));
@@ -368,7 +367,7 @@
VOID
TCPConnectEventHandler(void *arg, err_t err)
{
- PCONNECTION_ENDPOINT Connection = arg;
+ PCONNECTION_ENDPOINT Connection = (PCONNECTION_ENDPOINT)arg;
PTDI_BUCKET Bucket;
PLIST_ENTRY Entry;
Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/tcp.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/drive…
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/tcp.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/tcp.c [iso-8859-1] Thu Jul
21 20:58:54 2011
@@ -115,19 +115,19 @@
DbgPrint("[IP, TCPClose] Called for Connection( 0x%x )->SocketConext( 0x%x
)\n", Connection, Connection->SocketContext);
Socket = Connection->SocketContext;
- Connection->SocketContext = NULL;
+ //Connection->SocketContext = NULL;
/* We should not be associated to an address file at this point */
ASSERT(!Connection->AddressFile);
/* Don't try to close again if the other side closed us already */
- if (Socket)
+ if (Connection->SocketContext)
{
FlushAllQueues(Connection, STATUS_CANCELLED);
DbgPrint("[IP, TCPClose] Socket (pcb) = 0x%x\n", Socket);
- LibTCPClose(Socket, FALSE);
+ LibTCPClose(Connection, FALSE);
}
DbgPrint("[IP, TCPClose] Leaving. Connection->RefCount = %d\n",
Connection->RefCount);
@@ -299,7 +299,7 @@
bindaddr.addr = Connection->AddressFile->Address.Address.IPv4Address;
}
- Status = TCPTranslateError(LibTCPBind(Connection->SocketContext,
+ Status = TCPTranslateError(LibTCPBind(Connection,
&bindaddr,
Connection->AddressFile->Port));
@@ -338,7 +338,7 @@
InsertTailList( &Connection->ConnectRequest, &Bucket->Entry );
- Status = TCPTranslateError(LibTCPConnect(Connection->SocketContext,
+ Status = TCPTranslateError(LibTCPConnect(Connection,
&connaddr,
RemotePort));
@@ -372,12 +372,12 @@
{
if (Flags & TDI_DISCONNECT_RELEASE)
{
- Status = TCPTranslateError(LibTCPShutdown(Connection->SocketContext, 0,
1));
+ Status = TCPTranslateError(LibTCPShutdown(Connection, 0, 1));
}
if ((Flags & TDI_DISCONNECT_ABORT) || !Flags)
{
- Status = TCPTranslateError(LibTCPShutdown(Connection->SocketContext, 1,
1));
+ Status = TCPTranslateError(LibTCPShutdown(Connection, 1, 1));
}
}
else
@@ -464,7 +464,7 @@
Connection->SocketContext));
DbgPrint("[IP, TCPSendData] Called\n");
- Status = TCPTranslateError(LibTCPSend(Connection->SocketContext,
+ Status = TCPTranslateError(LibTCPSend(Connection,
BufferData,
SendLength,
FALSE));
Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/drive…
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/CMakeLists.txt [iso-8859-1]
(original)
+++ branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/CMakeLists.txt [iso-8859-1] Thu Jul 21
20:58:54 2011
@@ -1,3 +1,8 @@
+include_directories(
+ BEFORE include
+ ${REACTOS_SOURCE_DIR}/drivers/network/tcpip/include
+ ${REACTOS_SOURCE_DIR}/lib/drivers/lwip/src/include
+ ${REACTOS_SOURCE_DIR}/lib/drivers/lwip/src/include/ipv4)
include_directories(
src/include
Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/include/rosip.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/drive…
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/include/rosip.h [iso-8859-1]
(original)
+++ branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/include/rosip.h [iso-8859-1] Thu
Jul 21 20:58:54 2011
@@ -4,6 +4,9 @@
#include "lwip/tcp.h"
#include "lwip/pbuf.h"
#include "lwip/ip_addr.h"
+#include "tcpip.h"
+
+typedef struct tcp_pcb* PTCP_PCB;
/* External TCP event handlers */
extern void TCPConnectEventHandler(void *arg, const err_t err);
@@ -13,16 +16,17 @@
extern u32_t TCPRecvEventHandler(void *arg, struct pbuf *p);
/* TCP functions */
-struct tcp_pcb *LibTCPSocket(void *arg);
-err_t LibTCPBind(struct tcp_pcb *pcb, struct ip_addr *const ipaddr, const u16_t port);
-struct tcp_pcb *LibTCPListen(struct tcp_pcb *pcb, const u8_t backlog);
-err_t LibTCPSend(struct tcp_pcb *pcb, void *const dataptr, const u16_t len, const int
safe);
-err_t LibTCPConnect(struct tcp_pcb *pcb, struct ip_addr *const ipaddr, const u16_t
port);
-err_t LibTCPShutdown(struct tcp_pcb *pcb, const int shut_rx, const int shut_tx);
-err_t LibTCPClose(struct tcp_pcb *pcb, const int safe);
-err_t LibTCPGetPeerName(struct tcp_pcb *pcb, struct ip_addr *const ipaddr, u16_t *const
port);
-err_t LibTCPGetHostName(struct tcp_pcb *pcb, struct ip_addr *const ipaddr, u16_t *const
port);
-void LibTCPAccept(struct tcp_pcb *pcb, struct tcp_pcb *listen_pcb, void *arg);
+PTCP_PCB LibTCPSocket(void *arg);
+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, 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);
+
+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);
/* IP functions */
void LibIPInsertPacket(void *ifarg, const void *const data, const u32_t size);
Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/drive…
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c [iso-8859-1] (original)
+++ branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c [iso-8859-1] Thu Jul 21
20:58:54 2011
@@ -272,7 +272,7 @@
KEVENT Event;
/* Input */
- struct tcp_pcb *Pcb;
+ PCONNECTION_ENDPOINT Connection;
struct ip_addr *IpAddress;
u16_t Port;
@@ -288,18 +288,20 @@
ASSERT(msg);
- msg->Error = tcp_bind(msg->Pcb, msg->IpAddress, ntohs(msg->Port));
+ msg->Error = tcp_bind((PTCP_PCB)msg->Connection->SocketContext,
+ msg->IpAddress,
+ ntohs(msg->Port));
KeSetEvent(&msg->Event, IO_NO_INCREMENT, FALSE);
}
err_t
-LibTCPBind(struct tcp_pcb *pcb, struct ip_addr *const ipaddr, const u16_t port)
+LibTCPBind(PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t
port)
{
struct bind_callback_msg *msg;
err_t ret;
- if (!pcb)
+ if (!Connection->SocketContext)
return ERR_CLSD;
DbgPrint("[lwIP, LibTCPBind] Called\n");
@@ -308,7 +310,7 @@
if (msg)
{
KeInitializeEvent(&msg->Event, NotificationEvent, FALSE);
- msg->Pcb = pcb;
+ msg->Connection = Connection;
msg->IpAddress = ipaddr;
msg->Port = port;
@@ -319,7 +321,7 @@
else
ret = ERR_CLSD;
- DbgPrint("[lwIP, LibTCPBind] pcb = 0x%x\n", pcb);
+ DbgPrint("[lwIP, LibTCPBind] pcb = 0x%x\n",
Connection->SocketContext);
DbgPrint("[lwIP, LibTCPBind] Done\n");
@@ -337,11 +339,11 @@
KEVENT Event;
/* Input */
- struct tcp_pcb *Pcb;
+ PCONNECTION_ENDPOINT Connection;
u8_t Backlog;
/* Output */
- struct tcp_pcb *NewPcb;
+ PTCP_PCB NewPcb;
};
static
@@ -354,7 +356,7 @@
DbgPrint("[lwIP, LibTCPListenCallback] Called\n");
- msg->NewPcb = tcp_listen_with_backlog(msg->Pcb, msg->Backlog);
+ msg->NewPcb =
tcp_listen_with_backlog((PTCP_PCB)msg->Connection->SocketContext, msg->Backlog);
if (msg->NewPcb)
{
@@ -366,22 +368,22 @@
KeSetEvent(&msg->Event, IO_NO_INCREMENT, FALSE);
}
-struct tcp_pcb *
-LibTCPListen(struct tcp_pcb *pcb, const u8_t backlog)
+PTCP_PCB
+LibTCPListen(PCONNECTION_ENDPOINT Connection, const u8_t backlog)
{
struct listen_callback_msg *msg;
- void *ret;
-
- DbgPrint("[lwIP, LibTCPListen] Called on pcb = 0x%x\n", pcb);
-
- if (!pcb)
+ PTCP_PCB ret;
+
+ DbgPrint("[lwIP, LibTCPListen] Called on pcb = 0x%x\n",
Connection->SocketContext);
+
+ if (!Connection->SocketContext)
return NULL;
msg = ExAllocatePool(NonPagedPool, sizeof(struct listen_callback_msg));
if (msg)
{
KeInitializeEvent(&msg->Event, NotificationEvent, FALSE);
- msg->Pcb = pcb;
+ msg->Connection = Connection;
msg->Backlog = backlog;
tcpip_callback_with_block(LibTCPListenCallback, msg, 1);
@@ -392,7 +394,7 @@
ret = NULL;
DbgPrint("[lwIP, LibTCPListen] pcb = 0x%x, newpcb = 0x%x, sizeof(pcb) = %d
\n",
- pcb, ret, sizeof(struct tcp_pcb));
+ Connection->SocketContext, ret, sizeof(struct tcp_pcb));
DbgPrint("[lwIP, LibTCPListen] Done\n");
@@ -410,7 +412,7 @@
KEVENT Event;
/* Input */
- struct tcp_pcb *Pcb;
+ PCONNECTION_ENDPOINT Connection;
void *Data;
u16_t DataLength;
@@ -426,26 +428,29 @@
ASSERT(msg);
- if (tcp_sndbuf(msg->Pcb) < msg->DataLength)
+ if (tcp_sndbuf((PTCP_PCB)msg->Connection->SocketContext) <
msg->DataLength)
{
msg->Error = ERR_INPROGRESS;
}
else
{
- msg->Error = tcp_write(msg->Pcb, msg->Data, msg->DataLength,
TCP_WRITE_FLAG_COPY);
-
- tcp_output(msg->Pcb);
+ msg->Error = tcp_write((PTCP_PCB)msg->Connection->SocketContext,
+ msg->Data,
+ msg->DataLength,
+ TCP_WRITE_FLAG_COPY);
+
+ tcp_output((PTCP_PCB)msg->Connection->SocketContext);
}
KeSetEvent(&msg->Event, IO_NO_INCREMENT, FALSE);
}
err_t
-LibTCPSend(struct tcp_pcb *pcb, void *const dataptr, const u16_t len, const int safe)
+LibTCPSend(PCONNECTION_ENDPOINT Connection, void *const dataptr, const u16_t len, const
int safe)
{
err_t ret;
- if (!pcb)
+ if (!Connection->SocketContext)
return ERR_CLSD;
/*
@@ -455,14 +460,14 @@
*/
if (safe)
{
- if (tcp_sndbuf(pcb) < len)
+ if (tcp_sndbuf((PTCP_PCB)Connection->SocketContext) < len)
{
ret = ERR_INPROGRESS;
}
else
{
- ret = tcp_write(pcb, dataptr, len, TCP_WRITE_FLAG_COPY);
- tcp_output(pcb);
+ ret = tcp_write((PTCP_PCB)Connection->SocketContext, dataptr, len,
TCP_WRITE_FLAG_COPY);
+ tcp_output((PTCP_PCB)Connection->SocketContext);
}
return ret;
@@ -475,7 +480,7 @@
if (msg)
{
KeInitializeEvent(&msg->Event, NotificationEvent, FALSE);
- msg->Pcb = pcb;
+ msg->Connection = Connection;
msg->Data = dataptr;
msg->DataLength = len;
@@ -486,7 +491,7 @@
else
ret = ERR_CLSD;
- DbgPrint("[lwIP, LibTCPSend] pcb = 0x%x\n", pcb);
+ DbgPrint("[lwIP, LibTCPSend] pcb = 0x%x\n",
Connection->SocketContext);
ExFreePool(msg);
@@ -503,7 +508,7 @@
KEVENT Event;
/* Input */
- struct tcp_pcb *Pcb;
+ PCONNECTION_ENDPOINT Connection;
struct ip_addr *IpAddress;
u16_t Port;
@@ -521,10 +526,13 @@
ASSERT(arg);
- tcp_recv(msg->Pcb, InternalRecvEventHandler);
- tcp_sent(msg->Pcb, InternalSendEventHandler);
-
- err_t Error = tcp_connect(msg->Pcb, msg->IpAddress, ntohs(msg->Port),
InternalConnectEventHandler);
+ tcp_recv((PTCP_PCB)msg->Connection->SocketContext, InternalRecvEventHandler);
+ tcp_sent((PTCP_PCB)msg->Connection->SocketContext, InternalSendEventHandler);
+
+ err_t Error = tcp_connect((PTCP_PCB)msg->Connection->SocketContext,
+ msg->IpAddress, ntohs(msg->Port),
+ InternalConnectEventHandler);
+
msg->Error = Error == ERR_OK ? ERR_INPROGRESS : Error;
KeSetEvent(&msg->Event, IO_NO_INCREMENT, FALSE);
@@ -533,21 +541,21 @@
}
err_t
-LibTCPConnect(struct tcp_pcb *pcb, struct ip_addr *const ipaddr, const u16_t port)
+LibTCPConnect(PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t
port)
{
struct connect_callback_msg *msg;
err_t ret;
DbgPrint("[lwIP, LibTCPConnect] Called\n");
- if (!pcb)
+ if (!Connection->SocketContext)
return ERR_CLSD;
msg = ExAllocatePool(NonPagedPool, sizeof(struct connect_callback_msg));
if (msg)
{
KeInitializeEvent(&msg->Event, NotificationEvent, FALSE);
- msg->Pcb = pcb;
+ msg->Connection = Connection;
msg->IpAddress = ipaddr;
msg->Port = port;
@@ -562,7 +570,7 @@
ExFreePool(msg);
- DbgPrint("[lwIP, LibTCPConnect] pcb = 0x%x\n", pcb);
+ DbgPrint("[lwIP, LibTCPConnect] pcb = 0x%x\n",
Connection->SocketContext);
DbgPrint("[lwIP, LibTCPConnect] Done\n");
@@ -578,7 +586,7 @@
KEVENT Event;
/* Input */
- struct tcp_pcb *Pcb;
+ PCONNECTION_ENDPOINT Connection;
int shut_rx;
int shut_tx;
@@ -597,9 +605,12 @@
it means lwIP will take care of it anyway and if it does so before us it will
cause memory corruption.
*/
- if ((msg->Pcb->state == ESTABLISHED) || (msg->Pcb->state == SYN_RCVD))
- {
- msg->Error = tcp_shutdown(msg->Pcb, msg->shut_rx, msg->shut_tx);
+ if ((((PTCP_PCB)msg->Connection->SocketContext)->state == ESTABLISHED) ||
+ (((PTCP_PCB)msg->Connection->SocketContext)->state == SYN_RCVD))
+ {
+ msg->Error =
+ tcp_shutdown((PTCP_PCB)msg->Connection->SocketContext,
+ msg->shut_rx, msg->shut_tx);
}
else
msg->Error = ERR_OK;
@@ -608,27 +619,29 @@
}
err_t
-LibTCPShutdown(struct tcp_pcb *pcb, const int shut_rx, const int shut_tx)
+LibTCPShutdown(PCONNECTION_ENDPOINT Connection, const int shut_rx, const int shut_tx)
{
struct shutdown_callback_msg *msg;
err_t ret;
- DbgPrint("[lwIP, LibTCPShutdown] Called on pcb = 0x%x, rx = %d, tx = %d\n",
pcb, shut_rx, shut_tx);
-
- if (!pcb)
+ DbgPrint("[lwIP, LibTCPShutdown] Called on pcb = 0x%x, rx = %d, tx =
%d\n",
+ Connection->SocketContext, shut_rx, shut_tx);
+
+ if (!Connection->SocketContext)
{
DbgPrint("[lwIP, LibTCPShutdown] Done... NO pcb\n");
return ERR_CLSD;
}
- DbgPrint("[lwIP, LibTCPShutdown] pcb->state = %s\n",
tcp_state_str[pcb->state]);
+ DbgPrint("[lwIP, LibTCPShutdown] pcb->state = %s\n",
+ tcp_state_str[((PTCP_PCB)Connection->SocketContext)->state]);
msg = ExAllocatePool(NonPagedPool, sizeof(struct shutdown_callback_msg));
if (msg)
{
KeInitializeEvent(&msg->Event, NotificationEvent, FALSE);
- msg->Pcb = pcb;
+ msg->Connection = Connection;
msg->shut_rx = shut_rx;
msg->shut_tx = shut_tx;
@@ -655,7 +668,7 @@
KEVENT Event;
/* Input */
- struct tcp_pcb *Pcb;
+ PCONNECTION_ENDPOINT Connection;
/* Output */
err_t Error;
@@ -663,49 +676,9 @@
static
void
-LibTCPCloseCallback(void *arg)
-{
- struct close_callback_msg *msg = arg;
-
- if (msg->Pcb->state == CLOSED)
- {
- DbgPrint("[lwIP, LibTCPCloseCallback] Connection was closed on us\n");
- msg->Error = ERR_OK;
- }
-
- if (msg->Pcb->state == LISTEN)
- {
- DbgPrint("[lwIP, LibTCPCloseCallback] Closing a listener\n");
- msg->Error = tcp_close(msg->Pcb);
- }
- else
- {
- DbgPrint("[lwIP, LibTCPCloseCallback] Aborting a connection\n");
- tcp_abort(msg->Pcb);
- msg->Error = ERR_OK;
- }
-
- KeSetEvent(&msg->Event, IO_NO_INCREMENT, FALSE);
-}
-
-err_t
-//LibTCPClose(struct tcp_pcb *pcb, const int safe)
-LibTCPClose(struct tcp_pcb *pcb, const int safe)
-{
- err_t ret;
-
- DbgPrint("[lwIP, LibTCPClose] Called on pcb = 0x%x\n", pcb);
-
- if (!pcb)
- {
- DbgPrint("[lwIP, LibTCPClose] Done... NO pcb\n");
- return ERR_CLSD;
- }
-
- DbgPrint("[lwIP, LibTCPClose] pcb->state = %s\n",
tcp_state_str[pcb->state]);
-
+CloseCallbacks(struct tcp_pcb *pcb)
+{
tcp_arg(pcb, NULL);
-
/*
if this pcb is not in LISTEN state than it has
valid recv, send and err callbacks to cancel
@@ -718,6 +691,58 @@
}
tcp_accept(pcb, NULL);
+}
+
+static
+void
+LibTCPCloseCallback(void *arg)
+{
+ struct close_callback_msg *msg = arg;
+
+ DbgPrint("[lwIP, LibTCPCloseCallback] pcb = 0x%x\n",
(PTCP_PCB)msg->Connection->SocketContext);
+
+ if (!msg->Connection->SocketContext)
+ {
+ DbgPrint("[lwIP, LibTCPCloseCallback] NULL pcb...bail, bail!!!\n");
+
+ ASSERT(FALSE);
+
+ msg->Error = ERR_OK;
+ return;
+ }
+
+ CloseCallbacks((PTCP_PCB)msg->Connection->SocketContext);
+
+ if (((PTCP_PCB)msg->Connection->SocketContext)->state == LISTEN)
+ {
+ DbgPrint("[lwIP, LibTCPCloseCallback] Closing a listener\n");
+ msg->Error = tcp_close((PTCP_PCB)msg->Connection->SocketContext);
+ }
+ else
+ {
+ DbgPrint("[lwIP, LibTCPCloseCallback] Aborting a connection\n");
+ tcp_abort((PTCP_PCB)msg->Connection->SocketContext);
+ msg->Error = ERR_OK;
+ }
+
+ KeSetEvent(&msg->Event, IO_NO_INCREMENT, FALSE);
+}
+
+err_t
+LibTCPClose(PCONNECTION_ENDPOINT Connection, const int safe)
+{
+ err_t ret;
+
+ DbgPrint("[lwIP, LibTCPClose] Called on pcb = 0x%x\n",
Connection->SocketContext);
+
+ if (!Connection->SocketContext)
+ {
+ DbgPrint("[lwIP, LibTCPClose] Done... NO pcb\n");
+ return ERR_CLSD;
+ }
+
+ DbgPrint("[lwIP, LibTCPClose] pcb->state = %s\n",
+ tcp_state_str[((PTCP_PCB)Connection->SocketContext)->state]);
/*
If we're being called from a handler it means we're in the conetxt of
teh tcpip
@@ -726,15 +751,16 @@
*/
if (safe)
{
- if (pcb->state == LISTEN)
+ CloseCallbacks((PTCP_PCB)Connection->SocketContext);
+ if ( ((PTCP_PCB)Connection->SocketContext)->state == LISTEN )
{
DbgPrint("[lwIP, LibTCPClose] Closing a listener\n");
- ret = tcp_close(pcb);
+ ret = tcp_close((PTCP_PCB)Connection->SocketContext);
}
else
{
DbgPrint("[lwIP, LibTCPClose] Aborting a connection\n");
- tcp_abort(pcb);
+ tcp_abort((PTCP_PCB)Connection->SocketContext);
ret = ERR_OK;
}
@@ -749,7 +775,7 @@
{
KeInitializeEvent(&msg->Event, NotificationEvent, FALSE);
- msg->Pcb = pcb;
+ msg->Connection = Connection;
tcpip_callback_with_block(LibTCPCloseCallback, msg, 1);
@@ -772,7 +798,7 @@
}
void
-LibTCPAccept(struct tcp_pcb *pcb, struct tcp_pcb *listen_pcb, void *arg)
+LibTCPAccept(PTCP_PCB pcb, struct tcp_pcb *listen_pcb, void *arg)
{
DbgPrint("[lwIP, LibTCPAccept] Called. (pcb, arg) = (0x%x, 0x%x)\n", pcb,
arg);
@@ -790,7 +816,7 @@
}
err_t
-LibTCPGetHostName(struct tcp_pcb *pcb, struct ip_addr *const ipaddr, u16_t *const port)
+LibTCPGetHostName(PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
{
DbgPrint("[lwIP, LibTCPGetHostName] Called. pcb = (0x%x)\n", pcb);
@@ -808,7 +834,7 @@
}
err_t
-LibTCPGetPeerName(struct tcp_pcb *pcb, struct ip_addr * const ipaddr, u16_t * const
port)
+LibTCPGetPeerName(PTCP_PCB pcb, struct ip_addr * const ipaddr, u16_t * const port)
{
DbgPrint("[lwIP, LibTCPGetPeerName] pcb = (0x%x)\n", pcb);