-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpoller.go
134 lines (113 loc) · 2.81 KB
/
poller.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// ©Hayabusa Cloud Co., Ltd. 2022. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package sox
import (
"io"
"os"
"time"
)
const (
pollerDefaultEventsNum = 1 << 10
)
const (
pollerEventIn = 0x1
pollerEventOut = 0x4
pollerEventHup = 0x10
)
type pollerEvent struct {
Events uint32
Fd int32
pad [4]byte
}
type poller interface {
add(fd int, events uint32) error
del(fd int) error
wait(d time.Duration) (events []pollerEvent, err error)
Close() error
}
// PollFd is the interface that warps Fd
type PollFd interface {
// Fd returns the file descriptor
Fd() int
}
// PollReader is the interface that groups Fd and the basic Read method
type PollReader interface {
PollFd
io.Reader
}
// PollUintReader is the interface that groups ReadUint()
// and the methods in interface PollReader
type PollUintReader interface {
PollReader
ReadUint() (val uint, err error)
}
// PollWriter is the interface that groups Fd and the basic Write method
type PollWriter interface {
PollFd
io.Writer
}
// PollUintWriter is the interface that groups WriteUint()
// and the methods in interface PollWriter
type PollUintWriter interface {
PollWriter
WriteUint(val uint) error
}
// PollReadWriter is the interface that groups the methods
// in interface PollReader and PollWriter
type PollReadWriter interface {
PollReader
PollWriter
}
// PollUintReadWriter is the interface that groups the methods
// in interface PollUintReader and PollUintWriter
type PollUintReadWriter interface {
PollUintReader
PollUintWriter
}
// PollCloser is the interface that groups Fd and the basic Close method
type PollCloser interface {
PollFd
io.Closer
}
// PollReadCloser is the interface that groups the methods
// in interface PollReader and PollCloser
type PollReadCloser interface {
PollReader
io.Closer
}
// PollWriteCloser is the interface that groups the methods
// in interface PollWriter and PollCloser
type PollWriteCloser interface {
PollWriter
io.Closer
}
// PollReadWriteCloser is the interface that groups the methods
// in interface PollReader, PollWriter and PollCloser
type PollReadWriteCloser interface {
PollReader
PollWriter
io.Closer
}
// PollUintReadCloser is the interface that groups the methods
// in interface PollUintReader and PollUintCloser
type PollUintReadCloser interface {
PollUintReader
io.Closer
}
// PollUintWriteCloser is the interface that groups the methods
// in interface PollUintWriter and PollCloser
type PollUintWriteCloser interface {
PollUintWriter
io.Closer
}
// PollUintReadWriteCloser is the interface that groups the methods
// in interface PollUintReader, PollUintWriter and PollCloser
type PollUintReadWriteCloser interface {
PollUintReader
PollUintWriter
io.Closer
}
type file interface {
File() (f *os.File, err error)
}