aboutsummaryrefslogtreecommitdiff
path: root/src/stable/server.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
committerMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
commitec05778d5718a7912e506764d443a78d6a6179e3 (patch)
tree78a9a01532180030c095acefc45763f07c14edb8 /src/stable/server.h
parentb20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff)
downloadlibbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip
Converted tabs to spaces with tabconv.
Diffstat (limited to 'src/stable/server.h')
-rw-r--r--src/stable/server.h138
1 files changed, 69 insertions, 69 deletions
diff --git a/src/stable/server.h b/src/stable/server.h
index 5a414d9..05ec018 100644
--- a/src/stable/server.h
+++ b/src/stable/server.h
@@ -11,7 +11,7 @@
11#include <stdint.h> 11#include <stdint.h>
12 12
13#ifndef WIN32 13#ifndef WIN32
14 #include <sys/select.h> 14 #include <sys/select.h>
15#endif 15#endif
16 16
17#include "bu/string.h" 17#include "bu/string.h"
@@ -25,90 +25,90 @@
25 25
26namespace Bu 26namespace Bu
27{ 27{
28 class TcpServerSocket; 28 class TcpServerSocket;
29 class TcpSocket; 29 class TcpSocket;
30 class Client; 30 class Client;
31 31
32 /** 32 /**
33 * Core of a network server. This class is distinct from a ServerSocket in 33 * Core of a network server. This class is distinct from a ServerSocket in
34 * that a ServerSocket is one listening socket, nothing more. Socket will 34 * that a ServerSocket is one listening socket, nothing more. Socket will
35 * manage a pool of both ServerSockets and connected Sockets along with 35 * manage a pool of both ServerSockets and connected Sockets along with
36 * their protocols and buffers. 36 * their protocols and buffers.
37 * 37 *
38 * To start serving on a new port, use the addPort functions. Each call to 38 * To start serving on a new port, use the addPort functions. Each call to
39 * addPort creates a new ServerSocket, starts it listening, and adds it to 39 * addPort creates a new ServerSocket, starts it listening, and adds it to
40 * the server pool. 40 * the server pool.
41 * 41 *
42 * All of the real work is done by scan, which will wait for up 42 * All of the real work is done by scan, which will wait for up
43 * to the timeout set by setTimeout before returning if there is no data 43 * to the timeout set by setTimeout before returning if there is no data
44 * pending. scan should probably be called in some sort of tight 44 * pending. scan should probably be called in some sort of tight
45 * loop, possibly in it's own thread, or in the main control loop. 45 * loop, possibly in it's own thread, or in the main control loop.
46 * 46 *
47 * In order to use a Server you must subclass it and implement the pure 47 * In order to use a Server you must subclass it and implement the pure
48 * virtual functions. These allow you to receive notification of events 48 * virtual functions. These allow you to receive notification of events
49 * happening within the server itself, and actually makes it useful. 49 * happening within the server itself, and actually makes it useful.
50 *@ingroup Serving 50 *@ingroup Serving
51 */ 51 */
52 class Server 52 class Server
53 { 53 {
54 public: 54 public:
55 Server(); 55 Server();
56 virtual ~Server(); 56 virtual ~Server();
57 57
58#ifdef WIN32 58#ifdef WIN32
59 typedef unsigned int socket_t; 59 typedef unsigned int socket_t;
60#else 60#else
61 typedef int socket_t; 61 typedef int socket_t;
62#endif 62#endif
63 63
64 void addPort( int nPort, int nPoolSize=40 ); 64 void addPort( int nPort, int nPoolSize=40 );
65 void addPort( const String &sAddr, int nPort, int nPoolSize=40 ); 65 void addPort( const String &sAddr, int nPort, int nPoolSize=40 );
66 66
67 virtual void scan(); 67 virtual void scan();
68 void setTimeout( int nTimeoutSec, int nTimeoutUSec=0 ); 68 void setTimeout( int nTimeoutSec, int nTimeoutUSec=0 );
69 69
70 void addClient( socket_t nSocket, int nPort ); 70 void addClient( socket_t nSocket, int nPort );
71 71
72 void setAutoTick( bool bEnable=true ); 72 void setAutoTick( bool bEnable=true );
73 void tick(); 73 void tick();
74 74
75 virtual void onNewConnection( Client *pClient, int nPort )=0; 75 virtual void onNewConnection( Client *pClient, int nPort )=0;
76 virtual void onClosedConnection( Client *pClient )=0; 76 virtual void onClosedConnection( Client *pClient )=0;
77 77
78 void shutdown(); 78 void shutdown();
79 79
80 private: 80 private:
81 void closeClient( socket_t iSocket ); 81 void closeClient( socket_t iSocket );
82 class SrvClientLink : public Bu::ClientLink 82 class SrvClientLink : public Bu::ClientLink
83 { 83 {
84 public: 84 public:
85 SrvClientLink( Bu::Client *pClient ); 85 SrvClientLink( Bu::Client *pClient );
86 virtual ~SrvClientLink(); 86 virtual ~SrvClientLink();
87 87
88 virtual void sendMessage( const Bu::String &sMsg ); 88 virtual void sendMessage( const Bu::String &sMsg );
89 89
90 private: 90 private:
91 Bu::Client *pClient; 91 Bu::Client *pClient;
92 }; 92 };
93 93
94 class SrvClientLinkFactory : public Bu::ClientLinkFactory 94 class SrvClientLinkFactory : public Bu::ClientLinkFactory
95 { 95 {
96 public: 96 public:
97 SrvClientLinkFactory(); 97 SrvClientLinkFactory();
98 virtual ~SrvClientLinkFactory(); 98 virtual ~SrvClientLinkFactory();
99 99
100 virtual Bu::ClientLink *createLink( Bu::Client *pClient ); 100 virtual Bu::ClientLink *createLink( Bu::Client *pClient );
101 }; 101 };
102 102
103 int nTimeoutSec; 103 int nTimeoutSec;
104 int nTimeoutUSec; 104 int nTimeoutUSec;
105 fd_set fdActive; 105 fd_set fdActive;
106 typedef Hash<socket_t,TcpServerSocket *> SrvHash; 106 typedef Hash<socket_t,TcpServerSocket *> SrvHash;
107 SrvHash hServers; 107 SrvHash hServers;
108 typedef Hash<socket_t,Client *> ClientHash; 108 typedef Hash<socket_t,Client *> ClientHash;
109 ClientHash hClients; 109 ClientHash hClients;
110 bool bAutoTick; 110 bool bAutoTick;
111 }; 111 };
112} 112}
113 113
114#endif 114#endif