diff options
author | Mike Buland <eichlan@xagasoft.com> | 2023-07-28 21:18:56 -0700 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2023-07-28 21:18:56 -0700 |
commit | 915005e218b5d00939b548de65ce6354f7acb487 (patch) | |
tree | 2f624a37f86f97cfd61c1995df7e4368b462bcac /src/unstable/itoserver.h | |
parent | e43a2cac32cb773994b11a3d964ec4acc372d273 (diff) | |
download | libbu++-915005e218b5d00939b548de65ce6354f7acb487.tar.gz libbu++-915005e218b5d00939b548de65ce6354f7acb487.tar.bz2 libbu++-915005e218b5d00939b548de65ce6354f7acb487.tar.xz libbu++-915005e218b5d00939b548de65ce6354f7acb487.zip |
Completely redesigned Server and Client.
Like, seriously, they're almost completely different.
Diffstat (limited to '')
-rw-r--r-- | src/unstable/itoserver.h | 147 |
1 files changed, 0 insertions, 147 deletions
diff --git a/src/unstable/itoserver.h b/src/unstable/itoserver.h deleted file mode 100644 index f5e4a71..0000000 --- a/src/unstable/itoserver.h +++ /dev/null | |||
@@ -1,147 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2019 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_ITO_SERVER_H | ||
9 | #define BU_ITO_SERVER_H | ||
10 | |||
11 | #include <stdint.h> | ||
12 | |||
13 | #ifndef WIN32 | ||
14 | #include <sys/select.h> | ||
15 | #endif | ||
16 | |||
17 | #include "bu/string.h" | ||
18 | #include "bu/list.h" | ||
19 | #include "bu/thread.h" | ||
20 | #include "bu/mutex.h" | ||
21 | #include "bu/synchroqueue.h" | ||
22 | #include "bu/hash.h" | ||
23 | |||
24 | #include "bu/clientlink.h" | ||
25 | #include "bu/clientlinkfactory.h" | ||
26 | |||
27 | namespace Bu | ||
28 | { | ||
29 | class TcpServerSocket; | ||
30 | class TcpSocket; | ||
31 | class Client; | ||
32 | |||
33 | /** | ||
34 | * Core of a network server. This class is distinct from a ServerSocket in | ||
35 | * that a ServerSocket is one listening socket, nothing more. Socket will | ||
36 | * manage a pool of both ServerSockets and connected Sockets along with | ||
37 | * their protocols and buffers. | ||
38 | * | ||
39 | * To start serving on a new port, use the addPort functions. Each call to | ||
40 | * addPort creates a new ServerSocket, starts it listening, and adds it to | ||
41 | * the server pool. | ||
42 | * | ||
43 | * All of the real work is done by scan, which will wait for up | ||
44 | * to the timeout set by setTimeout before returning if there is no data | ||
45 | * pending. scan should probably be called in some sort of tight | ||
46 | * loop, possibly in it's own thread, or in the main control loop. | ||
47 | * | ||
48 | * In order to use a Server you must subclass it and implement the pure | ||
49 | * virtual functions. These allow you to receive notification of events | ||
50 | * happening within the server itself, and actually makes it useful. | ||
51 | *@ingroup Threading Serving | ||
52 | */ | ||
53 | class ItoServer : public Thread | ||
54 | { | ||
55 | friend class ItoClient; | ||
56 | friend class SrvClientLinkFactory; | ||
57 | public: | ||
58 | ItoServer(); | ||
59 | virtual ~ItoServer(); | ||
60 | |||
61 | #ifdef WIN32 | ||
62 | typedef unsigned int socket_t; | ||
63 | #else | ||
64 | typedef int socket_t; | ||
65 | #endif | ||
66 | |||
67 | void addPort( int nPort, int nPoolSize=40 ); | ||
68 | void addPort( const String &sAddr, int nPort, int nPoolSize=40 ); | ||
69 | |||
70 | //void scan(); | ||
71 | void setTimeout( int nTimeoutSec, int nTimeoutUSec=0 ); | ||
72 | |||
73 | void addClient( socket_t nSocket, int nPort ); | ||
74 | |||
75 | virtual void onNewConnection( Client *pClient, int nPort )=0; | ||
76 | virtual void onClosedConnection( Client *pClient )=0; | ||
77 | |||
78 | protected: | ||
79 | virtual void run(); | ||
80 | |||
81 | private: | ||
82 | class SrvClientLink; | ||
83 | class ItoClient : public Thread | ||
84 | { | ||
85 | friend class Bu::ItoServer::SrvClientLink; | ||
86 | public: | ||
87 | ItoClient( ItoServer &rSrv, socket_t nSocket, int nPort, | ||
88 | int nTimeoutSec, int nTimeoutUSec ); | ||
89 | virtual ~ItoClient(); | ||
90 | |||
91 | typedef SynchroQueue<Bu::String *> StringQueue; | ||
92 | StringQueue qMsg; | ||
93 | |||
94 | protected: | ||
95 | virtual void run(); | ||
96 | |||
97 | private: | ||
98 | ItoServer &rSrv; | ||
99 | Client *pClient; | ||
100 | fd_set fdActive; | ||
101 | socket_t iSocket; | ||
102 | int iPort; | ||
103 | int nTimeoutSec; | ||
104 | int nTimeoutUSec; | ||
105 | Mutex imProto; | ||
106 | }; | ||
107 | |||
108 | class SrvClientLink : public Bu::ClientLink | ||
109 | { | ||
110 | public: | ||
111 | SrvClientLink( ItoClient *pClient ); | ||
112 | virtual ~SrvClientLink(); | ||
113 | |||
114 | virtual void sendMessage( const Bu::String &sMsg ); | ||
115 | |||
116 | private: | ||
117 | ItoClient *pClient; | ||
118 | }; | ||
119 | |||
120 | class SrvClientLinkFactory : public Bu::ClientLinkFactory | ||
121 | { | ||
122 | public: | ||
123 | SrvClientLinkFactory( ItoServer &rSrv ); | ||
124 | virtual ~SrvClientLinkFactory(); | ||
125 | |||
126 | virtual Bu::ClientLink *createLink( Bu::Client *pClient ); | ||
127 | |||
128 | private: | ||
129 | ItoServer &rSrv; | ||
130 | }; | ||
131 | |||
132 | int nTimeoutSec; | ||
133 | int nTimeoutUSec; | ||
134 | fd_set fdActive; | ||
135 | typedef Hash<socket_t,TcpServerSocket *> ServerHash; | ||
136 | ServerHash hServers; | ||
137 | typedef Hash<socket_t,ItoClient *> ClientHash; | ||
138 | typedef SynchroQueue<ItoClient *> ClientQueue; | ||
139 | ClientHash hClients; | ||
140 | ClientQueue qClientCleanup; | ||
141 | Mutex imClients; | ||
142 | |||
143 | void clientCleanup( socket_t iSocket ); | ||
144 | }; | ||
145 | } | ||
146 | |||
147 | #endif | ||