From 1291252a7b1317ad2dc13fbeb15f6e9d2d92192c Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 11 Jan 2009 23:07:44 +0000 Subject: 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. --- src/server.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/server.cpp') 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 @@ Bu::Server::Server() : nTimeoutSec( 0 ), - nTimeoutUSec( 0 ) + nTimeoutUSec( 0 ), + bAutoTick( false ) { FD_ZERO( &fdActive ); } @@ -123,6 +124,9 @@ void Bu::Server::scan() hClients.erase( *i ); FD_CLR( *i, &fdActive ); } + + if( bAutoTick ) + tick(); } void Bu::Server::addClient( int nSocket, int nPort ) @@ -166,3 +170,16 @@ Bu::ClientLink *Bu::Server::SrvClientLinkFactory::createLink( return new SrvClientLink( pClient ); } +void Bu::Server::setAutoTick( bool bEnable ) +{ + bAutoTick = bEnable; +} + +void Bu::Server::tick() +{ + for( ClientHash::iterator i = hClients.begin(); i != hClients.end(); i++ ) + { + (*i)->tick(); + } +} + -- cgit v1.2.3