diff options
Diffstat (limited to 'src/multiserver.h')
-rw-r--r-- | src/multiserver.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/multiserver.h b/src/multiserver.h new file mode 100644 index 0000000..cf71203 --- /dev/null +++ b/src/multiserver.h | |||
@@ -0,0 +1,46 @@ | |||
1 | #ifndef BU_MULTI_SERVER_H | ||
2 | #define BU_MULTI_SERVER_H | ||
3 | |||
4 | #include "bu/server.h" | ||
5 | #include "bu/hash.h" | ||
6 | |||
7 | namespace Bu | ||
8 | { | ||
9 | class Protocol; | ||
10 | class Client; | ||
11 | |||
12 | template<class T> | ||
13 | Protocol *genProtocol() | ||
14 | { | ||
15 | return new T; | ||
16 | } | ||
17 | |||
18 | class MultiServer : protected Server | ||
19 | { | ||
20 | public: | ||
21 | MultiServer(); | ||
22 | virtual ~MultiServer(); | ||
23 | |||
24 | void addProtocol( Protocol *(*proc)(), int iPort, int nPoolSize=40 ); | ||
25 | void addProtocol( Protocol *(*proc)(), const FString &sAddr, int iPort, | ||
26 | int nPoolSize=40 ); | ||
27 | |||
28 | void scan() | ||
29 | { | ||
30 | Server::scan(); | ||
31 | } | ||
32 | |||
33 | void setTimeout( int nTimeoutSec, int nTimeoutUSec=0 ) | ||
34 | { | ||
35 | Server::setTimeout( nTimeoutSec, nTimeoutUSec ); | ||
36 | } | ||
37 | |||
38 | virtual void onNewConnection( Client *pClient, int nPort ); | ||
39 | virtual void onClosedConnection( Client *pClient ); | ||
40 | |||
41 | private: | ||
42 | Bu::Hash<int, Protocol *(*)()> hProtos; | ||
43 | }; | ||
44 | } | ||
45 | |||
46 | #endif | ||