diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-08-25 20:24:31 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-08-25 20:24:31 +0000 |
commit | 0c2d075e795858779af102e932a881498e2268ae (patch) | |
tree | e4cab130b72997bd76af1cde4d9bbe3f5de343d3 /src/connection.cpp | |
parent | ec1a4f20eace44b6ffde4c1eacdecf3938942cd4 (diff) | |
download | libbu++-0c2d075e795858779af102e932a881498e2268ae.tar.gz libbu++-0c2d075e795858779af102e932a881498e2268ae.tar.bz2 libbu++-0c2d075e795858779af102e932a881498e2268ae.tar.xz libbu++-0c2d075e795858779af102e932a881498e2268ae.zip |
Added a new exception for connecitons, and added a new function to the
connection class, that reads at least n bytes in x seconds.
Diffstat (limited to 'src/connection.cpp')
-rw-r--r-- | src/connection.cpp | 24 |
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 | ||
13 | Connection::Connection() | 14 | Connection::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 | ||
275 | void 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 | |||
275 | bool Connection::clearOutput() | 293 | bool Connection::clearOutput() |
276 | { | 294 | { |
277 | return xOutputBuf.clearData(); | 295 | return xOutputBuf.clearData(); |