From 0acdeb045f1bf6caae786c474d99cea68071f31f Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 21 Jun 2006 22:50:21 +0000 Subject: Updated the readInput function to tell you how much time is left over after blocking. --- src/connection.cpp | 6 ++++-- src/connection.h | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/connection.cpp b/src/connection.cpp index a277ea7..5b79dfe 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -238,7 +238,7 @@ bool Connection::readInput() return true; } -bool Connection::readInput( int nSec, int nUSec ) +bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack ) { fd_set rfds; struct timeval tv; @@ -252,7 +252,9 @@ bool Connection::readInput( int nSec, int nUSec ) tv.tv_usec = nUSec; retval = select( nSocket+1, &rfds, NULL, NULL, &tv ); - /* Don't rely on the value of tv now! */ + + if( pnSecBack ) (*pnSecBack) = tv.tv_sec; + if( pnUSecBack ) (*pnUSecBack) = tv.tv_usec; if (retval == -1) { diff --git a/src/connection.h b/src/connection.h index efb8630..dd4112b 100644 --- a/src/connection.h +++ b/src/connection.h @@ -272,11 +272,16 @@ public: * Reads all pending input from the connection, blocking up to nSec * seconds and nUSec micro-seconds for the data. This uses select to * simulate blocking, but has the same effect as standard io blocking. - * If you don't want to block, just set both values to zero. + * If you don't want to block, just set both values to zero. The back + * parameters are optional, set to null to not use them. The variables + * you pass in through the back parameters will contain the remaining + * time if data arrived before the max timeout was reached. *@param nSec Max seconds to wait. *@param nUSec Max micro-seconds to wait. + *@param pnSecBack The number of seconds remaining. + *@param pnUSecBack The number of micro-seconds remaining. */ - bool readInput( int nSec, int nUSec ); + bool readInput( int nSec, int nUSec, int *pnSecBack=NULL, int *pnUSecBack=NULL ); /** Writes all data that is pending to the socket. *@returns True if all data was written succesfully, false otherwise. -- cgit v1.2.3