aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-01-09 07:55:02 +0000
committerMike Buland <eichlan@xagasoft.com>2009-01-09 07:55:02 +0000
commit861e5bd7d3df941685f048d7039029b83ec87cb9 (patch)
treef82f1a58134f72036a67988237e33ae85bf36e83
parentaba7c45c2c69d402d1b6fc427cde5bfa4661a0e1 (diff)
downloadlibbu++-861e5bd7d3df941685f048d7039029b83ec87cb9.tar.gz
libbu++-861e5bd7d3df941685f048d7039029b83ec87cb9.tar.bz2
libbu++-861e5bd7d3df941685f048d7039029b83ec87cb9.tar.xz
libbu++-861e5bd7d3df941685f048d7039029b83ec87cb9.zip
Hey, that's better. The server now idles the same, but sends data uber-fast!
Diffstat (limited to '')
-rw-r--r--src/client.h2
-rw-r--r--src/server.cpp20
2 files changed, 18 insertions, 4 deletions
diff --git a/src/client.h b/src/client.h
index 954f134..2cd700b 100644
--- a/src/client.h
+++ b/src/client.h
@@ -64,6 +64,8 @@ namespace Bu
64 64
65 void onMessage( const Bu::FString &sMsg ); 65 void onMessage( const Bu::FString &sMsg );
66 66
67 bool hasOutput() { return !sWriteBuf.isEmpty(); }
68
67 private: 69 private:
68 Bu::Socket *pSocket; 70 Bu::Socket *pSocket;
69 Bu::Protocol *pProto; 71 Bu::Protocol *pProto;
diff --git a/src/server.cpp b/src/server.cpp
index eb85997..804bbcc 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -59,10 +59,18 @@ void Bu::Server::scan()
59 struct timeval xTimeout = { nTimeoutSec, nTimeoutUSec }; 59 struct timeval xTimeout = { nTimeoutSec, nTimeoutUSec };
60 60
61 fd_set fdRead = fdActive; 61 fd_set fdRead = fdActive;
62 fd_set fdWrite = fdActive; 62 fd_set fdWrite /* = fdActive*/;
63 fd_set fdException = fdActive; 63 fd_set fdException = fdActive;
64 64
65 if( TEMP_FAILURE_RETRY( select( FD_SETSIZE, &fdRead, NULL, &fdException, &xTimeout ) ) < 0 ) 65 FD_ZERO( &fdWrite );
66 for( ClientHash::iterator i = hClients.begin(); i != hClients.end(); i++ )
67 {
68 if( (*i)->hasOutput() )
69 FD_SET( i.getKey(), &fdWrite );
70 }
71
72 if( TEMP_FAILURE_RETRY( select( FD_SETSIZE,
73 &fdRead, &fdWrite, &fdException, &xTimeout ) ) < 0 )
66 { 74 {
67 throw ExceptionBase("Error attempting to scan open connections."); 75 throw ExceptionBase("Error attempting to scan open connections.");
68 } 76 }
@@ -88,6 +96,11 @@ void Bu::Server::scan()
88 } 96 }
89 } 97 }
90 } 98 }
99 if( FD_ISSET( j, &fdWrite ) )
100 {
101 Client *pClient = hClients.get( j );
102 pClient->processOutput();
103 }
91 } 104 }
92 105
93 Bu::List<int> lDelete; 106 Bu::List<int> lDelete;
@@ -96,8 +109,7 @@ void Bu::Server::scan()
96 // wanting to accept writes (using a select). 109 // wanting to accept writes (using a select).
97 for( ClientHash::iterator i = hClients.begin(); i != hClients.end(); i++ ) 110 for( ClientHash::iterator i = hClients.begin(); i != hClients.end(); i++ )
98 { 111 {
99 (*i)->processOutput(); 112 if( (*i)->wantsDisconnect() && !(*i)->hasOutput() )
100 if( (*i)->wantsDisconnect() )
101 { 113 {
102 lDelete.append( i.getKey() ); 114 lDelete.append( i.getKey() );
103 } 115 }