Fixed pcb->state == CLOSE_WAIT bug

This commit is contained in:
Joseph Henry 2016-01-15 11:18:26 -08:00
parent 323d40a560
commit 35fb602dff
3 changed files with 13 additions and 20 deletions

View File

@ -439,8 +439,8 @@ void NetconEthernetTap::closeConnection(PhySocket *sock)
removeConnection(conn); removeConnection(conn);
if(!conn->pcb) if(!conn->pcb)
return; return;
if(conn->pcb->state == SYN_SENT) { if(conn->pcb->state == SYN_SENT || conn->pcb->state == CLOSE_WAIT) {
dwr(MSG_DEBUG," closeConnection(): invalid PCB state (SYN_SENT) -- cannot close right now\n"); dwr(MSG_DEBUG," closeConnection(): invalid PCB state for this operation. ignoring.\n");
return; return;
} }
dwr(MSG_DEBUG," closeConnection(): PCB->state = %d\n", conn->pcb->state); dwr(MSG_DEBUG," closeConnection(): PCB->state = %d\n", conn->pcb->state);
@ -488,7 +488,6 @@ void NetconEthernetTap::phyOnUnixWritable(PhySocket *sock,void **uptr)
} else { } else {
perror("\n"); perror("\n");
dwr(MSG_ERROR," phyOnUnixWritable(): errno = %d\n", errno); dwr(MSG_ERROR," phyOnUnixWritable(): errno = %d\n", errno);
dwr(MSG_ERROR," phyOnUnixWritable(): no data written to stream <%x>\n", conn->sock);
} }
} }
@ -734,9 +733,8 @@ err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *PCB, struct pbuf *
if(p == NULL) { if(p == NULL) {
if(l->conn && !l->conn->listening) { if(l->conn && !l->conn->listening) {
dwr(MSG_INFO," nc_recved(): closing connection\n"); dwr(MSG_INFO," nc_recved(): closing connection\n");
if(l->tap->lwipstack->_tcp_close(l->conn->pcb) != ERR_OK) { //if(l->tap->lwipstack->_tcp_close(l->conn->pcb) != ERR_OK)
dwr(MSG_ERROR," nc_recved(): error while calling tcp_close()\n"); // dwr(MSG_ERROR," nc_recved(): error while calling tcp_close()\n");
}
l->tap->closeConnection(l->conn->sock); l->tap->closeConnection(l->conn->sock);
return ERR_ABRT; return ERR_ABRT;
} }
@ -758,7 +756,7 @@ err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *PCB, struct pbuf *
tot += len; tot += len;
} }
if(tot) if(tot)
l->tap->_phy.setNotifyWritable(l->conn->sock, true); // Signal that we're interested in knowing when we can write l->tap->_phy.setNotifyWritable(l->conn->sock, true);
l->tap->lwipstack->_pbuf_free(q); l->tap->lwipstack->_pbuf_free(q);
return ERR_OK; return ERR_OK;
} }
@ -913,7 +911,7 @@ void NetconEthernetTap::handleBind(PhySocket *sock, PhySocket *rpcSock, void **u
sendReturnValue(rpcSock, -1, EINVAL); sendReturnValue(rpcSock, -1, EINVAL);
} }
} else { } else {
dwr(MSG_ERROR," handleBind(): can't locate connection for PCB\n"); dwr(MSG_ERROR," handleBind(): unable to locate TcpConnection.\n");
sendReturnValue(rpcSock, -1, EBADF); sendReturnValue(rpcSock, -1, EBADF);
} }
} }
@ -922,7 +920,7 @@ void NetconEthernetTap::handleListen(PhySocket *sock, PhySocket *rpcSock, void *
{ {
TcpConnection *conn = getConnection(sock); TcpConnection *conn = getConnection(sock);
if(!conn){ if(!conn){
dwr(MSG_ERROR," handleListen(): unable to locate connection object\n"); dwr(MSG_ERROR," handleListen(): unable to locate TcpConnection.\n");
sendReturnValue(rpcSock, -1, EBADF); sendReturnValue(rpcSock, -1, EBADF);
return; return;
} }
@ -1055,18 +1053,16 @@ void NetconEthernetTap::handleWrite(TcpConnection *conn)
} }
// How much we are currently allowed to write to the connection // How much we are currently allowed to write to the connection
int err, sz, r, sndbuf = conn->pcb->snd_buf; int err, sz, r, sndbuf = conn->pcb->snd_buf;
if(sndbuf == 0) { if(!sndbuf) {
/* PCB send buffer is full,turn off readability notifications for the /* PCB send buffer is full, turn off readability notifications for the
corresponding PhySocket until nc_sent() is called and confirms that there is corresponding PhySocket until nc_sent() is called and confirms that there is
now space on the buffer */ now space on the buffer */
dwr(MSG_DEBUG," handleWrite(): sndbuf == 0, LWIP stack is full\n"); dwr(MSG_DEBUG," handleWrite(): sndbuf == 0, LWIP stack is full\n");
_phy.setNotifyReadable(conn->sock, false); _phy.setNotifyReadable(conn->sock, false);
return; return;
} }
if(conn->txsz <= 0) { if(conn->txsz <= 0)
dwr(MSG_DEBUG,"handleWrite(): conn->txsz <= 0, nothing in buffer to write\n"); return; // Nothing to write
return;
}
if(!conn->listening) if(!conn->listening)
lwipstack->_tcp_output(conn->pcb); lwipstack->_tcp_output(conn->pcb);
@ -1080,7 +1076,7 @@ void NetconEthernetTap::handleWrite(TcpConnection *conn)
if(err != ERR_OK) { if(err != ERR_OK) {
dwr(MSG_ERROR," handleWrite(): error while writing to PCB, (err = %d)\n", err); dwr(MSG_ERROR," handleWrite(): error while writing to PCB, (err = %d)\n", err);
if(err == -1) if(err == -1)
dwr(MSG_DEBUG," handleWrite(): possibly out of memory\n"); dwr(MSG_DEBUG," handleWrite(): out of memory\n");
return; return;
} else { } else {
sz = (conn->txsz)-r; sz = (conn->txsz)-r;

View File

@ -46,11 +46,8 @@ extern "C" {
#endif #endif
int get_retval(int); int get_retval(int);
//#ifdef NETCON_INTERCEPT
int rpc_join(const char * sockname); int rpc_join(const char * sockname);
int rpc_send_command(char *path, int cmd, int forfd, void *data, int len); int rpc_send_command(char *path, int cmd, int forfd, void *data, int len);
//#endif
int get_new_fd(int sock); int get_new_fd(int sock);
ssize_t sock_fd_write(int sock, int fd); ssize_t sock_fd_write(int sock, int fd);

View File

@ -42,7 +42,7 @@
#ifndef _COMMON_H #ifndef _COMMON_H
#define _COMMON_H 1 #define _COMMON_H 1
#define DEBUG_LEVEL 0 #define DEBUG_LEVEL 4
#define MSG_TRANSFER 1 // RX/TX specific statements #define MSG_TRANSFER 1 // RX/TX specific statements
#define MSG_ERROR 2 // Errors #define MSG_ERROR 2 // Errors