diff --git a/Csocket.cpp b/Csocket.cpp index f686b7ad..cac39fa5 100644 --- a/Csocket.cpp +++ b/Csocket.cpp @@ -1,6 +1,6 @@ /** @file * -* Copyright (c) 1999-2006 Jim Hull +* Copyright (c) 1999-2007 Jim Hull * All rights reserved * * Redistribution and use in source and binary forms, with or without modification, @@ -303,11 +303,14 @@ CCron::CCron() m_bPause = false; } -void CCron::run( time_t iNow ) +void CCron::run( time_t & iNow ) { if ( m_bPause ) return; + if( iNow == 0 ) + iNow = time( NULL ); + if ( ( m_bActive ) && ( iNow >= m_iTime ) ) { RunJob(); @@ -988,10 +991,13 @@ bool Csock::ConnectSSL( const CS_STRING & sBindhost ) #endif /* HAVE_LIBSSL */ } -bool Csock::AllowWrite( unsigned long long iNOW ) const +bool Csock::AllowWrite( unsigned long long & iNOW ) const { if ( ( m_iMaxBytes > 0 ) && ( m_iMaxMilliSeconds > 0 ) ) { + if( iNOW == 0 ) + iNOW = millitime(); + if( m_iLastSend < m_iMaxBytes ) return( true ); // allow sending if our out buffer was less than what we can send if ( ( iNOW - m_iLastSendTime ) < m_iMaxMilliSeconds ) @@ -1657,7 +1663,8 @@ unsigned long long Csock::GetRateTime() { return( m_iMaxMilliSeconds ); } void Csock::Cron() { - time_t iNow = time( NULL ); + time_t iNow = 0; + for( vector::size_type a = 0; a < m_vcCrons.size(); a++ ) { CCron *pcCron = m_vcCrons[a]; diff --git a/Csocket.h b/Csocket.h index 5fa5a488..82613cd7 100644 --- a/Csocket.h +++ b/Csocket.h @@ -366,7 +366,7 @@ public: virtual ~CCron() {} //! This is used by the Job Manager, and not you directly - void run( time_t iNow ); + void run( time_t & iNow ); /** * @param TimeSequence how often to run in seconds @@ -939,8 +939,8 @@ public: m_bindhost.SetAFRequire( iAFRequire ); } - //! returns true if this socket can write its data, primarily used with rate shaping - bool AllowWrite( unsigned long long iNOW ) const; + //! returns true if this socket can write its data, primarily used with rate shaping, initialize iNOW to 0 and it sets it on the first call + bool AllowWrite( unsigned long long & iNOW ) const; private: u_short m_iport, m_iRemotePort, m_iLocalPort; @@ -1750,7 +1750,7 @@ private: bool bHasWriteable = false; bool bHasAvailSocks = false; - unsigned long long iNOW = millitime(); + unsigned long long iNOW = 0; for( unsigned int i = 0; i < this->size(); i++ ) { @@ -1994,7 +1994,7 @@ private: //! these crons get ran and checked in Loop() virtual void Cron() { - time_t iNow = time( NULL ); + time_t iNow = 0; for( unsigned int a = 0; a < m_vcCrons.size(); a++ ) { CCron *pcCron = m_vcCrons[a];