From 5ff43b1a4abd06a47a996b817846567f8d1bc615 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 25 Aug 2006 22:44:09 +0000 Subject: Fixed more stuff in the connection class. Yay. --- src/connection.cpp | 36 ++++++++++++++++++++++++++++++------ src/test/clistress/main.cpp | 6 ++++-- src/test/srvstress/main.cpp | 4 ++++ 3 files changed, 38 insertions(+), 8 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 @@ #include #include #include +#include #include #include #include @@ -238,20 +239,21 @@ int Connection::readInput() bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack ) { fd_set rfds; - struct timeval tv; + struct timeval tv, start, end; + struct timezone tz; int retval; + gettimeofday( &start, &tz ); + FD_ZERO(&rfds); FD_SET(nSocket, &rfds); tv.tv_sec = nSec; tv.tv_usec = nUSec; + //printf("Starting at %d %d\n", nSec, nUSec ); retval = select( nSocket+1, &rfds, NULL, NULL, &tv ); - if( pnSecBack ) (*pnSecBack) = tv.tv_sec; - if( pnUSecBack ) (*pnUSecBack) = tv.tv_usec; - if( retval == -1 ) { // Oh my god!!! some kind of horrible problem!!!! @@ -260,7 +262,7 @@ bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack } else if( retval ) { - printf("retval=%d, nSocket=%d,%d, sec=%d, usec=%d\n", retval, nSocket, FD_ISSET( nSocket, &rfds ), tv.tv_sec, tv.tv_usec ); + //printf("retval=%d, nSocket=%d,%d, sec=%d, usec=%d\n", retval, nSocket, FD_ISSET( nSocket, &rfds ), tv.tv_sec, tv.tv_usec ); // None of them have data, but the connection is still active. if( readInput() == 0 ) { @@ -268,10 +270,32 @@ bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack throw ConnectionException( excodeConnectionClosed, "Connection closed"); } } + + gettimeofday( &end, &tz ); + + int st, ust; + st = nSec - ( end.tv_sec - start.tv_sec ); + if( ( end.tv_usec - start.tv_usec ) > nUSec ) + { + (st)--; + ust = 1000000 - (end.tv_usec - start.tv_usec); + } else { - return true; + ust = nUSec - (end.tv_usec - start.tv_usec); } + + if( st < 0 ) + { + st = ust = 0; + } + + *pnSecBack = st; + *pnUSecBack = ust; + + //printf("New time: %d %d\n", *pnSecBack, *pnUSecBack ); + + return true; } void Connection::waitForInput( int nBytesIn, int nSec, int nUSec ) diff --git a/src/test/clistress/main.cpp b/src/test/clistress/main.cpp index 0869945..6b0ac66 100644 --- a/src/test/clistress/main.cpp +++ b/src/test/clistress/main.cpp @@ -6,10 +6,12 @@ int main() c.open("localhost", 4001 ); - c.appendOutput("d"); + c.appendOutput("w"); c.writeOutput(); - c.waitForInput( 5, 40, 0 ); + c.waitForInput( 6, 5, 0 ); + + printf("read: %s\n", c.getInput() ); c.close(); diff --git a/src/test/srvstress/main.cpp b/src/test/srvstress/main.cpp index c7795e4..7fe7657 100644 --- a/src/test/srvstress/main.cpp +++ b/src/test/srvstress/main.cpp @@ -13,6 +13,10 @@ public: case 'd': throw "Hello"; break; + + case 'w': + getConnection()->appendOutput("Hello"); + break; }; return true; -- cgit v1.2.3