forked from pkg/poller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepoll_linux_error.go
82 lines (66 loc) · 1.31 KB
/
epoll_linux_error.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
package poller
import (
"fmt"
"strings"
"syscall"
)
const (
EPOLLERR = uint32(syscall.EPOLLERR)
EPOLLHUP = uint32(syscall.EPOLLHUP)
EPOLLIN = uint32(syscall.EPOLLIN)
EPOLLOUT = uint32(syscall.EPOLLOUT)
EPOLLONESHOT = uint32(syscall.EPOLLONESHOT)
)
func EventNames(revents uint32) string {
var s []string
if revents == 0 {
return ""
}
if revents&EPOLLERR != 0 {
revents &= ^EPOLLERR
s = append(s, "EPOLLERR")
}
if revents&EPOLLHUP != 0 {
revents &= ^EPOLLHUP
s = append(s, "EPOLLHUP")
}
if revents&EPOLLIN != 0 {
revents &= ^EPOLLIN
s = append(s, "EPOLLIN")
}
if revents&EPOLLOUT != 0 {
revents &= ^EPOLLOUT
s = append(s, "EPOLLOUT")
}
if revents&EPOLLONESHOT != 0 {
revents &= ^EPOLLONESHOT
s = append(s, "EPOLLONESHOT")
}
if revents != 0 {
s = append(s, fmt.Sprintf("0x%x", revents))
}
return strings.Join(s, "|")
}
type EventError struct {
fd uintptr
revents uint32
}
func NewEventError(fd uintptr, revents uint32) EventError {
e := EventError{
fd: fd,
revents: revents,
}
return e
}
func (e EventError) Error() string {
return fmt.Sprintf("epoll: Unexpected event %s (0x%x) on fd:%d",
EventNames(e.revents),
e.revents,
e.fd)
}
func (e EventError) Fd() uintptr {
return e.fd
}
func (e EventError) Events() uint32 {
return e.revents
}