-
Notifications
You must be signed in to change notification settings - Fork 3
/
epoll_poller.go
37 lines (29 loc) · 1.15 KB
/
epoll_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
package evnet
import (
"os"
"golang.org/x/sys/unix"
)
type Poller struct {
Fd int
}
const (
readEvents = unix.EPOLLPRI | unix.EPOLLIN
writeEvents = unix.EPOLLOUT
readWriteEvents = readEvents | writeEvents
ErrEvents = unix.EPOLLERR | unix.EPOLLHUP | unix.EPOLLRDHUP
// OutEvents combines EPOLLOUT event and some exceptional events.
OutEvents = ErrEvents | unix.EPOLLOUT
// InEvents combines EPOLLIN/EPOLLPRI events and some exceptional events.
InEvents = ErrEvents | unix.EPOLLIN | unix.EPOLLPRI
)
// Delete removes the given file-descriptor from the poller.
func (p *Poller) Delete(fd int) error {
return os.NewSyscallError("epoll_ctl del", unix.EpollCtl(p.Fd, unix.EPOLL_CTL_DEL, fd, nil))
}
func (p *Poller) ModReadWrite(fd int) error {
return os.NewSyscallError("EPOLL_MOD", unix.EpollCtl(p.Fd, unix.EPOLL_CTL_MOD, fd, &unix.EpollEvent{Fd: int32(fd), Events: readWriteEvents}))
}
// ModRead renews the given file-descriptor with readable event in the poller.
func (p *Poller) ModRead(fd int) error {
return os.NewSyscallError("EPOLL_MOD", unix.EpollCtl(p.Fd, unix.EPOLL_CTL_MOD, fd, &unix.EpollEvent{Fd: int32(fd), Events: readEvents}))
}