aboutsummaryrefslogtreecommitdiff
path: root/src/connection.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-08-25 22:44:09 +0000
committerMike Buland <eichlan@xagasoft.com>2006-08-25 22:44:09 +0000
commit5ff43b1a4abd06a47a996b817846567f8d1bc615 (patch)
tree59d13dad781bf3f285c337429128fb241007ab3d /src/connection.cpp
parente1f398363812115611d20c0c803802c78ed65974 (diff)
downloadlibbu++-5ff43b1a4abd06a47a996b817846567f8d1bc615.tar.gz
libbu++-5ff43b1a4abd06a47a996b817846567f8d1bc615.tar.bz2
libbu++-5ff43b1a4abd06a47a996b817846567f8d1bc615.tar.xz
libbu++-5ff43b1a4abd06a47a996b817846567f8d1bc615.zip
Fixed more stuff in the connection class. Yay.
Diffstat (limited to '')
-rw-r--r--src/connection.cpp36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/connection.cpp b/src/connection.cpp
index c68c519..3b90329 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -6,6 +6,7 @@
6#include <unistd.h> 6#include <unistd.h>
7#include <sys/types.h> 7#include <sys/types.h>
8#include <sys/socket.h> 8#include <sys/socket.h>
9#include <sys/time.h>
9#include <netinet/in.h> 10#include <netinet/in.h>
10#include <netdb.h> 11#include <netdb.h>
11#include <arpa/inet.h> 12#include <arpa/inet.h>
@@ -238,20 +239,21 @@ int Connection::readInput()
238bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack ) 239bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack )
239{ 240{
240 fd_set rfds; 241 fd_set rfds;
241 struct timeval tv; 242 struct timeval tv, start, end;
243 struct timezone tz;
242 int retval; 244 int retval;
243 245
246 gettimeofday( &start, &tz );
247
244 FD_ZERO(&rfds); 248 FD_ZERO(&rfds);
245 FD_SET(nSocket, &rfds); 249 FD_SET(nSocket, &rfds);
246 250
247 tv.tv_sec = nSec; 251 tv.tv_sec = nSec;
248 tv.tv_usec = nUSec; 252 tv.tv_usec = nUSec;
249 253
254 //printf("Starting at %d %d\n", nSec, nUSec );
250 retval = select( nSocket+1, &rfds, NULL, NULL, &tv ); 255 retval = select( nSocket+1, &rfds, NULL, NULL, &tv );
251 256
252 if( pnSecBack ) (*pnSecBack) = tv.tv_sec;
253 if( pnUSecBack ) (*pnUSecBack) = tv.tv_usec;
254
255 if( retval == -1 ) 257 if( retval == -1 )
256 { 258 {
257 // Oh my god!!! some kind of horrible problem!!!! 259 // Oh my god!!! some kind of horrible problem!!!!
@@ -260,7 +262,7 @@ bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack
260 } 262 }
261 else if( retval ) 263 else if( retval )
262 { 264 {
263 printf("retval=%d, nSocket=%d,%d, sec=%d, usec=%d\n", retval, nSocket, FD_ISSET( nSocket, &rfds ), tv.tv_sec, tv.tv_usec ); 265 //printf("retval=%d, nSocket=%d,%d, sec=%d, usec=%d\n", retval, nSocket, FD_ISSET( nSocket, &rfds ), tv.tv_sec, tv.tv_usec );
264 // None of them have data, but the connection is still active. 266 // None of them have data, but the connection is still active.
265 if( readInput() == 0 ) 267 if( readInput() == 0 )
266 { 268 {
@@ -268,10 +270,32 @@ bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack
268 throw ConnectionException( excodeConnectionClosed, "Connection closed"); 270 throw ConnectionException( excodeConnectionClosed, "Connection closed");
269 } 271 }
270 } 272 }
273
274 gettimeofday( &end, &tz );
275
276 int st, ust;
277 st = nSec - ( end.tv_sec - start.tv_sec );
278 if( ( end.tv_usec - start.tv_usec ) > nUSec )
279 {
280 (st)--;
281 ust = 1000000 - (end.tv_usec - start.tv_usec);
282 }
271 else 283 else
272 { 284 {
273 return true; 285 ust = nUSec - (end.tv_usec - start.tv_usec);
274 } 286 }
287
288 if( st < 0 )
289 {
290 st = ust = 0;
291 }
292
293 *pnSecBack = st;
294 *pnUSecBack = ust;
295
296 //printf("New time: %d %d\n", *pnSecBack, *pnUSecBack );
297
298 return true;
275} 299}
276 300
277void Connection::waitForInput( int nBytesIn, int nSec, int nUSec ) 301void Connection::waitForInput( int nBytesIn, int nSec, int nUSec )