Back to index

courier  0.68.2
alarm.h
Go to the documentation of this file.
00001 #ifndef       alarm_h
00002 #define       alarm_h
00003 
00004 
00006 //
00007 // This is an asynchronous timer function that is driven by the alarm()
00008 // system call.  I attempt to implement here a half-baked multiple timer
00009 // feature.
00010 //
00011 // Note - you can't really do a lot in a signal handler, stick to setting
00012 // global flags, and making system calls ( **NOT** standard library calls).
00013 //
00015 
00016 #include      "config.h"
00017 
00018 class Alarm;
00019 
00020 class Alarm {
00021 
00022 static Alarm *first, *last;
00023 
00024        Alarm *next, *prev;  // List sorted by expiration interval.
00025        unsigned set_interval;      // For how many seconds we're set.
00026 
00027        void   Unlink();
00028 
00029 static void cancel_sig(unsigned);
00030 static void set_sig();
00031 static RETSIGTYPE alarm_func(int);
00032 static unsigned sig_left();
00033 public:
00034        Alarm() : next(0), prev(0), set_interval(0)      {}
00035        virtual ~Alarm();
00036 
00037        virtual void handler()=0;
00038 
00039        void   Set(unsigned);
00040        void   Cancel();
00041 } ;
00042 #endif