Mercurial > projects > ldc
comparison druntime/import/stdc/posix/sys/select.d @ 760:6f33b427bfd1
Seems like hg ignores .di files, so I missed a bunch of stuff. complete druntime should be there now :)
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Wed, 12 Nov 2008 00:19:18 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
759:d3eb054172f9 | 760:6f33b427bfd1 |
---|---|
1 /** | |
2 * D header file for POSIX. | |
3 * | |
4 * Copyright: Public Domain | |
5 * License: Public Domain | |
6 * Authors: Sean Kelly | |
7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition | |
8 */ | |
9 module stdc.posix.sys.select; | |
10 | |
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 | |
16 | |
17 extern (C): | |
18 | |
19 // | |
20 // Required | |
21 // | |
22 /* | |
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. | |
27 | |
28 fd_set | |
29 | |
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); | |
34 | |
35 FD_SETSIZE | |
36 | |
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*); | |
39 */ | |
40 | |
41 version( linux ) | |
42 { | |
43 private | |
44 { | |
45 alias c_long __fd_mask; | |
46 const __NFDBITS = 8 * __fd_mask.sizeof; | |
47 | |
48 extern (D) int __FDELT( int d ) | |
49 { | |
50 return d / __NFDBITS; | |
51 } | |
52 | |
53 extern (D) int __FDMASK( int d ) | |
54 { | |
55 return cast(__fd_mask) 1 << ( d % __NFDBITS ); | |
56 } | |
57 } | |
58 | |
59 const FD_SETSIZE = 1024; | |
60 | |
61 struct fd_set | |
62 { | |
63 __fd_mask[FD_SETSIZE / __NFDBITS] fds_bits; | |
64 } | |
65 | |
66 extern (D) void FD_CLR( int fd, fd_set* fdset ) | |
67 { | |
68 fdset.fds_bits[__FDELT( fd )] &= ~__FDMASK( fd ); | |
69 } | |
70 | |
71 extern (D) int FD_ISSET( int fd, fd_set* fdset ) | |
72 { | |
73 return fdset.fds_bits[__FDELT( fd )] & __FDMASK( fd ); | |
74 } | |
75 | |
76 extern (D) void FD_SET( int fd, fd_set* fdset ) | |
77 { | |
78 fdset.fds_bits[__FDELT( fd )] |= __FDMASK( fd ); | |
79 } | |
80 | |
81 extern (D) void FD_ZERO( fd_set* fdset ) | |
82 { | |
83 fdset.fds_bits[0 .. $] = 0; | |
84 } | |
85 | |
86 /+ | |
87 + GNU ASM Implementation | |
88 + | |
89 # define __FD_ZERO(fdsp) \ | |
90 do { \ | |
91 int __d0, __d1; \ | |
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]) \ | |
97 : "memory"); \ | |
98 } while (0) | |
99 | |
100 # define __FD_SET(fd, fdsp) \ | |
101 __asm__ __volatile__ ("btsl %1,%0" \ | |
102 : "=m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \ | |
103 : "r" (((int) (fd)) % __NFDBITS) \ | |
104 : "cc","memory") | |
105 # define __FD_CLR(fd, fdsp) \ | |
106 __asm__ __volatile__ ("btrl %1,%0" \ | |
107 : "=m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \ | |
108 : "r" (((int) (fd)) % __NFDBITS) \ | |
109 : "cc","memory") | |
110 # define __FD_ISSET(fd, fdsp) \ | |
111 (__extension__ \ | |
112 ({register char __result; \ | |
113 __asm__ __volatile__ ("btl %1,%2 ; setcb %b0" \ | |
114 : "=q" (__result) \ | |
115 : "r" (((int) (fd)) % __NFDBITS), \ | |
116 "m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \ | |
117 : "cc"); \ | |
118 __result; })) | |
119 +/ | |
120 | |
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*); | |
123 } | |
124 else version( darwin ) | |
125 { | |
126 private | |
127 { | |
128 const uint __DARWIN_NBBY = 8; /* bits in a byte */ | |
129 const uint __DARWIN_NFDBITS = (int.sizeof * __DARWIN_NBBY); /* bits per mask */ | |
130 } | |
131 | |
132 const FD_SETSIZE = 1024; | |
133 | |
134 struct fd_set | |
135 { | |
136 int fds_bits[(((FD_SETSIZE) + ((__DARWIN_NFDBITS) - 1)) / (__DARWIN_NFDBITS))]; | |
137 } | |
138 } | |
139 else version( freebsd ) | |
140 { | |
141 private | |
142 { | |
143 const uint FD_SETSIZE = 1024; | |
144 const uint _NFDBITS = c_ulong.sizeof * 8; | |
145 } | |
146 struct fd_set | |
147 { | |
148 c_ulong fds_bits[((FD_SETSIZE + (_NFDBITS - 1)) / _NFDBITS)]; | |
149 } | |
150 } |