2 * D header file for POSIX.
4 * Copyright: Public Domain
5 * License: Public Domain
7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
9 module stdc.posix.sys.select;
11 private import stdc.posix.config;
12 public import stdc.time; // for timespec
13 public import stdc.posix.sys.time; // for timeval
14 public import stdc.posix.sys.types; // for time_t
15 public import stdc.posix.signal; // for sigset_t
23 NOTE: This module requires timeval from stdc.posix.sys.time, but timeval
24 is supposedly an XOpen extension. As a result, this header will not
25 compile on platforms that are not XSI-compliant. This must be resolved
26 on a per-platform basis.
30 void FD_CLR(int fd, fd_set* fdset);
31 int FD_ISSET(int fd, fd_set* fdset);
32 void FD_SET(int fd, fd_set* fdset);
33 void FD_ZERO(fd_set* fdset);
37 int pselect(int, fd_set*, fd_set*, fd_set*, in timespec*, in sigset_t*);
38 int select(int, fd_set*, fd_set*, fd_set*, timeval*);
45 alias c_long __fd_mask;
46 const __NFDBITS = 8 * __fd_mask.sizeof;
48 extern (D) int __FDELT( int d )
53 extern (D) int __FDMASK( int d )
55 return cast(__fd_mask) 1 << ( d % __NFDBITS );
59 const FD_SETSIZE = 1024;
63 __fd_mask[FD_SETSIZE / __NFDBITS] fds_bits;
66 extern (D) void FD_CLR( int fd, fd_set* fdset )
68 fdset.fds_bits[__FDELT( fd )] &= ~__FDMASK( fd );
71 extern (D) int FD_ISSET( int fd, fd_set* fdset )
73 return fdset.fds_bits[__FDELT( fd )] & __FDMASK( fd );
76 extern (D) void FD_SET( int fd, fd_set* fdset )
78 fdset.fds_bits[__FDELT( fd )] |= __FDMASK( fd );
81 extern (D) void FD_ZERO( fd_set* fdset )
83 fdset.fds_bits[0 .. $] = 0;
87 + GNU ASM Implementation
89 # define __FD_ZERO(fdsp) \
92 __asm__ __volatile__ ("cld; rep; stosl" \
93 : "=c" (__d0), "=D" (__d1) \
94 : "a" (0), "0" (sizeof (fd_set) \
95 / sizeof (__fd_mask)), \
96 "1" (&__FDS_BITS (fdsp)[0]) \
100 # define __FD_SET(fd, fdsp) \
101 __asm__ __volatile__ ("btsl %1,%0" \
102 : "=m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \
103 : "r" (((int) (fd)) % __NFDBITS) \
105 # define __FD_CLR(fd, fdsp) \
106 __asm__ __volatile__ ("btrl %1,%0" \
107 : "=m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \
108 : "r" (((int) (fd)) % __NFDBITS) \
110 # define __FD_ISSET(fd, fdsp) \
112 ({register char __result; \
113 __asm__ __volatile__ ("btl %1,%2 ; setcb %b0" \
115 : "r" (((int) (fd)) % __NFDBITS), \
116 "m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \
121 int pselect(int, fd_set*, fd_set*, fd_set*, in timespec*, in sigset_t*);
122 int select(int, fd_set*, fd_set*, fd_set*, timeval*);
124 else version( darwin )
128 const uint __DARWIN_NBBY = 8; /* bits in a byte */
129 const uint __DARWIN_NFDBITS = (int.sizeof * __DARWIN_NBBY); /* bits per mask */
132 const FD_SETSIZE = 1024;
136 int fds_bits[(((FD_SETSIZE) + ((__DARWIN_NFDBITS) - 1)) / (__DARWIN_NFDBITS))];
139 else version( freebsd )
143 const uint FD_SETSIZE = 1024;
144 const uint _NFDBITS = c_ulong.sizeof * 8;
148 c_ulong fds_bits[((FD_SETSIZE + (_NFDBITS - 1)) / _NFDBITS)];