forked from DiceDB/dice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes_linux.go
59 lines (48 loc) · 1.16 KB
/
types_linux.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
package iomultiplexer
import (
"syscall"
"time"
)
// newTime converts the given time.Duration to Linux's ms in int
func newTime(t time.Duration) int {
if t < 0 {
return -1
}
return int(t / time.Millisecond)
}
// toNative converts the given generic Event to Linux's EpollEvent struct
func (e Event) toNative() syscall.EpollEvent {
return syscall.EpollEvent{
Fd: int32(e.Fd),
Events: e.Op.toNative(),
}
}
// newEvent converts the given Linux's EpollEvent struct to the generic Event type
func newEvent(ePEvent syscall.EpollEvent) Event {
return Event{
Fd: int(ePEvent.Fd),
Op: newOperations(ePEvent.Events),
}
}
// toNative converts the given generic Operations to Linux's EpollEvent type
func (op Operations) toNative() uint32 {
native := uint32(0)
if op&OpRead != 0 {
native |= syscall.EPOLLIN
}
if op&OpWrite != 0 {
native |= syscall.EPOLLOUT
}
return native
}
// newOperations converts the given Linux's EpollEvent type to the generic Operations type
func newOperations(events uint32) Operations {
op := Operations(0)
if events&syscall.EPOLLIN != 0 {
op |= OpRead
}
if events&syscall.EPOLLOUT != 0 {
op |= OpWrite
}
return op
}