Author: cmihail Date: Mon Jul 18 19:20:12 2011 New Revision: 52730
URL: http://svn.reactos.org/svn/reactos?rev=52730&view=rev Log: [lwIP] - rewrite fix to race condition crash this time in a correct and much more elegant manner
Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c
Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/driver... ============================================================================== --- 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] Mon Jul 18 19:20:12 2011 @@ -587,8 +587,13 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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; }