diff options
Diffstat (limited to 'src/connectionmanager.cpp')
-rw-r--r-- | src/connectionmanager.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/connectionmanager.cpp b/src/connectionmanager.cpp index 36ff961..ded5aa4 100644 --- a/src/connectionmanager.cpp +++ b/src/connectionmanager.cpp | |||
@@ -13,9 +13,9 @@ | |||
13 | #include "connectionmanager.h" | 13 | #include "connectionmanager.h" |
14 | #include <fcntl.h> | 14 | #include <fcntl.h> |
15 | 15 | ||
16 | ConnectionManager::ConnectionManager() | 16 | ConnectionManager::ConnectionManager() : |
17 | xLog( MultiLog::getInstance() ) | ||
17 | { | 18 | { |
18 | pLog = MultiLog::getLog(); | ||
19 | nMasterSocket = -1; | 19 | nMasterSocket = -1; |
20 | pMonitor = NULL; | 20 | pMonitor = NULL; |
21 | } | 21 | } |
@@ -42,7 +42,7 @@ bool ConnectionManager::startServer( int nPort, int nInitPool ) | |||
42 | nMasterSocket = socket (PF_INET, SOCK_STREAM, 0); | 42 | nMasterSocket = socket (PF_INET, SOCK_STREAM, 0); |
43 | if (nMasterSocket < 0) | 43 | if (nMasterSocket < 0) |
44 | { | 44 | { |
45 | pLog->LineLog( MultiLog::LError, "Couldn't create a listen socket."); | 45 | xLog.LineLog( MultiLog::LError, "Couldn't create a listen socket."); |
46 | return false; | 46 | return false; |
47 | } | 47 | } |
48 | 48 | ||
@@ -59,13 +59,13 @@ bool ConnectionManager::startServer( int nPort, int nInitPool ) | |||
59 | 59 | ||
60 | if (bind (nMasterSocket, (struct sockaddr *) &name, sizeof (name)) < 0) | 60 | if (bind (nMasterSocket, (struct sockaddr *) &name, sizeof (name)) < 0) |
61 | { | 61 | { |
62 | pLog->LineLog( MultiLog::LError, "Couldn't bind to the listen socket."); | 62 | xLog.LineLog( MultiLog::LError, "Couldn't bind to the listen socket."); |
63 | return false; | 63 | return false; |
64 | } | 64 | } |
65 | 65 | ||
66 | if (listen (nMasterSocket, 1) < 0) | 66 | if (listen (nMasterSocket, 1) < 0) |
67 | { | 67 | { |
68 | pLog->LineLog( MultiLog::LError, "Couldn't begin listening to the server socket."); | 68 | xLog.LineLog( MultiLog::LError, "Couldn't begin listening to the server socket."); |
69 | return false; | 69 | return false; |
70 | } | 70 | } |
71 | 71 | ||
@@ -90,18 +90,18 @@ bool ConnectionManager::startServer( int nPort, int nInitPool, int nNumTries, in | |||
90 | 90 | ||
91 | for( int j = 0; j < nNumTries; j++ ) | 91 | for( int j = 0; j < nNumTries; j++ ) |
92 | { | 92 | { |
93 | pLog->LineLog( MultiLog::LStatus, "Attempting to create server socket (attempt [%d/%d])...", j+1, nNumTries ); | 93 | xLog.LineLog( MultiLog::LStatus, "Attempting to create server socket (attempt [%d/%d])...", j+1, nNumTries ); |
94 | if( startServer( nPort, nInitPool ) == true ) | 94 | if( startServer( nPort, nInitPool ) == true ) |
95 | { | 95 | { |
96 | return true; | 96 | return true; |
97 | } | 97 | } |
98 | else if( j < nNumTries-1 ) | 98 | else if( j < nNumTries-1 ) |
99 | { | 99 | { |
100 | pLog->LineLog( MultiLog::LStatus, "Waiting for %d secconds to allow port to clear...", nTimeout ); | 100 | xLog.LineLog( MultiLog::LStatus, "Waiting for %d secconds to allow port to clear...", nTimeout ); |
101 | xTimeout.tv_sec = nTimeout; | 101 | xTimeout.tv_sec = nTimeout; |
102 | xTimeout.tv_usec = 0; | 102 | xTimeout.tv_usec = 0; |
103 | if (select(0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, &xTimeout) < 0) { | 103 | if (select(0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, &xTimeout) < 0) { |
104 | pLog->LineLog( MultiLog::LError, "Error using select to sleep for a while."); | 104 | xLog.LineLog( MultiLog::LError, "Error using select to sleep for a while."); |
105 | } | 105 | } |
106 | usleep( nTimeout ); | 106 | usleep( nTimeout ); |
107 | } | 107 | } |
@@ -127,7 +127,7 @@ bool ConnectionManager::scanConnections( int nTimeout, bool bForceTimeout ) | |||
127 | // if there are ANY connections there... | 127 | // if there are ANY connections there... |
128 | if( TEMP_FAILURE_RETRY( select( FD_SETSIZE, &fdRead, (fd_set *)0/*&fdWrite*/, &fdException, &xTimeout ) ) < 0 ) | 128 | if( TEMP_FAILURE_RETRY( select( FD_SETSIZE, &fdRead, (fd_set *)0/*&fdWrite*/, &fdException, &xTimeout ) ) < 0 ) |
129 | { | 129 | { |
130 | pLog->LineLog( MultiLog::LError, "Error attempting to scan open connections."); | 130 | xLog.LineLog( MultiLog::LError, "Error attempting to scan open connections."); |
131 | perror("ConnectionManager"); | 131 | perror("ConnectionManager"); |
132 | return false; | 132 | return false; |
133 | } | 133 | } |
@@ -137,7 +137,7 @@ bool ConnectionManager::scanConnections( int nTimeout, bool bForceTimeout ) | |||
137 | if( bForceTimeout ) | 137 | if( bForceTimeout ) |
138 | { | 138 | { |
139 | if (select(0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, &xTimeout) < 0) { | 139 | if (select(0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, &xTimeout) < 0) { |
140 | pLog->LineLog( MultiLog::LError, "Error using select to sleep for a while."); | 140 | xLog.LineLog( MultiLog::LError, "Error using select to sleep for a while."); |
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
@@ -155,14 +155,14 @@ bool ConnectionManager::scanConnections( int nTimeout, bool bForceTimeout ) | |||
155 | Connection *pCon = findActiveConnection( i ); | 155 | Connection *pCon = findActiveConnection( i ); |
156 | if( pCon == NULL ) | 156 | if( pCon == NULL ) |
157 | { | 157 | { |
158 | pLog->LineLog( MultiLog::LError, "A connection object was lost, or never created!"); | 158 | xLog.LineLog( MultiLog::LError, "A connection object was lost, or never created!"); |
159 | return false; | 159 | return false; |
160 | } | 160 | } |
161 | 161 | ||
162 | /* Data arriving on an already-connected socket. */ | 162 | /* Data arriving on an already-connected socket. */ |
163 | if( pCon->readInput() != true ) | 163 | if( pCon->readInput() != true ) |
164 | { | 164 | { |
165 | pLog->LineLog( MultiLog::LStatus, "Closing connection due to disconnect."); | 165 | xLog.LineLog( MultiLog::LStatus, "Closing connection due to disconnect."); |
166 | close( i ); | 166 | close( i ); |
167 | FD_CLR( i, &fdActive ); | 167 | FD_CLR( i, &fdActive ); |
168 | pMonitor->onClosedConnection( pCon ); | 168 | pMonitor->onClosedConnection( pCon ); |
@@ -203,7 +203,7 @@ bool ConnectionManager::scanConnections( int nTimeout, bool bForceTimeout ) | |||
203 | std::list<Connection *>::iterator l = i; | 203 | std::list<Connection *>::iterator l = i; |
204 | i--; | 204 | i--; |
205 | lActive.erase( l ); | 205 | lActive.erase( l ); |
206 | pLog->LineLog( MultiLog::LStatus, "Closing connection due to server request."); | 206 | xLog.LineLog( MultiLog::LStatus, "Closing connection due to server request."); |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
@@ -269,13 +269,13 @@ bool ConnectionManager::addConnection() | |||
269 | #endif | 269 | #endif |
270 | if( newSocket < 0 ) | 270 | if( newSocket < 0 ) |
271 | { | 271 | { |
272 | pLog->LineLog( MultiLog::LError, "Error accepting a new connection!" ); | 272 | xLog.LineLog( MultiLog::LError, "Error accepting a new connection!" ); |
273 | return false; | 273 | return false; |
274 | } | 274 | } |
275 | // char *tmpa = inet_ntoa(clientname.sin_addr); | 275 | // char *tmpa = inet_ntoa(clientname.sin_addr); |
276 | char tmpa[20]; | 276 | char tmpa[20]; |
277 | inet_ntop( AF_INET, (void *)&clientname.sin_addr, tmpa, 20 ); | 277 | inet_ntop( AF_INET, (void *)&clientname.sin_addr, tmpa, 20 ); |
278 | pLog->LineLog( MultiLog::LStatus, "New connection from host %s, port %hd.", tmpa, ntohs (clientname.sin_port) ); | 278 | xLog.LineLog( MultiLog::LStatus, "New connection from host %s, port %hd.", tmpa, ntohs (clientname.sin_port) ); |
279 | /* | 279 | /* |
280 | int nCnt = 0; | 280 | int nCnt = 0; |
281 | for( int j = 0; j < nPoolSize; j++ ) | 281 | for( int j = 0; j < nPoolSize; j++ ) |
@@ -285,7 +285,7 @@ bool ConnectionManager::addConnection() | |||
285 | nCnt++; | 285 | nCnt++; |
286 | } | 286 | } |
287 | } | 287 | } |
288 | pLog->LineLog( MultiLog::LStatus, "Connections %d/%d.", nCnt, nPoolSize ); | 288 | xLog.LineLog( MultiLog::LStatus, "Connections %d/%d.", nCnt, nPoolSize ); |
289 | */ | 289 | */ |
290 | // free( tmpa ); | 290 | // free( tmpa ); |
291 | FD_SET( newSocket, &fdActive ); | 291 | FD_SET( newSocket, &fdActive ); |