summaryrefslogtreecommitdiffstats
path: root/maildrop/alarm.h
diff options
context:
space:
mode:
Diffstat (limited to 'maildrop/alarm.h')
-rw-r--r--maildrop/alarm.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/maildrop/alarm.h b/maildrop/alarm.h
new file mode 100644
index 0000000..01d926c
--- /dev/null
+++ b/maildrop/alarm.h
@@ -0,0 +1,42 @@
+#ifndef alarm_h
+#define alarm_h
+
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// This is an asynchronous timer function that is driven by the alarm()
+// system call. I attempt to implement here a half-baked multiple timer
+// feature.
+//
+// Note - you can't really do a lot in a signal handler, stick to setting
+// global flags, and making system calls ( **NOT** standard library calls).
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include "config.h"
+
+class Alarm;
+
+class Alarm {
+
+static Alarm *first, *last;
+
+ Alarm *next, *prev; // List sorted by expiration interval.
+ unsigned set_interval; // For how many seconds we're set.
+
+ void Unlink();
+
+static void cancel_sig(unsigned);
+static void set_sig();
+static RETSIGTYPE alarm_func(int);
+static unsigned sig_left();
+public:
+ Alarm() : next(0), prev(0), set_interval(0) {}
+ virtual ~Alarm();
+
+ virtual void handler()=0;
+
+ void Set(unsigned);
+ void Cancel();
+} ;
+#endif