chiark / gitweb /
Implement hooks for foreign select-using systems (currently not well
[mLib] / sel.h
diff --git a/sel.h b/sel.h
index 8d121ef4bbed5b5f8bf134ffaad28e64d49835c0..c2aa57f6f99bb6b384d28c4222bcd15440697f7d 100644 (file)
--- a/sel.h
+++ b/sel.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: sel.h,v 1.4 1999/05/22 13:39:15 mdw Exp $
+ * $Id: sel.h,v 1.5 1999/08/19 18:30:26 mdw Exp $
  *
  * I/O multiplexing support
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: sel.h,v $
+ * Revision 1.5  1999/08/19 18:30:26  mdw
+ * Implement hooks for foreign select-using systems (currently not well
+ * tested).
+ *
  * Revision 1.4  1999/05/22 13:39:15  mdw
  * Change spelling of `multiplexor'. ;-)
  *
 
 /*----- Data structures ---------------------------------------------------*/
 
+/* --- A multiplexor --- *
+ *
+ * The files are sorted in reverse order of file descriptor number; the
+ * timers are in normal order of occurrence.  Thus, the interesting one
+ * is always at the front of the list.
+ */
+
+enum {
+  SEL_READ,
+  SEL_WRITE,
+  SEL_EXC,
+  SEL_MODES
+};
+
+typedef struct sel_state {
+  struct sel_file *files;
+  struct sel_timer *timers;
+  struct sel_hook *hooks;
+  fd_set fd[SEL_MODES];
+  struct timeval tv;
+} sel_state;
+
 /* --- Listening for a file --- */
 
 typedef struct sel_file {
@@ -107,36 +133,40 @@ typedef struct sel_file {
   void *p;
 } sel_file;
 
-enum {
-  SEL_READ,
-  SEL_WRITE,
-  SEL_EXC,
-  SEL_MODES
-};
-
 /* --- Waiting for a timeout --- */
 
 typedef struct sel_timer {
   struct sel_timer *next;
   struct sel_timer *prev;
   struct timeval tv;
-  void (*func)(struct timeval *tv, void *p);
+  void (*func)(struct timeval */*tv*/, void */*p*/);
   void *p;
 } sel_timer;
 
-/* --- A multiplexor --- *
+/* --- A select argument block --- */
+
+typedef struct sel_args {
+  int maxfd;
+  fd_set fd[SEL_MODES];
+  struct timeval tv, *tvp;
+  struct timeval now;
+} sel_args;
+
+/* --- A selector hook --- *
  *
- * The files are sorted in reverse order of file descriptor number; the
- * timers are in normal order of occurrence.  Thus, the interesting one
- * is always at the front of the list.
+ * The hooks are called (in arbitrary order) on each select.
  */
 
-typedef struct sel_state {
-  struct sel_file *files;
-  struct sel_timer *timers;
-  fd_set fd[SEL_MODES];
-  struct timeval tv;
-} sel_state;
+typedef void (*sel_hookfn)(sel_state */*s*/,
+                          sel_args */*a*/,
+                          void */*p*/);
+
+typedef struct sel_hook {
+  struct sel_hook *next;
+  struct sel_hook *prev;
+  sel_hookfn before, after;
+  void *p;
+} sel_hook;
 
 /*----- Functions provided ------------------------------------------------*/
 
@@ -201,7 +231,6 @@ extern void sel_rmfile(sel_file */*f*/);
  * Arguments:  @sel_state *s@ = pointer to a state block
  *             @sel_timer *t@ = pointer to a timer block
  *             @struct timeval *tv@ = pointer to time to activate
- *             @void (*func)(struct timeval *tv, void *p)@ = handler
  *             @void *p@ = argument for handler function
  *
  * Returns:    ---
@@ -226,6 +255,47 @@ extern void sel_addtimer(sel_state */*s*/, sel_timer */*t*/,
 
 extern void sel_rmtimer(sel_timer */*t*/);
 
+/* --- @sel_addhook@ --- *
+ *
+ * Arguments:  @sel_state *s@ = pointer to state block
+ *             @sel_hook *h@ = pointer to hook block
+ *             @sel_hookfn before, after@ = hook functions
+ *             @void *p@ = pointer argument to pass to hook functions
+ *
+ * Returns:    ---
+ *
+ * Use:                Registers hook functions to be called on each select call.
+ */
+
+extern void sel_addhook(sel_state */*s*/, sel_hook */*h*/,
+                       sel_hookfn /*before*/, sel_hookfn /*after*/,
+                       void */*p*/);
+
+/* --- @sel_rmhook@ --- *
+ *
+ * Arguments:  @sel_hook *h@ = pointer to hook block
+ *
+ * Returns:    ---
+ *
+ * Use:                Removes hook functions.
+ */
+
+extern void sel_rmhook(sel_hook */*h*/);
+
+/* --- @sel_fdmerge@ --- *
+ *
+ * Arguments:  @fd_set *dest@ = destination FD set
+ *             @fd_set *fd@ = pointer to set to merge
+ *             @int maxfd@ = highest numbered descriptor in @fd@ + 1
+ *
+ * Returns:    Actual highest numbered descriptor.
+ *
+ * Use:                Merges file descriptor sets, and returns an accurate @maxfd@
+ *             value.
+ */
+
+extern int sel_fdmerge(fd_set */*dest*/, fd_set */*fd*/, int /*maxfd*/);
+
 /* --- @sel_select@ --- *
  *
  * Arguments:  @sel_state *s@ = pointer to state block