}
wd, errno := syscall.InotifyAddWatch(w.poller.fd, name, flags)
if wd == -1 {
- return os.NewSyscallError("inotify_add_watch", errno)
+ return errno
}
w.mu.Lock()
}
success, errno := syscall.InotifyRmWatch(w.poller.fd, watch.wd)
if success == -1 {
- return os.NewSyscallError("inotify_rm_watch", errno)
+ return errno
}
delete(w.watches, name)
return nil
if n < 0 {
select {
- case w.Errors <- os.NewSyscallError("read", errno):
+ case w.Errors <- errno:
case <-w.done:
return
}
import (
"errors"
- "os"
"syscall"
)
// Create inotify fd
poller.fd, errno = syscall.InotifyInit()
if poller.fd == -1 {
- return nil, os.NewSyscallError("inotify_init", errno)
+ return nil, errno
}
// Create epoll fd
poller.epfd, errno = syscall.EpollCreate(1)
if poller.epfd == -1 {
syscall.Close(poller.fd)
- return nil, os.NewSyscallError("epoll_create", errno)
+ return nil, errno
}
// Create pipe; pipe[0] is the read end, pipe[1] the write end.
errno = syscall.Pipe(poller.pipe[:])
if errno != nil {
syscall.Close(poller.fd)
syscall.Close(poller.epfd)
- return nil, os.NewSyscallError("pipe", errno)
+ return nil, errno
}
// Register inotify fd with epoll
syscall.Close(poller.epfd)
syscall.Close(poller.pipe[0])
syscall.Close(poller.pipe[1])
- return nil, os.NewSyscallError("epoll_ctl", errno)
+ return nil, errno
}
// Register pipe fd with epoll
syscall.Close(poller.epfd)
syscall.Close(poller.pipe[0])
syscall.Close(poller.pipe[1])
- return nil, os.NewSyscallError("epoll_ctl", errno)
+ return nil, errno
}
return poller, nil
if errno == syscall.EINTR {
continue
}
- return false, os.NewSyscallError("epoll_wait", errno)
+ return false, errno
}
if n == 0 {
// If there are no events, try again.
buf := make([]byte, 1)
n, errno := syscall.Write(poller.pipe[1], buf)
if n == -1 {
- return os.NewSyscallError("write", errno)
+ return errno
}
return nil
}
buf := make([]byte, 100)
n, errno := syscall.Read(poller.pipe[0], buf)
if n == -1 {
- return os.NewSyscallError("read", errno)
+ return errno
}
return nil
}