chiark / gitweb /
buf: Fix two embarassing bugs found while writing Lisp bindings.
[mLib] / sel.h
diff --git a/sel.h b/sel.h
index c2aa57f6f99bb6b384d28c4222bcd15440697f7d..fe7e2c1bd326bb2083d2d266f887b77f2aab552d 100644 (file)
--- a/sel.h
+++ b/sel.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: sel.h,v 1.5 1999/08/19 18:30:26 mdw Exp $
+ * $Id: sel.h,v 1.10 2004/04/08 01:36:13 mdw Exp $
  *
  * I/O multiplexing support
  *
  * MA 02111-1307, USA.
  */
 
-/*----- 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'. ;-)
- *
- * Revision 1.3  1999/05/17 20:36:36  mdw
- * Make the selector type symbols an enumeration rather than a bunch of
- * #defines.
- *
- * Revision 1.2  1999/05/15 10:33:32  mdw
- * Fix copyright notices.
- *
- * Revision 1.1  1999/05/14 21:01:15  mdw
- * Integrated `select' handling bits from the background resolver project.
- *
- */
-
-#ifndef SEL_H
-#define SEL_H
+#ifndef MLIB_SEL_H
+#define MLIB_SEL_H
 
 #ifdef __cplusplus
   extern "C" {
  */
 
 enum {
-  SEL_READ,
-  SEL_WRITE,
-  SEL_EXC,
-  SEL_MODES
+  SEL_READ,                            /* File is ready to read */
+  SEL_WRITE,                           /* File is ready to write */
+  SEL_EXC,                             /* Something odd has happened */
+  SEL_MODES                            /* Number of modes available */
 };
 
 typedef struct sel_state {
-  struct sel_file *files;
-  struct sel_timer *timers;
-  struct sel_hook *hooks;
-  fd_set fd[SEL_MODES];
-  struct timeval tv;
+  struct sel_file *files[SEL_MODES];   /* Lists of interesting files */
+  struct sel_timer *timers;            /* List of timers */
+  struct sel_hook *hooks;              /* List of hook functions applied */
+  fd_set fd[SEL_MODES];                        /* Quick reference table for files */
+  struct sel_args *args;               /* Pointer to arguments */
 } sel_state;
 
 /* --- Listening for a file --- */
 
 typedef struct sel_file {
-  struct sel_file *next;
-  struct sel_file *prev;
-  struct sel_state *s;
-  int fd;
-  unsigned mode;
-  void (*func)(int /*fd*/, unsigned /*mode*/, void */*p*/);
-  void *p;
+  struct sel_file *next;               /* Next file in the list */
+  struct sel_file **prev;              /* Previous file in the list */
+  struct sel_state *s;                 /* Pointer to select multiplexor */
+  int fd;                              /* File descriptor */
+  unsigned mode;                       /* Interesting event for file */
+  void (*func)(int /*fd*/, unsigned /*mode*/, void */*p*/); /* Handler */
+  void *p;                             /* Argument for the handler */
+  struct sel_pendfile *pend;           /* Pending file information */
 } sel_file;
 
 /* --- 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 *p;
+  struct sel_timer *next;              /* Next timer in the list */
+  struct sel_timer **prev;             /* Previous timer in the list */
+  struct timeval tv;                   /* Real time when timer should go */
+  void (*func)(struct timeval */*tv*/, void */*p*/); /* Handler function */
+  void *p;                             /* Argument for the handler */
+  struct sel_pendtimer *pend;          /* Pending timer information */
 } sel_timer;
 
 /* --- A select argument block --- */
 
 typedef struct sel_args {
-  int maxfd;
-  fd_set fd[SEL_MODES];
-  struct timeval tv, *tvp;
-  struct timeval now;
+  int maxfd;                           /* Highest-numbered file */
+  fd_set fd[SEL_MODES];                        /* Bit flags for all the files */
+  struct timeval tv, *tvp;             /* Time to return */
+  struct timeval now;                  /* Current time */
 } sel_args;
 
 /* --- A selector hook --- *
@@ -162,10 +142,10 @@ typedef void (*sel_hookfn)(sel_state */*s*/,
                           void */*p*/);
 
 typedef struct sel_hook {
-  struct sel_hook *next;
-  struct sel_hook *prev;
-  sel_hookfn before, after;
-  void *p;
+  struct sel_hook *next;               /* Next hook in the list */
+  struct sel_hook **prev;              /* Previous hook in the list */
+  sel_hookfn before, after;            /* Hook functions */
+  void *p;                             /* Argument for the hook functions */
 } sel_hook;
 
 /*----- Functions provided ------------------------------------------------*/
@@ -226,6 +206,20 @@ extern void sel_addfile(sel_file */*f*/);
 
 extern void sel_rmfile(sel_file */*f*/);
 
+/* --- @sel_force@ --- *
+ *
+ * Arguments:  @sel_file *f@ = pointer to file selector
+ *
+ * Returns:    ---
+ *
+ * Use:                Forces a file selector to be considered ready.  This is only
+ *             useful during a call to @sel_select@.  Of particular use is
+ *             forcing a write selector when there's something interesting
+ *             ready for it.
+ */
+
+extern void sel_force(sel_file */*f*/);
+
 /* --- @sel_addtimer@ --- *
  *
  * Arguments:  @sel_state *s@ = pointer to a state block