From 14a460c60b162aefaf1798c71ac790ad574e739f Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 12 Mar 2010 16:21:25 +0000 Subject: The server and multiserver now support a shutdown() function which calls onCloseConnection on each client before cleaning it up, allowing for smooth cleanup. Later we may want to add a nicer version with a timeout for pending data to be transmitted and the like. This one is pretty harsh. --- src/multiserver.cpp | 5 +++++ src/multiserver.h | 2 ++ src/server.cpp | 28 +++++++++++++++++++--------- src/server.h | 2 ++ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/multiserver.cpp b/src/multiserver.cpp index ad7855a..dd2da3b 100644 --- a/src/multiserver.cpp +++ b/src/multiserver.cpp @@ -43,3 +43,8 @@ void Bu::MultiServer::onClosedConnection( Bu::Client *pClient ) delete pClient->getProtocol(); } +void Bu::MultiServer::shutdown() +{ + Bu::Server::shutdown(); +} + diff --git a/src/multiserver.h b/src/multiserver.h index 2938e0b..fc8305f 100644 --- a/src/multiserver.h +++ b/src/multiserver.h @@ -45,6 +45,8 @@ namespace Bu virtual void onNewConnection( Client *pClient, int nPort ); virtual void onClosedConnection( Client *pClient ); + void shutdown(); + private: Bu::Hash hProtos; }; diff --git a/src/server.cpp b/src/server.cpp index 8bc1767..80ed509 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -23,15 +23,7 @@ Bu::Server::Server() : Bu::Server::~Server() { - for( SrvHash::iterator i = hServers.begin(); i != hServers.end(); i++ ) - { - delete *i; - } - - for( ClientHash::iterator i = hClients.begin(); i != hClients.end(); i++ ) - { - delete *i; - } + shutdown(); } void Bu::Server::addPort( int nPort, int nPoolSize ) @@ -185,3 +177,21 @@ void Bu::Server::tick() } } +void Bu::Server::shutdown() +{ + for( SrvHash::iterator i = hServers.begin(); i != hServers.end(); i++ ) + { + delete *i; + } + + hServers.clear(); + + for( ClientHash::iterator i = hClients.begin(); i != hClients.end(); i++ ) + { + onClosedConnection( *i ); + delete *i; + } + + hClients.clear(); +} + diff --git a/src/server.h b/src/server.h index f4b2da6..d83c346 100644 --- a/src/server.h +++ b/src/server.h @@ -68,6 +68,8 @@ namespace Bu virtual void onNewConnection( Client *pClient, int nPort )=0; virtual void onClosedConnection( Client *pClient )=0; + void shutdown(); + private: class SrvClientLink : public Bu::ClientLink { -- cgit v1.2.3