blob: 8e8f81f0e3ce6ff0a7c3dbb7151aac0d31b4ea28 [file] [log] [blame]
Guido van Rossuma3309961993-07-28 09:05:47 +00001#ifndef Py_MYSELECT_H
2#define Py_MYSELECT_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
Guido van Rossumed233a51992-06-23 09:07:03 +00007/***********************************************************
Guido van Rossum5799b521995-01-04 19:06:22 +00008Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
9The Netherlands.
Guido van Rossumed233a51992-06-23 09:07:03 +000010
11 All Rights Reserved
12
Guido van Rossumfd71b9e2000-06-30 23:50:40 +000013Copyright (c) 2000, BeOpen.com.
14Copyright (c) 1995-2000, Corporation for National Research Initiatives.
15Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
16All rights reserved.
Guido van Rossumed233a51992-06-23 09:07:03 +000017
Guido van Rossumfd71b9e2000-06-30 23:50:40 +000018See the file "Misc/COPYRIGHT" for information on usage and
19redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossumed233a51992-06-23 09:07:03 +000020
21******************************************************************/
22
Guido van Rossumb6775db1994-08-01 11:34:53 +000023/* Include file for users of select() */
Guido van Rossumed233a51992-06-23 09:07:03 +000024
Guido van Rossumb6775db1994-08-01 11:34:53 +000025/* NB caller must include <sys/types.h> */
Guido van Rossumed233a51992-06-23 09:07:03 +000026
Guido van Rossumb6775db1994-08-01 11:34:53 +000027#ifdef HAVE_SYS_SELECT_H
Guido van Rossumed233a51992-06-23 09:07:03 +000028
Guido van Rossumb6775db1994-08-01 11:34:53 +000029#ifdef SYS_SELECT_WITH_SYS_TIME
30#include "mytime.h"
31#else /* !SYS_SELECT_WITH_SYS_TIME */
32#include <time.h>
33#endif /* !SYS_SELECT_WITH_SYS_TIME */
Guido van Rossumed233a51992-06-23 09:07:03 +000034
Guido van Rossum03dc5381998-09-28 22:05:22 +000035#include <sys/select.h>
36
Guido van Rossumb6775db1994-08-01 11:34:53 +000037#else /* !HAVE_SYS_SELECT_H */
Guido van Rossumed233a51992-06-23 09:07:03 +000038
Guido van Rossumddc3b632000-04-24 15:12:54 +000039#ifdef USE_GUSI1
Jack Jansene708f401996-02-14 16:04:39 +000040/* If we don't have sys/select the definition may be in unistd.h */
41#include <GUSI.h>
42#endif
43
Guido van Rossumb6775db1994-08-01 11:34:53 +000044#include "mytime.h"
Guido van Rossumed233a51992-06-23 09:07:03 +000045
Guido van Rossumb6775db1994-08-01 11:34:53 +000046#endif /* !HAVE_SYS_SELECT_H */
47
48/* If the fd manipulation macros aren't defined,
49 here is a set that should do the job */
Guido van Rossumed233a51992-06-23 09:07:03 +000050
51#ifndef FD_SETSIZE
52#define FD_SETSIZE 256
53#endif
54
55#ifndef FD_SET
56
Guido van Rossumb6775db1994-08-01 11:34:53 +000057typedef long fd_mask;
Guido van Rossumed233a51992-06-23 09:07:03 +000058
59#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
60#ifndef howmany
61#define howmany(x, y) (((x)+((y)-1))/(y))
Guido van Rossumb6775db1994-08-01 11:34:53 +000062#endif /* howmany */
Guido van Rossumed233a51992-06-23 09:07:03 +000063
64typedef struct fd_set {
65 fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
66} fd_set;
67
68#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
69#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
70#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
Guido van Rossum4fbf7981992-08-04 09:13:45 +000071#define FD_ZERO(p) memset((char *)(p), '\0', sizeof(*(p)))
Guido van Rossumed233a51992-06-23 09:07:03 +000072
73#endif /* FD_SET */
Guido van Rossuma3309961993-07-28 09:05:47 +000074
75#ifdef __cplusplus
76}
77#endif
78#endif /* !Py_MYSELECT_H */