aboutsummaryrefslogtreecommitdiff
path: root/src/connection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/connection.cpp')
-rw-r--r--src/connection.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/connection.cpp b/src/connection.cpp
index 5b79dfe..0e7f111 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -9,6 +9,7 @@
9#include <netinet/in.h> 9#include <netinet/in.h>
10#include <netdb.h> 10#include <netdb.h>
11#include <arpa/inet.h> 11#include <arpa/inet.h>
12#include "exceptions.h"
12 13
13Connection::Connection() 14Connection::Connection()
14{ 15{
@@ -244,10 +245,9 @@ bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack
244 struct timeval tv; 245 struct timeval tv;
245 int retval; 246 int retval;
246 247
247 /* Watch stdin (fd 0) to see when it has input. */
248 FD_ZERO(&rfds); 248 FD_ZERO(&rfds);
249 FD_SET(nSocket, &rfds); 249 FD_SET(nSocket, &rfds);
250 /* Wait up to five seconds. */ 250
251 tv.tv_sec = nSec; 251 tv.tv_sec = nSec;
252 tv.tv_usec = nUSec; 252 tv.tv_usec = nUSec;
253 253
@@ -256,7 +256,7 @@ bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack
256 if( pnSecBack ) (*pnSecBack) = tv.tv_sec; 256 if( pnSecBack ) (*pnSecBack) = tv.tv_sec;
257 if( pnUSecBack ) (*pnUSecBack) = tv.tv_usec; 257 if( pnUSecBack ) (*pnUSecBack) = tv.tv_usec;
258 258
259 if (retval == -1) 259 if( retval == -1 )
260 { 260 {
261 // Oh my god!!! some kind of horrible problem!!!! 261 // Oh my god!!! some kind of horrible problem!!!!
262 return false; 262 return false;
@@ -272,6 +272,24 @@ bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack
272 } 272 }
273} 273}
274 274
275void Connection::waitForInput( int nBytesIn, int nSec, int nUSec )
276{
277 int rlen = getInputAmnt();
278
279 if( rlen >= nBytesIn )
280 return;
281
282 while( rlen < nBytesIn )
283 {
284 if( nSec == 0 && nUSec == 0 )
285 {
286 throw ConnectionException("Socket Timeout");
287 }
288 readInput( nSec, nUSec, &nSec, &nUSec );
289 rlen = getInputAmnt();
290 }
291}
292
275bool Connection::clearOutput() 293bool Connection::clearOutput()
276{ 294{
277 return xOutputBuf.clearData(); 295 return xOutputBuf.clearData();