Update to latest Csocket

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1159 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
psychon
2008-08-18 11:10:27 +00:00
parent 5f0846fc9a
commit c3b6a4b29a
2 changed files with 40 additions and 15 deletions
+4 -2
View File
@@ -28,7 +28,7 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* $Revision: 1.80 $
* $Revision: 1.82 $
*/
#include "Csocket.h"
@@ -388,6 +388,7 @@ CCron::CCron()
m_iTime = 0;
m_iTimeSequence = 60;
m_bPause = false;
m_bRunOnNextCall = false;
}
void CCron::run( time_t & iNow )
@@ -398,8 +399,9 @@ void CCron::run( time_t & iNow )
if( iNow == 0 )
iNow = time( NULL );
if ( ( m_bActive ) && ( iNow >= m_iTime ) )
if ( ( m_bActive ) && ( iNow >= m_iTime || m_bRunOnNextCall ) )
{
m_bRunOnNextCall = false; // Setting this here because RunJob() could set it back to true
RunJob();
if ( ( m_iMaxCycles > 0 ) && ( ++m_iCycles >= m_iMaxCycles ) )
+36 -13
View File
@@ -28,7 +28,7 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* $Revision: 1.191 $
* $Revision: 1.195 $
*/
// note to compile with win32 need to link to winsock2, using gcc its -lws2_32
@@ -375,6 +375,9 @@ public:
//! this is the method you should override
virtual void RunJob();
protected:
bool m_bRunOnNextCall; //!< if set to true, RunJob() gets called on next invocation of run() despite the timeout
private:
time_t m_iTime;
bool m_bActive, m_bPause;
@@ -1589,9 +1592,11 @@ public:
//! returns a pointer to the FIRST sock found by name or NULL on no match
virtual T * FindSockByName( const CS_STRING & sName )
{
for( unsigned int i = 0; i < this->size(); i++ )
if ( (*this)[i]->GetSockName() == sName )
return( (*this)[i] );
typename std::vector<T *>::iterator it;
typename std::vector<T *>::iterator it_end = this->end();
for( it = this->begin(); it != it_end; it++ )
if ( (*it)->GetSockName() == sName )
return( *it );
return( NULL );
}
@@ -2062,6 +2067,14 @@ private:
} else
CS_Delete( NewpcSock );
}
#ifdef _WIN32
else if( GetSockError() != WSAEWOULDBLOCK )
#else /* _WIN32 */
else if( GetSockError() != EAGAIN )
#endif /* _WIN32 */
{
pcSock->SockError( GetSockError() );
}
}
}
}
@@ -2071,15 +2084,21 @@ private:
{
time_t iNextRunTime = iNow + iMaxResolution;
time_t iMinTimeout = iMaxResolution;
for( u_long a = 0; a < this->size() && iMinTimeout; a++ )
typename std::vector<T *>::const_iterator it;
// This is safe, because we don't modify the vector.
typename std::vector<T *>::const_iterator it_end = this->end();
for (it = this->begin(); it != it_end; it++)
{
if( (*this)[a]->GetConState() != T::CST_OK )
T* pSock = *it;
if( pSock->GetConState() != T::CST_OK )
iMinTimeout = 0; // this is in a nebulous state, need to let it proceed like normal
time_t iTimeoutInSeconds = (*this)[a]->GetTimeout();
time_t iTimeoutInSeconds = pSock->GetTimeout();
if( iTimeoutInSeconds > 0 )
{
time_t iLastTimeData = (*this)[a]->GetLastCheckTimeout();
time_t iLastTimeData = pSock->GetLastCheckTimeout();
time_t iDiff = iNow - iLastTimeData;
if( iDiff > iTimeoutInSeconds )
iTimeoutInSeconds = 0;
@@ -2089,12 +2108,16 @@ private:
iMinTimeout = std::min( iMinTimeout, iTimeoutInSeconds );
}
const std::vector<CCron *> & vCrons = (*this)[a]->GetCrons();
for( u_long b = 0; b < vCrons.size(); b++ )
iNextRunTime = std::min( iNextRunTime, vCrons[b]->GetNextRun() );
const std::vector<CCron *> & vCrons = pSock->GetCrons();
std::vector<CCron *>::const_iterator cit;
std::vector<CCron *>::const_iterator cit_end = vCrons.end();
for (cit = vCrons.begin(); cit != cit_end; it++)
iNextRunTime = std::min( iNextRunTime, (*cit)->GetNextRun() );
}
for( u_long a = 0; a < m_vcCrons.size(); a++ )
iNextRunTime = std::min( iNextRunTime, m_vcCrons[a]->GetNextRun() );
std::vector<CCron *>::const_iterator cit;
std::vector<CCron *>::const_iterator cit_end = m_vcCrons.end();
for (cit = m_vcCrons.begin(); cit != cit_end; cit++)
iNextRunTime = std::min( iNextRunTime, (*cit)->GetNextRun() );
if( iNextRunTime < iNow )
return( 0 ); // smallest unit possible