diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-01-11 23:07:44 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-01-11 23:07:44 +0000 |
commit | 1291252a7b1317ad2dc13fbeb15f6e9d2d92192c (patch) | |
tree | 5eb88c7cef5417c043b03b34a77334c57286e526 /src/server.cpp | |
parent | 595afe519791894c77c77a949fba7732f4d94872 (diff) | |
download | libbu++-1291252a7b1317ad2dc13fbeb15f6e9d2d92192c.tar.gz libbu++-1291252a7b1317ad2dc13fbeb15f6e9d2d92192c.tar.bz2 libbu++-1291252a7b1317ad2dc13fbeb15f6e9d2d92192c.tar.xz libbu++-1291252a7b1317ad2dc13fbeb15f6e9d2d92192c.zip |
A new feature has been added to Bu::Server. It's going to be trickier to
implement in Bu::ItoServer, but I'll get to it. Basically you can trigger a
"tick" any time you want and it will propegate as an onTick event to all active
clients. You can also have these generated automatically everytime the system
passes through a polling cycle. In this case, you should never ever write
data to the socket every tick. It will cause your program to go bursurk.
Diffstat (limited to 'src/server.cpp')
-rw-r--r-- | src/server.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/server.cpp b/src/server.cpp index 804bbcc..b7dec41 100644 --- a/src/server.cpp +++ b/src/server.cpp | |||
@@ -14,7 +14,8 @@ | |||
14 | 14 | ||
15 | Bu::Server::Server() : | 15 | Bu::Server::Server() : |
16 | nTimeoutSec( 0 ), | 16 | nTimeoutSec( 0 ), |
17 | nTimeoutUSec( 0 ) | 17 | nTimeoutUSec( 0 ), |
18 | bAutoTick( false ) | ||
18 | { | 19 | { |
19 | FD_ZERO( &fdActive ); | 20 | FD_ZERO( &fdActive ); |
20 | } | 21 | } |
@@ -123,6 +124,9 @@ void Bu::Server::scan() | |||
123 | hClients.erase( *i ); | 124 | hClients.erase( *i ); |
124 | FD_CLR( *i, &fdActive ); | 125 | FD_CLR( *i, &fdActive ); |
125 | } | 126 | } |
127 | |||
128 | if( bAutoTick ) | ||
129 | tick(); | ||
126 | } | 130 | } |
127 | 131 | ||
128 | void Bu::Server::addClient( int nSocket, int nPort ) | 132 | void Bu::Server::addClient( int nSocket, int nPort ) |
@@ -166,3 +170,16 @@ Bu::ClientLink *Bu::Server::SrvClientLinkFactory::createLink( | |||
166 | return new SrvClientLink( pClient ); | 170 | return new SrvClientLink( pClient ); |
167 | } | 171 | } |
168 | 172 | ||
173 | void Bu::Server::setAutoTick( bool bEnable ) | ||
174 | { | ||
175 | bAutoTick = bEnable; | ||
176 | } | ||
177 | |||
178 | void Bu::Server::tick() | ||
179 | { | ||
180 | for( ClientHash::iterator i = hClients.begin(); i != hClients.end(); i++ ) | ||
181 | { | ||
182 | (*i)->tick(); | ||
183 | } | ||
184 | } | ||
185 | |||