Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

WvTimeStream Class Reference

#include <wvtimestream.h>

Inheritance diagram for WvTimeStream:

WvStream WvStream List of all members.

Public Methods

 WvTimeStream ()
void set_timer (int msec, int max_backlog=10)
virtual bool isok () const
virtual bool pre_select (SelectInfo &si)
virtual bool post_select (SelectInfo &si)
void WvTimeStream::tick ()
virtual void execute ()
 WvTimeStream ()
void set_timer (int msec, int max_backlog=10)
virtual bool isok () const
virtual bool pre_select (SelectInfo &si)
virtual bool post_select (SelectInfo &si)
void WvTimeStream::tick ()
virtual void execute ()

Private Attributes

timeval last_tv
int ms_per_tick
int max_backlog
timeval last_tv

Detailed Description

WvTimeStream causes select() to be true after a configurable number of milliseconds. Because programs using WvStream make no guarantees about how often select() will be called, WvTimeStream tries to adjust its timing to a correct _average_ number of milliseconds per tick.

For example, if ms_per_tick=100, WvTimeStream will tick 10 times in one second. However, there may be a few milliseconds of difference ("jitter") for each individual tick, due to random system delays.

Note that the time delay given to list.select() is very important, because it determines the granularity of the timing. select(1000) will allow ticks only every 1000 ms. If ms_per_tick=100, then WvTimeStream will tick about 10 times (all at once) every second. select(-1) (wait forever) may never tick at all -- be careful.

Definition at line 27 of file include/wvtimestream.h.


Constructor & Destructor Documentation

WvTimeStream::WvTimeStream  
 

Definition at line 9 of file wvtimestream.cc.

References last_tv, max_backlog, and ms_per_tick.

WvTimeStream::WvTimeStream  
 


Member Function Documentation

virtual void WvTimeStream::execute   [virtual]
 

The callback() function calls execute(), and then calls the user- specified callback if one is defined. Do not call execute() directly; call callback() instead.

The default execute() function does nothing.

Note: If you override this function in a derived class, you must call the parent execute() yourself from the derived class.

Reimplemented from WvStream.

void WvTimeStream::execute   [virtual]
 

The callback() function calls execute(), and then calls the user- specified callback if one is defined. Do not call execute() directly; call callback() instead.

The default execute() function does nothing.

Note: If you override this function in a derived class, you must call the parent execute() yourself from the derived class.

Reimplemented from WvStream.

Definition at line 83 of file wvtimestream.cc.

References WvStream::execute().

virtual bool WvTimeStream::isok   const [virtual]
 

return true if the stream is actually usable right now

Reimplemented from WvStream.

bool WvTimeStream::isok   const [virtual]
 

return true if the stream is actually usable right now

Reimplemented from WvStream.

Definition at line 29 of file wvtimestream.cc.

virtual bool WvTimeStream::post_select SelectInfo &    si [virtual]
 

post_select() is called after select(), and returns true if this object is now ready. Usually this is done by checking for this object in the read, write, and except lists in the SelectInfo structure. If you want to do it in some other way, you should usually do it in pre_select() instead. (post_select() _only_ gets called if select() returned true for _some_ stream or another.)

You may also want to do extra maintenance functions here; for example, the standard WvStream::post_select tries to flush outbuf if it's nonempty. WvTCPConn might retry connect() if it's waiting for a connection to be established.

Reimplemented from WvStream.

bool WvTimeStream::post_select SelectInfo &    si [virtual]
 

post_select() is called after select(), and returns true if this object is now ready. Usually this is done by checking for this object in the read, write, and except lists in the SelectInfo structure. If you want to do it in some other way, you should usually do it in pre_select() instead. (post_select() _only_ gets called if select() returned true for _some_ stream or another.)

You may also want to do extra maintenance functions here; for example, the standard WvStream::post_select tries to flush outbuf if it's nonempty. WvTCPConn might retry connect() if it's waiting for a connection to be established.

Reimplemented from WvStream.

Definition at line 65 of file wvtimestream.cc.

virtual bool WvTimeStream::pre_select SelectInfo &    si [virtual]
 

pre_select() sets up for eventually calling select(). It adds the right fds to the read, write, and except lists in the SelectInfo struct.

Returns true if we already know this stream is ready, and there's no need to actually do a real select(). Some streams, such as timers, can be implemented by _only_ either returning true or false here after doing a calculation, and never actually adding anything to the SelectInfo.

You can add your stream to any of the lists even if readable, writable, or isexception isn't set. This is what force_select() does. You can also choose not to add yourself to the list if you know it would be useless right now.

pre_select() is only called if isok() is true.

pre_select() is allowed to reduce msec_timeout (or change it if it's -1). However, it's not allowed to _increase_ msec_timeout.

Reimplemented from WvStream.

bool WvTimeStream::pre_select SelectInfo &    si [virtual]
 

pre_select() sets up for eventually calling select(). It adds the right fds to the read, write, and except lists in the SelectInfo struct.

Returns true if we already know this stream is ready, and there's no need to actually do a real select(). Some streams, such as timers, can be implemented by _only_ either returning true or false here after doing a calculation, and never actually adding anything to the SelectInfo.

You can add your stream to any of the lists even if readable, writable, or isexception isn't set. This is what force_select() does. You can also choose not to add yourself to the list if you know it would be useless right now.

pre_select() is only called if isok() is true.

pre_select() is allowed to reduce msec_timeout (or change it if it's -1). However, it's not allowed to _increase_ msec_timeout.

Reimplemented from WvStream.

Definition at line 35 of file wvtimestream.cc.

References last_tv, max_backlog, and ms_per_tick.

void WvTimeStream::set_timer int    msec,
int    max_backlog = 10
 

every 'msec' milliseconds, select() will return true on this stream. if 'msec' is 0, the timer is disabled.

void WvTimeStream::set_timer int    msec,
int    max_backlog = 10
 

every 'msec' milliseconds, select() will return true on this stream. if 'msec' is 0, the timer is disabled.

Definition at line 18 of file wvtimestream.cc.

References last_tv, max_backlog, and ms_per_tick.

void WvTimeStream::WvTimeStream::tick  
 

notify timestream that we have "ticked" once

void WvTimeStream::WvTimeStream::tick  
 

notify timestream that we have "ticked" once


Member Data Documentation

struct timeval WvTimeStream::last_tv [private]
 

Definition at line 29 of file streams/wvtimestream.h.

struct timeval WvTimeStream::last_tv [private]
 

Definition at line 29 of file include/wvtimestream.h.

Referenced by pre_select(), set_timer(), and WvTimeStream().

int WvTimeStream::max_backlog [private]
 

Definition at line 30 of file streams/wvtimestream.h.

Referenced by pre_select(), set_timer(), and WvTimeStream().

int WvTimeStream::ms_per_tick [private]
 

Definition at line 30 of file streams/wvtimestream.h.

Referenced by pre_select(), set_timer(), and WvTimeStream().


The documentation for this class was generated from the following files:
Generated on Sun Aug 25 12:43:13 2002 for WvStreams by doxygen1.2.15