diff options
author | Mike Buland <eichlan@xagasoft.com> | 2023-07-26 21:33:36 -0700 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2023-07-26 21:33:36 -0700 |
commit | e43a2cac32cb773994b11a3d964ec4acc372d273 (patch) | |
tree | 9e281be52f9dd8b80855c7d3cb9ec3df9cdd0ad3 /src/stable/server.cpp | |
parent | b544779d5b759d4ab2b82654e3f53b82ea41bac7 (diff) | |
download | libbu++-e43a2cac32cb773994b11a3d964ec4acc372d273.tar.gz libbu++-e43a2cac32cb773994b11a3d964ec4acc372d273.tar.bz2 libbu++-e43a2cac32cb773994b11a3d964ec4acc372d273.tar.xz libbu++-e43a2cac32cb773994b11a3d964ec4acc372d273.zip |
Added a profiler and investageted Server.
Diffstat (limited to 'src/stable/server.cpp')
-rw-r--r-- | src/stable/server.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/stable/server.cpp b/src/stable/server.cpp index 3c42bf4..0552510 100644 --- a/src/stable/server.cpp +++ b/src/stable/server.cpp | |||
@@ -13,17 +13,27 @@ | |||
13 | #include "bu/tcpsocket.h" | 13 | #include "bu/tcpsocket.h" |
14 | #include "bu/config.h" | 14 | #include "bu/config.h" |
15 | 15 | ||
16 | #ifdef PROFILE_BU_SERVER | ||
17 | #define BU_PROFILE_START( x ) Bu::Profiler::getInstance().startEvent( x ) | ||
18 | #define BU_PROFILE_END( x ) Bu::Profiler::getInstance().endEvent( x ) | ||
19 | #else | ||
20 | #define BU_PROFILE_START( x ) (void)0 | ||
21 | #define BU_PROFILE_END( x ) (void)0 | ||
22 | #endif | ||
23 | |||
16 | Bu::Server::Server() : | 24 | Bu::Server::Server() : |
17 | nTimeoutSec( 0 ), | 25 | nTimeoutSec( 0 ), |
18 | nTimeoutUSec( 0 ), | 26 | nTimeoutUSec( 0 ), |
19 | bAutoTick( false ) | 27 | bAutoTick( false ) |
20 | { | 28 | { |
29 | BU_PROFILE_START("server"); | ||
21 | FD_ZERO( &fdActive ); | 30 | FD_ZERO( &fdActive ); |
22 | } | 31 | } |
23 | 32 | ||
24 | Bu::Server::~Server() | 33 | Bu::Server::~Server() |
25 | { | 34 | { |
26 | shutdown(); | 35 | shutdown(); |
36 | BU_PROFILE_START("server"); | ||
27 | } | 37 | } |
28 | 38 | ||
29 | void Bu::Server::addPort( int nPort, int nPoolSize ) | 39 | void Bu::Server::addPort( int nPort, int nPoolSize ) |
@@ -50,6 +60,7 @@ void Bu::Server::setTimeout( int nTimeoutSec, int nTimeoutUSec ) | |||
50 | 60 | ||
51 | void Bu::Server::scan() | 61 | void Bu::Server::scan() |
52 | { | 62 | { |
63 | BU_PROFILE_START("scan"); | ||
53 | struct timeval xTimeout = { nTimeoutSec, nTimeoutUSec }; | 64 | struct timeval xTimeout = { nTimeoutSec, nTimeoutUSec }; |
54 | 65 | ||
55 | fd_set fdRead = fdActive; | 66 | fd_set fdRead = fdActive; |
@@ -68,6 +79,7 @@ void Bu::Server::scan() | |||
68 | { | 79 | { |
69 | char buf[1024]; | 80 | char buf[1024]; |
70 | strerror_r( errno, buf, 1024 ); | 81 | strerror_r( errno, buf, 1024 ); |
82 | BU_PROFILE_END("scan"); | ||
71 | throw ExceptionBase( | 83 | throw ExceptionBase( |
72 | Bu::String("Error attempting to scan open connections: %1: %2").arg( errno ).arg( buf ).end().getStr() | 84 | Bu::String("Error attempting to scan open connections: %1: %2").arg( errno ).arg( buf ).end().getStr() |
73 | ); | 85 | ); |
@@ -85,7 +97,9 @@ void Bu::Server::scan() | |||
85 | else | 97 | else |
86 | { | 98 | { |
87 | Client *pClient = hClients.get( j ); | 99 | Client *pClient = hClients.get( j ); |
100 | BU_PROFILE_START("processInput"); | ||
88 | pClient->processInput(); | 101 | pClient->processInput(); |
102 | BU_PROFILE_END("processInput"); | ||
89 | if( !pClient->isOpen() ) | 103 | if( !pClient->isOpen() ) |
90 | { | 104 | { |
91 | closeClient( j ); | 105 | closeClient( j ); |
@@ -99,7 +113,9 @@ void Bu::Server::scan() | |||
99 | Client *pClient = hClients.get( j ); | 113 | Client *pClient = hClients.get( j ); |
100 | try | 114 | try |
101 | { | 115 | { |
116 | BU_PROFILE_START("processOutput"); | ||
102 | pClient->processOutput(); | 117 | pClient->processOutput(); |
118 | BU_PROFILE_END("processOutput"); | ||
103 | } | 119 | } |
104 | catch( Bu::TcpSocketException &e ) | 120 | catch( Bu::TcpSocketException &e ) |
105 | { | 121 | { |
@@ -133,10 +149,13 @@ void Bu::Server::scan() | |||
133 | 149 | ||
134 | if( bAutoTick ) | 150 | if( bAutoTick ) |
135 | tick(); | 151 | tick(); |
152 | |||
153 | BU_PROFILE_END("scan"); | ||
136 | } | 154 | } |
137 | 155 | ||
138 | void Bu::Server::addClient( socket_t nSocket, int nPort ) | 156 | void Bu::Server::addClient( socket_t nSocket, int nPort ) |
139 | { | 157 | { |
158 | BU_PROFILE_START("addClient"); | ||
140 | FD_SET( nSocket, &fdActive ); | 159 | FD_SET( nSocket, &fdActive ); |
141 | 160 | ||
142 | Client *c = new Client( | 161 | Client *c = new Client( |
@@ -146,6 +165,7 @@ void Bu::Server::addClient( socket_t nSocket, int nPort ) | |||
146 | hClients.insert( nSocket, c ); | 165 | hClients.insert( nSocket, c ); |
147 | 166 | ||
148 | onNewConnection( c, nPort ); | 167 | onNewConnection( c, nPort ); |
168 | BU_PROFILE_END("addClient"); | ||
149 | } | 169 | } |
150 | 170 | ||
151 | Bu::Server::SrvClientLink::SrvClientLink( Bu::Client *pClient ) : | 171 | Bu::Server::SrvClientLink::SrvClientLink( Bu::Client *pClient ) : |
@@ -208,11 +228,13 @@ void Bu::Server::shutdown() | |||
208 | 228 | ||
209 | void Bu::Server::closeClient( socket_t iSocket ) | 229 | void Bu::Server::closeClient( socket_t iSocket ) |
210 | { | 230 | { |
231 | BU_PROFILE_START("closeClient"); | ||
211 | Bu::Client *pClient = hClients.get( iSocket ); | 232 | Bu::Client *pClient = hClients.get( iSocket ); |
212 | onClosedConnection( pClient ); | 233 | onClosedConnection( pClient ); |
213 | pClient->close(); | 234 | pClient->close(); |
214 | hClients.erase( iSocket ); | 235 | hClients.erase( iSocket ); |
215 | FD_CLR( iSocket, &fdActive ); | 236 | FD_CLR( iSocket, &fdActive ); |
216 | delete pClient; | 237 | delete pClient; |
238 | BU_PROFILE_END("closeClient"); | ||
217 | } | 239 | } |
218 | 240 | ||