Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 1 | #ifndef Py_MYSELECT_H |
| 2 | #define Py_MYSELECT_H |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 7 | /*********************************************************** |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 8 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 9 | The Netherlands. |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 10 | |
| 11 | All Rights Reserved |
| 12 | |
| 13 | Permission to use, copy, modify, and distribute this software and its |
| 14 | documentation for any purpose and without fee is hereby granted, |
| 15 | provided that the above copyright notice appear in all copies and that |
| 16 | both that copyright notice and this permission notice appear in |
| 17 | supporting documentation, and that the names of Stichting Mathematisch |
| 18 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 19 | distribution of the software without specific, written prior permission. |
| 20 | |
| 21 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 22 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 23 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 24 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 25 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 26 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 27 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 28 | |
| 29 | ******************************************************************/ |
| 30 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 31 | /* Include file for users of select() */ |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 32 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 33 | /* NB caller must include <sys/types.h> */ |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 34 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 35 | #ifdef HAVE_SYS_SELECT_H |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 36 | |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 37 | #include <sys/select.h> |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 38 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 39 | #ifdef SYS_SELECT_WITH_SYS_TIME |
| 40 | #include "mytime.h" |
| 41 | #else /* !SYS_SELECT_WITH_SYS_TIME */ |
| 42 | #include <time.h> |
| 43 | #endif /* !SYS_SELECT_WITH_SYS_TIME */ |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 44 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 45 | #else /* !HAVE_SYS_SELECT_H */ |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 46 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 47 | #include "mytime.h" |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 48 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 49 | #endif /* !HAVE_SYS_SELECT_H */ |
| 50 | |
| 51 | /* If the fd manipulation macros aren't defined, |
| 52 | here is a set that should do the job */ |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 53 | |
| 54 | #ifndef FD_SETSIZE |
| 55 | #define FD_SETSIZE 256 |
| 56 | #endif |
| 57 | |
| 58 | #ifndef FD_SET |
| 59 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 60 | typedef long fd_mask; |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 61 | |
| 62 | #define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */ |
| 63 | #ifndef howmany |
| 64 | #define howmany(x, y) (((x)+((y)-1))/(y)) |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 65 | #endif /* howmany */ |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 66 | |
| 67 | typedef struct fd_set { |
| 68 | fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; |
| 69 | } fd_set; |
| 70 | |
| 71 | #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) |
| 72 | #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) |
| 73 | #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) |
Guido van Rossum | 4fbf798 | 1992-08-04 09:13:45 +0000 | [diff] [blame] | 74 | #define FD_ZERO(p) memset((char *)(p), '\0', sizeof(*(p))) |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 75 | |
| 76 | #endif /* FD_SET */ |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 77 | |
| 78 | #ifdef __cplusplus |
| 79 | } |
| 80 | #endif |
| 81 | #endif /* !Py_MYSELECT_H */ |