diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-03-12 16:21:25 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-03-12 16:21:25 +0000 |
commit | 14a460c60b162aefaf1798c71ac790ad574e739f (patch) | |
tree | 2e9920d5f671a55f5ec380787eca34c62f97afef /src | |
parent | 3667cec1f612e6a37479f99bd1fa23d92af7cff7 (diff) | |
download | libbu++-14a460c60b162aefaf1798c71ac790ad574e739f.tar.gz libbu++-14a460c60b162aefaf1798c71ac790ad574e739f.tar.bz2 libbu++-14a460c60b162aefaf1798c71ac790ad574e739f.tar.xz libbu++-14a460c60b162aefaf1798c71ac790ad574e739f.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/multiserver.cpp | 5 | ||||
-rw-r--r-- | src/multiserver.h | 2 | ||||
-rw-r--r-- | src/server.cpp | 28 | ||||
-rw-r--r-- | 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 ) | |||
43 | delete pClient->getProtocol(); | 43 | delete pClient->getProtocol(); |
44 | } | 44 | } |
45 | 45 | ||
46 | void Bu::MultiServer::shutdown() | ||
47 | { | ||
48 | Bu::Server::shutdown(); | ||
49 | } | ||
50 | |||
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 | |||
45 | virtual void onNewConnection( Client *pClient, int nPort ); | 45 | virtual void onNewConnection( Client *pClient, int nPort ); |
46 | virtual void onClosedConnection( Client *pClient ); | 46 | virtual void onClosedConnection( Client *pClient ); |
47 | 47 | ||
48 | void shutdown(); | ||
49 | |||
48 | private: | 50 | private: |
49 | Bu::Hash<int, Protocol *(*)()> hProtos; | 51 | Bu::Hash<int, Protocol *(*)()> hProtos; |
50 | }; | 52 | }; |
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() : | |||
23 | 23 | ||
24 | Bu::Server::~Server() | 24 | Bu::Server::~Server() |
25 | { | 25 | { |
26 | for( SrvHash::iterator i = hServers.begin(); i != hServers.end(); i++ ) | 26 | shutdown(); |
27 | { | ||
28 | delete *i; | ||
29 | } | ||
30 | |||
31 | for( ClientHash::iterator i = hClients.begin(); i != hClients.end(); i++ ) | ||
32 | { | ||
33 | delete *i; | ||
34 | } | ||
35 | } | 27 | } |
36 | 28 | ||
37 | void Bu::Server::addPort( int nPort, int nPoolSize ) | 29 | void Bu::Server::addPort( int nPort, int nPoolSize ) |
@@ -185,3 +177,21 @@ void Bu::Server::tick() | |||
185 | } | 177 | } |
186 | } | 178 | } |
187 | 179 | ||
180 | void Bu::Server::shutdown() | ||
181 | { | ||
182 | for( SrvHash::iterator i = hServers.begin(); i != hServers.end(); i++ ) | ||
183 | { | ||
184 | delete *i; | ||
185 | } | ||
186 | |||
187 | hServers.clear(); | ||
188 | |||
189 | for( ClientHash::iterator i = hClients.begin(); i != hClients.end(); i++ ) | ||
190 | { | ||
191 | onClosedConnection( *i ); | ||
192 | delete *i; | ||
193 | } | ||
194 | |||
195 | hClients.clear(); | ||
196 | } | ||
197 | |||
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 | |||
68 | virtual void onNewConnection( Client *pClient, int nPort )=0; | 68 | virtual void onNewConnection( Client *pClient, int nPort )=0; |
69 | virtual void onClosedConnection( Client *pClient )=0; | 69 | virtual void onClosedConnection( Client *pClient )=0; |
70 | 70 | ||
71 | void shutdown(); | ||
72 | |||
71 | private: | 73 | private: |
72 | class SrvClientLink : public Bu::ClientLink | 74 | class SrvClientLink : public Bu::ClientLink |
73 | { | 75 | { |