blocxx
BLOCXX_NAMESPACE::TimeoutTimer Class Reference

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
 

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

◆ TimeoutTimer()

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

Definition at line 48 of file TimeoutTimer.cpp.

◆ ~TimeoutTimer()

BLOCXX_NAMESPACE::TimeoutTimer::~TimeoutTimer ( )
virtual

Definition at line 55 of file TimeoutTimer.cpp.

Member Function Documentation

◆ asAbsoluteTimeout()

◆ asIntMs() [1/2]

int BLOCXX_NAMESPACE::TimeoutTimer::asIntMs ( ) const

◆ asIntMs() [2/2]

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

Definition at line 313 of file TimeoutTimer.cpp.

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

◆ asRelativeTimeout() [1/2]

Timeout BLOCXX_NAMESPACE::TimeoutTimer::asRelativeTimeout ( ) const

◆ asRelativeTimeout() [2/2]

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

Definition at line 247 of file TimeoutTimer.cpp.

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

◆ asTimeout()

Timeout BLOCXX_NAMESPACE::TimeoutTimer::asTimeout ( ) const

Definition at line 207 of file TimeoutTimer.cpp.

References m_timeout.

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

◆ calcSeconds() [1/2]

◆ calcSeconds() [2/2]

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

Definition at line 233 of file TimeoutTimer.cpp.

References calcSeconds().

◆ expired()

◆ getCurrentTime()

DateTime BLOCXX_NAMESPACE::TimeoutTimer::getCurrentTime ( ) const
privatevirtual

Definition at line 367 of file TimeoutTimer.cpp.

References BLOCXX_NAMESPACE::DateTime::getCurrent().

Referenced by loop(), and start().

◆ infinite()

bool BLOCXX_NAMESPACE::TimeoutTimer::infinite ( ) const

Indicates whether the timeout will never expire.

Definition at line 133 of file TimeoutTimer.cpp.

References BLOCXX_NAMESPACE::Timeout::infinite, and m_timeout.

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

◆ loop()

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(), BLOCXX_NAMESPACE::Exec::processInputOutput(), resetOnLoop(), BLOCXX_NAMESPACE::Select::selectRWEpoll(), BLOCXX_NAMESPACE::Select::selectRWPoll(), BLOCXX_NAMESPACE::Select::selectRWSelect(), BLOCXX_NAMESPACE::ThreadImpl::sleep(), and BLOCXX_NAMESPACE::Process::terminatesWithin().

◆ resetOnLoop()

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(), and BLOCXX_NAMESPACE::Exec::processInputOutput().

◆ start()

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::Exec::processInputOutput(), BLOCXX_NAMESPACE::Select::selectRWEpoll(), BLOCXX_NAMESPACE::Select::selectRWPoll(), and BLOCXX_NAMESPACE::Select::selectRWSelect().

Member Data Documentation

◆ m_loopTime

DateTime BLOCXX_NAMESPACE::TimeoutTimer::m_loopTime
private

Definition at line 154 of file TimeoutTimer.hpp.

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

◆ m_start

DateTime BLOCXX_NAMESPACE::TimeoutTimer::m_start
private

Definition at line 153 of file TimeoutTimer.hpp.

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

◆ m_timeout

Timeout BLOCXX_NAMESPACE::TimeoutTimer::m_timeout
private

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