aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-04-02 17:35:41 +0000
committerMike Buland <eichlan@xagasoft.com>2007-04-02 17:35:41 +0000
commita8e7b44c9981dd5d65b0b97f1d2ee34927a0f2a5 (patch)
tree1aeb8bc05b80648a504937ea2ab990c6958cf7aa
parentcc4604c1e22e01c31d25923ed76d1518693b7faa (diff)
downloadlibbu++-a8e7b44c9981dd5d65b0b97f1d2ee34927a0f2a5.tar.gz
libbu++-a8e7b44c9981dd5d65b0b97f1d2ee34927a0f2a5.tar.bz2
libbu++-a8e7b44c9981dd5d65b0b97f1d2ee34927a0f2a5.tar.xz
libbu++-a8e7b44c9981dd5d65b0b97f1d2ee34927a0f2a5.zip
Ok...now you can specify a timeout on the open function, 30 seconds is the
default so no programs need to be changed, it seemed like a good default to me... Still needs testing, but it should work just fine, and shouldn't effect any of our servers.
Diffstat (limited to '')
-rw-r--r--src/connection.cpp38
-rw-r--r--src/connection.h2
2 files changed, 33 insertions, 7 deletions
diff --git a/src/connection.cpp b/src/connection.cpp
index 9d8b02c..efef144 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -165,7 +165,7 @@ bool Connection::open( int nNewSocket )
165 return true; 165 return true;
166} 166}
167 167
168bool Connection::open( const char *sAddr, int nPort ) 168bool Connection::open( const char *sAddr, int nPort, int nSec )
169{ 169{
170 struct sockaddr_in xServerName; 170 struct sockaddr_in xServerName;
171 bActive = false; 171 bActive = false;
@@ -204,13 +204,42 @@ bool Connection::open( const char *sAddr, int nPort )
204 } 204 }
205 205
206 //printf("Making actual connection..."); 206 //printf("Making actual connection...");
207 fflush( stdout ); 207 //fflush( stdout );
208 int ret = connect( 208 connect(
209 nSocket, 209 nSocket,
210 (struct sockaddr *)&xServerName, 210 (struct sockaddr *)&xServerName,
211 sizeof(xServerName) 211 sizeof(xServerName)
212 ); 212 );
213 //printf("Connected.\n"); 213 //printf("Connected.\n");
214
215 bActive = true;
216 bDisconnectMe = false;
217
218 if( nSec > 0 )
219 {
220 fd_set rfds, wfds, efds;
221 int retval;
222
223 FD_ZERO(&rfds);
224 FD_SET(nSocket, &rfds);
225 FD_ZERO(&wfds);
226 FD_SET(nSocket, &wfds);
227 FD_ZERO(&efds);
228 FD_SET(nSocket, &efds);
229
230 struct timeval tv;
231 tv.tv_sec = nSec;
232 tv.tv_usec = 0;
233
234 retval = select( nSocket+1, &rfds, &wfds, &efds, &tv );
235
236 if( retval == 0 )
237 {
238 close();
239 throw ExceptionBase("Connection timeout.\n");
240 }
241
242 }
214 243
215 /* 244 /*
216 if( ret < 0 ) 245 if( ret < 0 )
@@ -218,9 +247,6 @@ bool Connection::open( const char *sAddr, int nPort )
218 return false; 247 return false;
219 }*/ 248 }*/
220 249
221 bActive = true;
222 bDisconnectMe = false;
223
224 return true; 250 return true;
225} 251}
226 252
diff --git a/src/connection.h b/src/connection.h
index 7e1141d..0e991c7 100644
--- a/src/connection.h
+++ b/src/connection.h
@@ -49,7 +49,7 @@ public:
49 *@todo Make this function add log entries to a standard MultiLog if 49 *@todo Make this function add log entries to a standard MultiLog if
50 * something goes wrong. 50 * something goes wrong.
51 */ 51 */
52 bool open( const char *sAddr, int nPort ); 52 bool open( const char *sAddr, int nPort, int nSec=30 );
53 53
54 void ensureCapacity( int nSize ); 54 void ensureCapacity( int nSize );
55 55