blocxx
Public Member Functions | Private Member Functions | Private Attributes

BLOCXX_NAMESPACE::TimeoutTimer Class Reference

A TimeoutTimer is used by an algorithm to determine when a timeout has expired. More...

#include <TimeoutTimer.hpp>

List of all members.

Public Member Functions

 TimeoutTimer (const Timeout &x)
virtual ~TimeoutTimer ()
void start ()
 Meant to be called by timeout functions which loop.
void resetOnLoop ()
 Meant to be called by timeout functions which loop, and that want to reset the interval.
void loop ()
 Meant to be called by timeout functions which loop, but don't want to reset the interval.
bool expired () const
 Indicates whether the last loop time has exceeded the timeout.
bool infinite () const
 Indicates whether the timeout will never expire.
Timeout asTimeout () const
Timeout asRelativeTimeout () const
Timeout asRelativeTimeout (double maxSeconds) const
Timeout asAbsoluteTimeout () const
 Converts the timer to an absolute timeout.
int asIntMs () const
int asIntMs (double maxSeconds) const

Private Member Functions

double calcSeconds () const
double calcSeconds (double maxSeconds) const
virtual DateTime getCurrentTime () const

Private Attributes

Timeout m_timeout
DateTime m_start
DateTime m_loopTime

Detailed Description

A TimeoutTimer is used by an algorithm to determine when a timeout has expired.

It is used like this:

TimeoutTimer timer(theTimeout); while (... && !timer.expired()) { // wait for something to happen, maybe calling select() or something else. struct timeval tv; select(... , timer.asTimeval(tv));

... // processing

if (something happened that might reset the interval) timer.resetOnLoop(); else timer.loop(); }

Definition at line 75 of file TimeoutTimer.hpp.


Constructor & Destructor Documentation

BLOCXX_NAMESPACE::TimeoutTimer::TimeoutTimer ( const Timeout x)

Definition at line 48 of file TimeoutTimer.cpp.

BLOCXX_NAMESPACE::TimeoutTimer::~TimeoutTimer ( ) [virtual]

Definition at line 55 of file TimeoutTimer.cpp.


Member Function Documentation

Timeout BLOCXX_NAMESPACE::TimeoutTimer::asAbsoluteTimeout ( ) const
int BLOCXX_NAMESPACE::TimeoutTimer::asIntMs ( ) const

Definition at line 300 of file TimeoutTimer.cpp.

References calcSeconds(), and infinite().

Referenced by BLOCXX_NAMESPACE::Select::selectRWEpoll().

int BLOCXX_NAMESPACE::TimeoutTimer::asIntMs ( double  maxSeconds) const

Definition at line 313 of file TimeoutTimer.cpp.

References calcSeconds(), infinite(), and INFINITY.

Timeout BLOCXX_NAMESPACE::TimeoutTimer::asRelativeTimeout ( double  maxSeconds) const

Definition at line 247 of file TimeoutTimer.cpp.

References calcSeconds(), and BLOCXX_NAMESPACE::Timeout::relative().

Timeout BLOCXX_NAMESPACE::TimeoutTimer::asRelativeTimeout ( ) const
Timeout BLOCXX_NAMESPACE::TimeoutTimer::asTimeout ( ) const

Definition at line 207 of file TimeoutTimer.cpp.

References m_timeout.

Referenced by BLOCXX_NAMESPACE::SelectEngine::go().

double BLOCXX_NAMESPACE::TimeoutTimer::calcSeconds ( double  maxSeconds) const [private]

Definition at line 233 of file TimeoutTimer.cpp.

References calcSeconds().

double BLOCXX_NAMESPACE::TimeoutTimer::calcSeconds ( ) const [private]
bool BLOCXX_NAMESPACE::TimeoutTimer::expired ( ) const
DateTime BLOCXX_NAMESPACE::TimeoutTimer::getCurrentTime ( ) const [private, virtual]

Definition at line 367 of file TimeoutTimer.cpp.

References BLOCXX_NAMESPACE::DateTime::getCurrent().

Referenced by loop(), and start().

bool BLOCXX_NAMESPACE::TimeoutTimer::infinite ( ) const

Indicates whether the timeout will never expire.

Definition at line 133 of file TimeoutTimer.cpp.

References m_timeout.

Referenced by asAbsoluteTimeout(), asIntMs(), and expired().

void BLOCXX_NAMESPACE::TimeoutTimer::loop ( )

Meant to be called by timeout functions which loop, but don't want to reset the interval.

It should be called each time through the loop. Either resetOnLoop() or loop() should be called each time through the loop, but not both.

Definition at line 76 of file TimeoutTimer.cpp.

References getCurrentTime(), and m_loopTime.

Referenced by calcSeconds(), BLOCXX_NAMESPACE::SocketBaseImpl::connect(), resetOnLoop(), BLOCXX_NAMESPACE::Select::selectRWEpoll(), BLOCXX_NAMESPACE::Select::selectRWSelect(), and BLOCXX_NAMESPACE::ThreadImpl::sleep().

void BLOCXX_NAMESPACE::TimeoutTimer::resetOnLoop ( )

Meant to be called by timeout functions which loop, and that want to reset the interval.

It should be called each time through the loop. For a relative with reset timeout it will reset the interval. Either resetOnLoop() or loop() should be called each time through the loop, but not both.

Definition at line 66 of file TimeoutTimer.cpp.

References BLOCXX_NAMESPACE::Timeout::E_RELATIVE_WITH_RESET, BLOCXX_NAMESPACE::Timeout::getType(), loop(), m_loopTime, m_start, and m_timeout.

Referenced by BLOCXX_NAMESPACE::SelectEngine::go().

void BLOCXX_NAMESPACE::TimeoutTimer::start ( )

Meant to be called by timeout functions which loop.

Normally, it should be called once, at the beginning of the function. The time this is called marks the beginning of a relative interval. For an absolute timeout, it does nothing. It is not necessary to call this function, only if the time the constructor ran isn't desireable to be used as the start time.

Definition at line 60 of file TimeoutTimer.cpp.

References getCurrentTime(), m_loopTime, and m_start.

Referenced by calcSeconds(), BLOCXX_NAMESPACE::SocketBaseImpl::connect(), BLOCXX_NAMESPACE::SelectEngine::go(), BLOCXX_NAMESPACE::Select::selectRWEpoll(), and BLOCXX_NAMESPACE::Select::selectRWSelect().


Member Data Documentation

Definition at line 154 of file TimeoutTimer.hpp.

Referenced by calcSeconds(), expired(), loop(), resetOnLoop(), and start().

Definition at line 153 of file TimeoutTimer.hpp.

Referenced by asAbsoluteTimeout(), calcSeconds(), expired(), resetOnLoop(), and start().


The documentation for this class was generated from the following files: