-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsys_select.sh
More file actions
46 lines (40 loc) · 957 Bytes
/
sys_select.sh
File metadata and controls
46 lines (40 loc) · 957 Bytes
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
36
37
38
39
40
41
42
43
44
45
46
declare -ri FD_SETSIZE=1024
declare -a fd_set
{
for ((_n = 0; _n < FD_SETSIZE / 8; _n++)); do
fd_set[_n]="uint8:0"
done
}
declare -ri SIZEOF_FD_SET=$((FD_SETSIZE/8))
function FD_CLR() {
local -n fdset=$1
local -i index=${2##*:}
local -i oval=${fdset[index / 8]##*:}
fdset[index / 8]=uint8:$((oval & ~(1 << (index % 8))))
}
function FD_SET() {
local -n fdset=$1
local -i index=${2##*:}
local -i oval=${fdset[index / 8]##*:}
fdset[index / 8]=uint8:$((oval | (1 << (index % 8))))
}
function FD_ISSET() {
local -n fdset=$1
local -i index=${2##*:}
local -i oval=${fdset[index / 8]##*:}
if ((oval & (1 << (index % 8)))); then
return 0
fi
return 1
}
function FD_ZERO() {
local -n fdset=$1
local n
for ((n = 0; n < FD_SETSIZE / 8; n++)); do
fdset[n]="uint8:0"
done
}
function so_select() {
dlcall -r int select $2 $3 $4 $5 $6
eval $1=\$DLRETVAL
}