Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

wvtimestream.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  */ 
00006 #ifndef __WVTIMESTREAM_H
00007 #define __WVTIMESTREAM_H
00008 
00009 #include "wvtimeutils.h"
00010 #include "wvstream.h"
00011 
00012 /**
00013  * WvTimeStream causes select() to be true after a configurable number
00014  * of milliseconds.  Because programs using WvStream make no guarantees
00015  * about how often select() will be called, WvTimeStream tries to adjust
00016  * its timing to a correct _average_ number of milliseconds per tick.
00017  * 
00018  * For example, if ms_per_tick=100, WvTimeStream will tick 10 times in one
00019  * second.  However, there may be a few milliseconds of difference
00020  * ("jitter") for each individual tick, due to random system delays.
00021  */
00022 class WvTimeStream : public WvStream
00023 {
00024     WvTime last;
00025     WvTime next;
00026     time_t ms_per_tick;
00027 
00028 public:
00029     WvTimeStream();
00030     
00031     /**
00032      * Every 'msec' milliseconds, select() will return true on this
00033      * stream.  if 'msec' is 0 (or less), the timer is disabled.
00034      *
00035      * Be careful when mixing alarm() with this. You can know whether
00036      * it was the alarm or if you had a timer event by looking at
00037      * alarm_was_ticking. But the alarm() has priority, so if there's
00038      * always an alarm, the timer event never gets to run. Calling
00039      * alarm(0) in the callback unconditionally would thus be a bad
00040      * idea, or even with an unsuitably small number (say, less than
00041      * the time it takes to go back into select()). So don't do it.
00042      */
00043     void set_timer(time_t msec);
00044 
00045     virtual bool isok() const;
00046     virtual bool pre_select(SelectInfo &si);
00047     virtual bool post_select(SelectInfo &si);
00048     virtual void execute();
00049 };
00050 
00051 
00052 #endif // __WVTIMESTREAM_H

Generated on Sat Mar 13 14:56:00 2004 for WvStreams by doxygen 1.3.6-20040222