-
Notifications
You must be signed in to change notification settings - Fork 4
/
select_h.lua
35 lines (29 loc) · 1.24 KB
/
select_h.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
local ffi = require("ffi")
pcall(ffi.cdef, "typedef long int __fd_mask;")
pcall(ffi.cdef, [[
typedef struct {
__fd_mask __fds_bits[32];
} fd_set;
]])
pcall(ffi.cdef, "int select(int, fd_set *restrict, fd_set *restrict, fd_set *restrict, struct timeval *restrict);")
pcall(ffi.cdef, "static const int POLLRDNORM = 64;")
pcall(ffi.cdef, "static const int POLLRDBAND = 128;")
--[[
#define __NFDBITS (8 * (int) sizeof (__fd_mask))
#define>__FD_ELT(d) ((d) / __NFDBITS)
#define>__FD_MASK(d) ((__fd_mask) (1UL << ((d) % __NFDBITS)))
#define __FDS_BITS(set) ((set)->__fds_bits)
#define __FD_ZERO(s) \
do { \
unsigned int __i; \
fd_set *__arr = (s); \
for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask); ++__i) \
__FDS_BITS (__arr)[__i] = 0; \
} while (0)
#define __FD_SET(d, s) \
((void) (__FDS_BITS (s)[__FD_ELT(d)] |= __FD_MASK(d)))
#define __FD_CLR(d, s) \
((void) (__FDS_BITS (s)[__FD_ELT(d)] &= ~__FD_MASK(d)))
#define __FD_ISSET(d, s) \
((__FDS_BITS (s)[__FD_ELT (d)] & __FD_MASK (d)) != 0)
--]]