func (p poller) Add(fd int, flags Flags) error { var ev C.struct_epoll_event if flags&In != 0 { ev.events |= C.EPOLLIN } if flags&Out != 0 { ev.events |= C.EPOLLOUT } if flags&OneShot != 0 { ev.events |= C.EPOLLONESHOT } var dataFd = (*C.int)(unsafe.Pointer(&ev.data)) *dataFd = C.int(fd) ok, err := C.epoll_ctl(C.int(p), C.EPOLL_CTL_ADD, C.int(fd), &ev) if ok < 0 && err != nil { if err == syscall.EEXIST { // Try MOD ok, err = C.epoll_ctl(C.int(p), C.EPOLL_CTL_MOD, C.int(fd), &ev) } } if ok >= 0 { err = nil } return err }
func (p poller) Delete(fd int) error { var ev C.struct_epoll_event // event must be non-NULL in kernels < 2.6.9 ok, err := C.epoll_ctl(C.int(p), C.EPOLL_CTL_DEL, C.int(fd), &ev) if ok < 0 { return err } return nil }