diff options
Diffstat (limited to '')
| -rw-r--r-- | src/server.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/server.h b/src/server.h new file mode 100644 index 0000000..9f4f459 --- /dev/null +++ b/src/server.h | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | #ifndef SERVER_H | ||
| 2 | #define SERVER_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include "bu/serversocket.h" | ||
| 6 | #include "bu/list.h" | ||
| 7 | #include "bu/client.h" | ||
| 8 | |||
| 9 | namespace Bu | ||
| 10 | { | ||
| 11 | /** | ||
| 12 | * Core of a network server. This class is distinct from a ServerSocket in | ||
| 13 | * that a ServerSocket is one listening socket, nothing more. Socket will | ||
| 14 | * manage a pool of both ServerSockets and connected Sockets along with | ||
| 15 | * their protocols and buffers. | ||
| 16 | * | ||
| 17 | * To start serving on a new port, use the addPort functions. Each call to | ||
| 18 | * addPort creates a new ServerSocket, starts it listening, and adds it to | ||
| 19 | * the server pool. | ||
| 20 | * | ||
| 21 | * All of the real work is done by scan, which will wait for up | ||
| 22 | * to the timeout set by setTimeout before returning if there is no data | ||
| 23 | * pending. scan should probably be called in some sort of tight | ||
| 24 | * loop, possibly in it's own thread, or in the main control loop. | ||
| 25 | */ | ||
| 26 | class Server | ||
| 27 | { | ||
| 28 | public: | ||
| 29 | Server(); | ||
| 30 | virtual ~Server(); | ||
| 31 | |||
| 32 | void addPort( int nPort, int nPoolSize=40 ); | ||
| 33 | void addPort( const FString &sAddr, int nPort, int nPoolSize=40 ); | ||
| 34 | |||
| 35 | void scan(); | ||
| 36 | void setTimeout( int nTimeoutSec, int nTimeoutUSec=0 ); | ||
| 37 | |||
| 38 | void addClient( int nSocket ); | ||
| 39 | |||
| 40 | private: | ||
| 41 | int nTimeoutSec; | ||
| 42 | int nTimeoutUSec; | ||
| 43 | fd_set fdActive; | ||
| 44 | Hash<int,ServerSocket *> hServers; | ||
| 45 | Hash<int,Client *> hClients; | ||
| 46 | }; | ||
| 47 | } | ||
| 48 | |||
| 49 | #endif | ||
