From 356e39f4b71af03a01c60b020617bf759c760854 Mon Sep 17 00:00:00 2001 From: Claudiu Mihail Date: Mon, 18 Jul 2011 19:20:12 +0000 Subject: [PATCH] [lwIP] - rewrite fix to race condition crash this time in a correct and much more elegant manner svn path=/branches/GSoC_2011/TcpIpDriver/; revision=52730 --- lib/drivers/lwip/src/rostcp.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/drivers/lwip/src/rostcp.c b/lib/drivers/lwip/src/rostcp.c index bd03e66640d..cd73eb56464 100755 --- a/lib/drivers/lwip/src/rostcp.c +++ b/lib/drivers/lwip/src/rostcp.c @@ -587,8 +587,13 @@ void LibTCPShutdownCallback(void *arg) { struct shutdown_callback_msg *msg = arg; - - msg->Error = tcp_shutdown(msg->Pcb, msg->shut_rx, msg->shut_tx); + + if (msg->Pcb->state == ESTABLISHED || msg->Pcb->state == SYN_RCVD) + { + msg->Error = tcp_shutdown(msg->Pcb, msg->shut_rx, msg->shut_tx); + } + else + msg->Error = ERR_OK; KeSetEvent(&msg->Event, IO_NO_INCREMENT, FALSE); } @@ -599,7 +604,7 @@ LibTCPShutdown(struct tcp_pcb *pcb, const int shut_rx, const int shut_tx) struct shutdown_callback_msg *msg; err_t ret; - DbgPrint("[lwIP, LibTCPShutdown] Called on pcb = 0x%x\n", pcb); + DbgPrint("[lwIP, LibTCPShutdown] Called on pcb = 0x%x with rx = %d, tx = %d\n", pcb, shut_rx, shut_tx); if (!pcb) { @@ -607,7 +612,7 @@ LibTCPShutdown(struct tcp_pcb *pcb, const int shut_rx, const int shut_tx) return ERR_CLSD; } - DbgPrint("[lwIP, LibTCPClose] pcb->state = %s\n", tcp_state_str[pcb->state]); + DbgPrint("[lwIP, LibTCPShutdown] pcb->state = %s\n", tcp_state_str[pcb->state]); msg = ExAllocatePool(NonPagedPool, sizeof(struct shutdown_callback_msg)); if (msg) @@ -658,19 +663,18 @@ LibTCPCloseCallback(void *arg) DbgPrint("[lwIP, LibTCPCloseCallback] Closing a listener\n"); msg->Error = tcp_close(msg->Pcb); } - else if (msg->Pcb->state != LAST_ACK && msg->Pcb->state != CLOSED) + else { DbgPrint("[lwIP, LibTCPCloseCallback] Aborting a connection\n"); tcp_abort(msg->Pcb); msg->Error = ERR_OK; } - else - 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; @@ -712,14 +716,12 @@ LibTCPClose(struct tcp_pcb *pcb, const int safe) DbgPrint("[lwIP, LibTCPClose] Closing a listener\n"); ret = tcp_close(pcb); } - else if (pcb->state != LAST_ACK && pcb->state != CLOSED) + else { DbgPrint("[lwIP, LibTCPClose] Aborting a connection\n"); tcp_abort(pcb); ret = ERR_OK; } - else - ret = ERR_OK; return ret; }