2006-08-08 16:33:33 +04:00
|
|
|
/*
|
2012-07-19 22:11:40 +04:00
|
|
|
* Copyright 2002-2012 Haiku, Inc. All Rights Reserved.
|
2006-08-08 16:33:33 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2002-08-28 23:53:43 +04:00
|
|
|
#ifndef _SYS_SELECT_H
|
|
|
|
#define _SYS_SELECT_H
|
2002-10-28 20:49:41 +03:00
|
|
|
|
2002-10-28 21:34:45 +03:00
|
|
|
|
2009-11-24 22:44:07 +03:00
|
|
|
#include <config/types.h>
|
|
|
|
|
2002-10-28 20:49:41 +03:00
|
|
|
#include <sys/time.h>
|
2002-10-28 21:34:45 +03:00
|
|
|
#include <signal.h>
|
2002-08-28 23:53:43 +04:00
|
|
|
|
2002-10-28 20:49:41 +03:00
|
|
|
|
|
|
|
/* If FD_SET is already defined, only the select() prototype is
|
|
|
|
* exported in this header.
|
2002-08-28 23:53:43 +04:00
|
|
|
*/
|
2002-10-28 20:49:41 +03:00
|
|
|
#ifndef FD_SET
|
2002-08-28 23:53:43 +04:00
|
|
|
|
2002-10-28 20:49:41 +03:00
|
|
|
/* You can define your own FDSETSIZE if you need more bits - but
|
|
|
|
* it should be enough for most uses.
|
|
|
|
*/
|
2002-08-28 23:53:43 +04:00
|
|
|
#ifndef FD_SETSIZE
|
2002-10-28 20:49:41 +03:00
|
|
|
# define FD_SETSIZE 1024
|
|
|
|
#endif
|
2002-08-28 23:53:43 +04:00
|
|
|
|
2009-11-24 22:44:07 +03:00
|
|
|
typedef __haiku_uint32 fd_mask;
|
2002-08-28 23:53:43 +04:00
|
|
|
|
2002-10-28 21:34:45 +03:00
|
|
|
#ifndef _howmany
|
|
|
|
# define _howmany(x, y) (((x) + ((y) - 1)) / (y))
|
2008-03-29 15:20:40 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef howmany
|
|
|
|
# define howmany(x, y) (((x) + ((y) - 1)) / (y))
|
2002-08-28 23:53:43 +04:00
|
|
|
#endif
|
|
|
|
|
2002-10-28 21:34:45 +03:00
|
|
|
#define NFDBITS (sizeof(fd_mask) * 8) /* bits per mask */
|
2002-08-28 23:53:43 +04:00
|
|
|
|
|
|
|
typedef struct fd_set {
|
2002-10-28 21:34:45 +03:00
|
|
|
fd_mask bits[_howmany(FD_SETSIZE, NFDBITS)];
|
2002-08-28 23:53:43 +04:00
|
|
|
} fd_set;
|
|
|
|
|
2002-10-28 20:49:41 +03:00
|
|
|
#define _FD_BITSINDEX(fd) ((fd) / NFDBITS)
|
|
|
|
#define _FD_BIT(fd) (1L << ((fd) % NFDBITS))
|
|
|
|
|
|
|
|
#define FD_ZERO(set) memset((set), 0, sizeof(fd_set))
|
|
|
|
#define FD_SET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] |= _FD_BIT(fd))
|
|
|
|
#define FD_CLR(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] &= ~_FD_BIT(fd))
|
|
|
|
#define FD_ISSET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] & _FD_BIT(fd))
|
2008-02-02 20:32:01 +03:00
|
|
|
#define FD_COPY(source, target) (*(target) = *(source))
|
2002-08-28 23:53:43 +04:00
|
|
|
|
2002-10-28 20:49:41 +03:00
|
|
|
#endif /* FD_SET */
|
2002-08-28 23:53:43 +04:00
|
|
|
|
2002-10-28 20:49:41 +03:00
|
|
|
#ifdef __cplusplus
|
2002-10-28 21:34:45 +03:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2002-10-30 05:28:09 +03:00
|
|
|
extern int pselect(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
|
|
|
|
struct fd_set *errorBits, const struct timespec *timeout, const sigset_t *sigMask);
|
2009-11-24 22:44:07 +03:00
|
|
|
extern int select(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
|
2002-10-30 05:28:09 +03:00
|
|
|
struct fd_set *errorBits, struct timeval *timeout);
|
2002-10-28 21:34:45 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2002-10-28 20:49:41 +03:00
|
|
|
#endif
|
2002-08-28 23:53:43 +04:00
|
|
|
|
2002-10-28 20:49:41 +03:00
|
|
|
#endif /* _SYS_SELECT_H */
|