From e73868bc5a4ef514e8059e345e8798b2a1d8328c Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Fri, 11 Sep 2015 19:02:44 -0400 Subject: [PATCH] various segfault fixes --- netcon/NetconEthernetTap.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/netcon/NetconEthernetTap.cpp b/netcon/NetconEthernetTap.cpp index 76f95bb08..53818b92e 100644 --- a/netcon/NetconEthernetTap.cpp +++ b/netcon/NetconEthernetTap.cpp @@ -334,6 +334,7 @@ void NetconEthernetTap::threadMain() void NetconEthernetTap::phyOnSocketPairEndpointClose(PhySocket *sock, void **uptr) { fprintf(stderr, "phyOnSocketPairEndpointClose\n"); + _phy.setNotifyWritable(sock, false); NetconClient *client = (NetconClient*)*uptr; closeConnection(client->getConnection(sock)); } @@ -369,12 +370,15 @@ void NetconEthernetTap::phyOnTcpWritable(PhySocket *sock,void **uptr) {} void NetconEthernetTap::phyOnUnixAccept(PhySocket *sockL,PhySocket *sockN,void **uptrL,void **uptrN) { + fprintf(stderr, "phyOnUnixAccept\n"); NetconClient *newClient = new NetconClient(); - newClient->addConnection(RPC, *uptrN); + newClient->rpc = newClient->addConnection(RPC, sockN); + *uptrN = newClient; } void NetconEthernetTap::phyOnUnixClose(PhySocket *sock,void **uptr) { + _phy.setNotifyWritable(sock, false); fprintf(stderr, "phyOnUnixClose\n"); closeClient(((NetconClient*)*uptr)); } @@ -383,6 +387,9 @@ void NetconEthernetTap::phyOnUnixData(PhySocket *sock,void **uptr,void *data,uns { unsigned char *buf = (unsigned char*)data; NetconClient *client = (NetconClient*)*uptr; + if(!client) + fprintf(stderr, "!client\n"); + switch(buf[0]) { case RPC_SOCKET: @@ -653,11 +660,13 @@ void NetconEthernetTap::handle_socket(NetconClient *client, struct socket_st* so { struct tcp_pcb *pcb = lwipstack->tcp_new(); if(pcb != NULL) { - int *their_fd = NULL; - NetconConnection *new_conn = client->addConnection(BUFFER, _phy.createSocketPair(*their_fd, client)); - new_conn->their_fd = *their_fd; + int their_fd; + NetconConnection *new_conn = client->addConnection(BUFFER, _phy.createSocketPair(their_fd, client)); + new_conn->their_fd = their_fd; new_conn->pcb = pcb; - sock_fd_write(_phy.getDescriptor(client->rpc->sock), *their_fd); + PhySocket *sock = client->rpc->sock; + int send_fd = _phy.getDescriptor(sock); + sock_fd_write(send_fd, their_fd); client->unmapped_conn = new_conn; } else { @@ -673,10 +682,11 @@ void NetconEthernetTap::handle_connect(NetconClient *client, struct connect_st* int conn_port = lwipstack->ntohs(connaddr->sin_port); ip_addr_t conn_addr = convert_ip((struct sockaddr_in *)&connect_rpc->__addr); + fprintf(stderr, "getConnectionByTheirFD(%d)\n", connect_rpc->__fd); NetconConnection *c = client->getConnectionByTheirFD(connect_rpc->__fd); if(c!= NULL) { - lwipstack->tcp_sent(c->pcb, NetconEthernetTap::nc_sent); // FIXME: Move? + lwipstack->tcp_sent(c->pcb, nc_sent); // FIXME: Move? lwipstack->tcp_recv(c->pcb, nc_recved); lwipstack->tcp_err(c->pcb, nc_err); lwipstack->tcp_poll(c->pcb, nc_poll, APPLICATION_POLL_FREQ);