diff options
Diffstat (limited to 'src/stable/multiserver.h')
| -rw-r--r-- | src/stable/multiserver.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/stable/multiserver.h b/src/stable/multiserver.h new file mode 100644 index 0000000..e3b3ec3 --- /dev/null +++ b/src/stable/multiserver.h | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef BU_MULTI_SERVER_H | ||
| 9 | #define BU_MULTI_SERVER_H | ||
| 10 | |||
| 11 | #include "bu/server.h" | ||
| 12 | #include "bu/hash.h" | ||
| 13 | |||
| 14 | namespace Bu | ||
| 15 | { | ||
| 16 | class Protocol; | ||
| 17 | class Client; | ||
| 18 | |||
| 19 | template<class T> | ||
| 20 | Protocol *genProtocol() | ||
| 21 | { | ||
| 22 | return new T; | ||
| 23 | } | ||
| 24 | |||
| 25 | class MultiServer : protected Server | ||
| 26 | { | ||
| 27 | public: | ||
| 28 | MultiServer(); | ||
| 29 | virtual ~MultiServer(); | ||
| 30 | |||
| 31 | void addProtocol( Protocol *(*proc)(), int iPort, int nPoolSize=40 ); | ||
| 32 | void addProtocol( Protocol *(*proc)(), const String &sAddr, int iPort, | ||
| 33 | int nPoolSize=40 ); | ||
| 34 | |||
| 35 | void scan() | ||
| 36 | { | ||
| 37 | Server::scan(); | ||
| 38 | } | ||
| 39 | |||
| 40 | void setTimeout( int nTimeoutSec, int nTimeoutUSec=0 ) | ||
| 41 | { | ||
| 42 | Server::setTimeout( nTimeoutSec, nTimeoutUSec ); | ||
| 43 | } | ||
| 44 | |||
| 45 | virtual void onNewConnection( Client *pClient, int nPort ); | ||
| 46 | virtual void onClosedConnection( Client *pClient ); | ||
| 47 | |||
| 48 | void shutdown(); | ||
| 49 | |||
| 50 | void tick(); | ||
| 51 | |||
| 52 | private: | ||
| 53 | Bu::Hash<int, Protocol *(*)()> hProtos; | ||
| 54 | }; | ||
| 55 | } | ||
| 56 | |||
| 57 | #endif | ||
