From dcf2e2182934291e7312993c78d3d3c5f72597d5 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 31 Jul 2023 16:25:45 -0700 Subject: Seems to work. We have a last ditch effort. It turns out that the SocketTcp class automatically closes sockets when it realizes they're at the end, it doesn't wait for us to call close. That could be a problem, we may need something in between, but at least we can detect it and clean it up. --- src/stable/server.cpp | 35 ++++++++++++++++++++++------------- src/stable/server.h | 1 - 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/stable/server.cpp b/src/stable/server.cpp index 160b3eb..3aa8a34 100644 --- a/src/stable/server.cpp +++ b/src/stable/server.cpp @@ -204,13 +204,29 @@ void Bu::Server::addClient( const Bu::ServerSocket *pSrv, Bu::Socket *pSocket ) ); { Bu::MutexLocker l( mClients ); - if( hClients.has( iFdCli ) ) + if( hClients.has( iFdCli ) || hSockets.has( iFdCli ) ) { - Bu::println("!!!!!!!!! hClients has %1 already.").arg( iFdCli ); - } - if( hSockets.has( iFdCli ) ) - { - Bu::println("!!!!!!!!! hSockets has %1 already.").arg( iFdCli ); + // Oops, it got closed and we haven't managed to get to it yet. + // We're not going to be able to write anyhting, we may as well + // just clean up. + // + // This can happen in a variety of situations, but mostly when + // we get a disconnect followed immediately be a reconnect. + struct epoll_event ev; + epoll_ctl( pCore->fdRead, EPOLL_CTL_DEL, iFdCli, &ev ); + epoll_ctl( pCore->fdWrite, EPOLL_CTL_DEL, iFdCli, &ev ); + Client *pOldClient = hClients.get( iFdCli ); + Socket *pOldSocket = hSockets.get( iFdCli ); + + hClients.erase( iFdCli ); + hSockets.erase( iFdCli ); + + onClosedConnection( pOldClient ); + pOldClient->close(); + pOldSocket->close(); + + delete pOldClient; + delete pOldSocket; } hClients.insert( iFdCli, pClient ); hSockets.insert( iFdCli, pSocket ); @@ -558,13 +574,6 @@ void Bu::Server::IoWorker::handleWrite( Client *pClient, Socket *pSocket ) } } -void Bu::Server::IoWorker::close( Bu::Socket *pSocket ) -{ -// Bu::Server::fd iFd; -// pSocket->getFd( iFd ); -// rSrv.closeClient( iFd ); -} - ///////// // ClientWorker //// diff --git a/src/stable/server.h b/src/stable/server.h index a839968..9fb8282 100644 --- a/src/stable/server.h +++ b/src/stable/server.h @@ -161,7 +161,6 @@ namespace Bu private: void handleRead( Client *pClient, Socket *pSocket ); void handleWrite( Client *pClient, Socket *pSocket ); - void close( Socket *pSocket ); private: Server &rSrv; -- cgit v1.2.3