blocxx
|
A TimeoutTimer is used by an algorithm to determine when a timeout has expired. More...
#include <TimeoutTimer.hpp>
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 |
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.
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.
Timeout BLOCXX_NAMESPACE::TimeoutTimer::asAbsoluteTimeout | ( | ) | const |
Converts the timer to an absolute timeout.
If the timer is infinite, the return will be an infinite relative timeout
Definition at line 253 of file TimeoutTimer.cpp.
References BLOCXX_NAMESPACE::Timeout::absolute(), BLOCXX_NAMESPACE::Timeout::E_ABSOLUTE, BLOCXX_NAMESPACE::DateTime::get(), BLOCXX_NAMESPACE::DateTime::getMicrosecond(), BLOCXX_NAMESPACE::Timeout::getRelative(), BLOCXX_NAMESPACE::Timeout::getType(), infinite(), m_start, and m_timeout.
Referenced by BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::acquireReadLock(), BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::acquireWriteLock(), BLOCXX_NAMESPACE::Thread::definitiveCancel(), BLOCXX_NAMESPACE::ThreadImpl::sleep(), BLOCXX_NAMESPACE::Thread::timedWait(), BLOCXX_NAMESPACE::Semaphore::timedWait(), and BLOCXX_NAMESPACE::Process::waitCloseTerm().
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 |
Definition at line 241 of file TimeoutTimer.cpp.
References calcSeconds(), and BLOCXX_NAMESPACE::Timeout::relative().
Referenced by BLOCXX_NAMESPACE::SocketBaseImpl::connect().
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] |
Definition at line 213 of file TimeoutTimer.cpp.
References BLOCXX_NAMESPACE::Timeout::E_ABSOLUTE, BLOCXX_NAMESPACE::DateTime::get(), BLOCXX_NAMESPACE::Timeout::getAbsolute(), BLOCXX_NAMESPACE::DateTime::getMicrosecond(), BLOCXX_NAMESPACE::Timeout::getRelative(), BLOCXX_NAMESPACE::Timeout::getType(), loop(), m_loopTime, m_start, m_timeout, and start().
Referenced by asIntMs(), asRelativeTimeout(), and calcSeconds().
bool BLOCXX_NAMESPACE::TimeoutTimer::expired | ( | ) | const |
Indicates whether the last loop time has exceeded the timeout.
The current time is not used, but the time when resetOnLoop() or loop() was called.
Definition at line 113 of file TimeoutTimer.cpp.
References BLOCXX_NAMESPACE::Timeout::E_ABSOLUTE, BLOCXX_NAMESPACE::Timeout::E_RELATIVE, BLOCXX_NAMESPACE::Timeout::E_RELATIVE_WITH_RESET, BLOCXX_NAMESPACE::Timeout::getAbsolute(), BLOCXX_NAMESPACE::Timeout::getRelative(), BLOCXX_NAMESPACE::Timeout::getType(), infinite(), m_loopTime, m_start, and m_timeout.
Referenced by BLOCXX_NAMESPACE::SocketBaseImpl::connect(), BLOCXX_NAMESPACE::Select::selectRWEpoll(), BLOCXX_NAMESPACE::Select::selectRWSelect(), and BLOCXX_NAMESPACE::ThreadImpl::sleep().
DateTime BLOCXX_NAMESPACE::TimeoutTimer::getCurrentTime | ( | ) | const [private, virtual] |
Definition at line 367 of file TimeoutTimer.cpp.
References BLOCXX_NAMESPACE::DateTime::getCurrent().
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().
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().
Definition at line 152 of file TimeoutTimer.hpp.
Referenced by asAbsoluteTimeout(), asTimeout(), calcSeconds(), expired(), infinite(), and resetOnLoop().