Fixed double-close bug

This commit is contained in:
Joseph Henry 2016-01-13 13:55:11 -08:00
parent e8e6a4702b
commit 7bba867ce8

View file

@ -54,7 +54,7 @@
#include "common.inc.c" #include "common.inc.c"
#include "RPC.h" #include "RPC.h"
#define APPLICATION_POLL_FREQ 20 #define APPLICATION_POLL_FREQ 2
#define ZT_LWIP_TCP_TIMER_INTERVAL 5 #define ZT_LWIP_TCP_TIMER_INTERVAL 5
#define STATUS_TMR_INTERVAL 250 // How often we check connection statuses (in ms) #define STATUS_TMR_INTERVAL 250 // How often we check connection statuses (in ms)
#define DEFAULT_READ_BUFFER_SIZE 1024 * 1024 #define DEFAULT_READ_BUFFER_SIZE 1024 * 1024
@ -348,6 +348,7 @@ void NetconEthernetTap::threadMain()
prev_status_time = now; prev_status_time = now;
status_remaining = STATUS_TMR_INTERVAL - since_status; status_remaining = STATUS_TMR_INTERVAL - since_status;
dwr(MSG_DEBUG," tap_thread(): tcp\\jobs = {%d, %d}\n", tcp_connections.size(), jobmap.size()); dwr(MSG_DEBUG," tap_thread(): tcp\\jobs = {%d, %d}\n", tcp_connections.size(), jobmap.size());
for(size_t i=0; i<tcp_connections.size(); i++) { for(size_t i=0; i<tcp_connections.size(); i++) {
@ -372,6 +373,7 @@ void NetconEthernetTap::threadMain()
phyOnUnixData(tcp_connections[i]->sock,_phy.getuptr(tcp_connections[i]->sock),&tmpbuf,BUF_SZ); phyOnUnixData(tcp_connections[i]->sock,_phy.getuptr(tcp_connections[i]->sock),&tmpbuf,BUF_SZ);
} }
} }
} }
// Main TCP/ETHARP timer section // Main TCP/ETHARP timer section
if (since_tcp >= ZT_LWIP_TCP_TIMER_INTERVAL) { if (since_tcp >= ZT_LWIP_TCP_TIMER_INTERVAL) {
@ -448,7 +450,11 @@ void NetconEthernetTap::closeConnection(PhySocket *sock)
return; return;
} }
TcpConnection *conn = getConnection(sock); TcpConnection *conn = getConnection(sock);
if(!conn || !conn->pcb) if(!conn)
return;
else
removeConnection(conn);
if(!conn->pcb)
return; return;
if(conn->pcb->state == SYN_SENT) { if(conn->pcb->state == SYN_SENT) {
dwr(MSG_DEBUG," closeConnection(): invalid PCB state (SYN_SENT) -- cannot close right now\n"); dwr(MSG_DEBUG," closeConnection(): invalid PCB state (SYN_SENT) -- cannot close right now\n");
@ -457,7 +463,6 @@ void NetconEthernetTap::closeConnection(PhySocket *sock)
if(lwipstack->_tcp_close(conn->pcb) != ERR_OK) { if(lwipstack->_tcp_close(conn->pcb) != ERR_OK) {
dwr(MSG_ERROR," closeConnection(): Error while calling tcp_close()\n"); dwr(MSG_ERROR," closeConnection(): Error while calling tcp_close()\n");
} }
removeConnection(conn);
if(!sock) if(!sock)
return; return;
close(_phy.getDescriptor(sock)); // close underlying fd close(_phy.getDescriptor(sock)); // close underlying fd
@ -922,6 +927,7 @@ void NetconEthernetTap::nc_err(void *arg, err_t err)
*/ */
err_t NetconEthernetTap::nc_poll(void* arg, struct tcp_pcb *tpcb) err_t NetconEthernetTap::nc_poll(void* arg, struct tcp_pcb *tpcb)
{ {
dwr(MSG_DEBUG," nc_poll()\n");
return ERR_OK; return ERR_OK;
} }