]> go.fuhry.dev Git - fsnotify.git/commitdiff
Generate inotify fd in NewWatcher, pass fd into newFdPoller
authorPieter Droogendijk <pieter@binky.org.uk>
Sat, 7 Feb 2015 21:18:46 +0000 (22:18 +0100)
committerNathan Youngman <git@nathany.com>
Sun, 8 Feb 2015 20:22:30 +0000 (13:22 -0700)
inotify.go
inotify_poller.go

index d33b96adabfe52f9060972d132ed368ff05fb44a..e02bf12b8bf1f2dfdeffdb584c3e6ae454c30941 100644 (file)
@@ -32,7 +32,13 @@ type Watcher struct {
 
 // NewWatcher establishes a new watcher with the underlying OS and begins waiting for events.
 func NewWatcher() (*Watcher, error) {
-       poller, err := newFdPoller()
+       // Create inotify fd
+       fd, errno := syscall.InotifyInit()
+       if fd == -1 {
+               return nil, errno
+       }
+       // Create epoll
+       poller, err := newFdPoller(fd)
        if err != nil {
                return nil, err
        }
index fbd664e0b02c42a1f97494fd8c5cd6d561e35e0e..726818c56e09bb899e5129a62e9868aa6e1a2c2b 100644 (file)
@@ -19,15 +19,11 @@ type fdPoller struct {
 
 // Create a new inotify poller.
 // This creates an inotify handler, and an epoll handler.
-func newFdPoller() (*fdPoller, error) {
+func newFdPoller(fd int) (*fdPoller, error) {
        var errno error
        poller := new(fdPoller)
+       poller.fd = fd
 
-       // Create inotify fd
-       poller.fd, errno = syscall.InotifyInit()
-       if poller.fd == -1 {
-               return nil, errno
-       }
        // Create epoll fd
        poller.epfd, errno = syscall.EpollCreate(1)
        if poller.epfd == -1 {