* 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
//! 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;
//! 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 );
}
} else
CS_Delete( NewpcSock );
}
+#ifdef _WIN32
+ else if( GetSockError() != WSAEWOULDBLOCK )
+#else /* _WIN32 */
+ else if( GetSockError() != EAGAIN )
+#endif /* _WIN32 */
+ {
+ pcSock->SockError( GetSockError() );
+ }
}
}
}
{
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;
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