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 | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 8 | Copyright (c) 2000, BeOpen.com. |
| 9 | Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
| 10 | Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
| 11 | All rights reserved. |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 12 | |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 13 | See the file "Misc/COPYRIGHT" for information on usage and |
| 14 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 15 | ******************************************************************/ |
| 16 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 17 | /* Include file for users of select() */ |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 18 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 19 | /* NB caller must include <sys/types.h> */ |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 20 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 21 | #ifdef HAVE_SYS_SELECT_H |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 22 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 23 | #ifdef SYS_SELECT_WITH_SYS_TIME |
| 24 | #include "mytime.h" |
| 25 | #else /* !SYS_SELECT_WITH_SYS_TIME */ |
| 26 | #include <time.h> |
| 27 | #endif /* !SYS_SELECT_WITH_SYS_TIME */ |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 28 | |
Guido van Rossum | 03dc538 | 1998-09-28 22:05:22 +0000 | [diff] [blame] | 29 | #include <sys/select.h> |
| 30 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 31 | #else /* !HAVE_SYS_SELECT_H */ |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 32 | |
Guido van Rossum | ddc3b63 | 2000-04-24 15:12:54 +0000 | [diff] [blame] | 33 | #ifdef USE_GUSI1 |
Jack Jansen | e708f40 | 1996-02-14 16:04:39 +0000 | [diff] [blame] | 34 | /* If we don't have sys/select the definition may be in unistd.h */ |
| 35 | #include <GUSI.h> |
| 36 | #endif |
| 37 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 38 | #include "mytime.h" |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 39 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 40 | #endif /* !HAVE_SYS_SELECT_H */ |
| 41 | |
| 42 | /* If the fd manipulation macros aren't defined, |
| 43 | here is a set that should do the job */ |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 44 | |
| 45 | #ifndef FD_SETSIZE |
| 46 | #define FD_SETSIZE 256 |
| 47 | #endif |
| 48 | |
| 49 | #ifndef FD_SET |
| 50 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 51 | typedef long fd_mask; |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 52 | |
| 53 | #define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */ |
| 54 | #ifndef howmany |
| 55 | #define howmany(x, y) (((x)+((y)-1))/(y)) |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 56 | #endif /* howmany */ |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 57 | |
| 58 | typedef struct fd_set { |
| 59 | fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; |
| 60 | } fd_set; |
| 61 | |
| 62 | #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) |
| 63 | #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) |
| 64 | #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] | 65 | #define FD_ZERO(p) memset((char *)(p), '\0', sizeof(*(p))) |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 66 | |
| 67 | #endif /* FD_SET */ |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 68 | |
| 69 | #ifdef __cplusplus |
| 70 | } |
| 71 | #endif |
| 72 | #endif /* !Py_MYSELECT_H */ |