File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / thttpd / fdwatch.h
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 17:21:13 2012 UTC (12 years, 3 months ago) by misho
Branches: thttpd, MAIN
CVS tags: v2_25b, HEAD
thttpd

    1: /* fdwatch.h - header file for fdwatch package
    2: **
    3: ** This package abstracts the use of the select()/poll()/kqueue()
    4: ** system calls.  The basic function of these calls is to watch a set
    5: ** of file descriptors for activity.  select() originated in the BSD world,
    6: ** while poll() came from SysV land, and their interfaces are somewhat
    7: ** different.  fdwatch lets you write your code to a single interface,
    8: ** with the portability differences hidden inside the package.
    9: **
   10: ** Usage is fairly simple.  Call fdwatch_get_nfiles() to initialize
   11: ** the package and find out how many fine descriptors are available.
   12: ** Then each time through your main loop, call fdwatch_clear(), then
   13: ** fdwatch_add_fd() for each of the descriptors you want to watch,
   14: ** then call fdwatch() to actually perform the watch.  After it returns
   15: ** you can check which descriptors are ready via fdwatch_check_fd().
   16: **
   17: ** If your descriptor set hasn't changed from the last time through
   18: ** the loop, you can skip calling fdwatch_clear() and fdwatch_add_fd()
   19: ** to save a little CPU time.
   20: **
   21: **
   22: ** Copyright © 1999 by Jef Poskanzer <jef@mail.acme.com>.
   23: ** All rights reserved.
   24: **
   25: ** Redistribution and use in source and binary forms, with or without
   26: ** modification, are permitted provided that the following conditions
   27: ** are met:
   28: ** 1. Redistributions of source code must retain the above copyright
   29: **    notice, this list of conditions and the following disclaimer.
   30: ** 2. Redistributions in binary form must reproduce the above copyright
   31: **    notice, this list of conditions and the following disclaimer in the
   32: **    documentation and/or other materials provided with the distribution.
   33: **
   34: ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   35: ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   36: ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   37: ** ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   38: ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   39: ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   40: ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   41: ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   42: ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   43: ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   44: ** SUCH DAMAGE.
   45: */
   46: 
   47: #ifndef _FDWATCH_H_
   48: #define _FDWATCH_H_
   49: 
   50: #define FDW_READ 0
   51: #define FDW_WRITE 1
   52: 
   53: #ifndef INFTIM
   54: #define INFTIM -1
   55: #endif /* INFTIM */
   56: 
   57: /* Figure out how many file descriptors the system allows, and
   58: ** initialize the fdwatch data structures.  Returns -1 on failure.
   59: */
   60: extern int fdwatch_get_nfiles( void );
   61: 
   62: /* Add a descriptor to the watch list.  rw is either FDW_READ or FDW_WRITE.  */
   63: extern void fdwatch_add_fd( int fd, void* client_data, int rw );
   64: 
   65: /* Delete a descriptor from the watch list. */
   66: extern void fdwatch_del_fd( int fd );
   67: 
   68: /* Do the watch.  Return value is the number of descriptors that are ready,
   69: ** or 0 if the timeout expired, or -1 on errors.  A timeout of INFTIM means
   70: ** wait indefinitely.
   71: */
   72: extern int fdwatch( long timeout_msecs );
   73: 
   74: /* Check if a descriptor was ready. */
   75: extern int fdwatch_check_fd( int fd );
   76: 
   77: /* Get the client data for the next returned event.  Returns -1 when there
   78: ** are no more events.
   79: */
   80: extern void* fdwatch_get_next_client_data( void );
   81: 
   82: /* Generate debugging statistics syslog message. */
   83: extern void fdwatch_logstats( long secs );
   84: 
   85: #endif /* _FDWATCH_H_ */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>