From: Nathan Youngman Date: Fri, 13 Jun 2014 03:43:49 +0000 (-0600) Subject: Pluralized channel names: Events and Errors. X-Git-Tag: v1.7.2~312^2~6 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=d2a3e00e0f2522bf41338ab4d001ae2c2760336e;p=fsnotify.git Pluralized channel names: Events and Errors. --- diff --git a/example_test.go b/example_test.go index e8a3b07..21a0f9a 100644 --- a/example_test.go +++ b/example_test.go @@ -19,9 +19,9 @@ func ExampleNewWatcher() { go func() { for { select { - case ev := <-watcher.Event: + case ev := <-watcher.Events: log.Println("event:", ev) - case err := <-watcher.Error: + case err := <-watcher.Errors: log.Println("error:", err) } } diff --git a/fsnotify_bsd.go b/fsnotify_bsd.go index 05fda24..b04c253 100644 --- a/fsnotify_bsd.go +++ b/fsnotify_bsd.go @@ -72,8 +72,8 @@ type Watcher struct { femut sync.Mutex // Protects access to fileExists. externalWatches map[string]bool // Map of watches added by user of the library. ewmut sync.Mutex // Protects access to externalWatches. - Error chan error // Errors are sent on this channel - Event chan *FileEvent // Events are returned on this channel + Errors chan error // Errors are sent on this channel + Events chan *FileEvent // Events are returned on this channel done chan bool // Channel for sending a "quit message" to the reader goroutine isClosed bool // Set to true when Close() is first called } @@ -92,8 +92,8 @@ func NewWatcher() (*Watcher, error) { finfo: make(map[int]os.FileInfo), fileExists: make(map[string]bool), externalWatches: make(map[string]bool), - Event: make(chan *FileEvent), - Error: make(chan error), + Events: make(chan *FileEvent), + Errors: make(chan error), done: make(chan bool, 1), } @@ -286,7 +286,7 @@ func (w *Watcher) removeWatch(path string) error { } // readEvents reads from the kqueue file descriptor, converts the -// received events into Event objects and sends them via the Event channel +// received events into Event objects and sends them via the Events channel func (w *Watcher) readEvents() { var ( eventbuf [10]syscall.Kevent_t // Event buffer @@ -311,10 +311,10 @@ func (w *Watcher) readEvents() { if done { errno := syscall.Close(w.kq) if errno != nil { - w.Error <- os.NewSyscallError("close", errno) + w.Errors <- os.NewSyscallError("close", errno) } - close(w.Event) - close(w.Error) + close(w.Events) + close(w.Errors) return } @@ -325,7 +325,7 @@ func (w *Watcher) readEvents() { // EINTR is okay, basically the syscall was interrupted before // timeout expired. if errno != nil && errno != syscall.EINTR { - w.Error <- os.NewSyscallError("kevent", errno) + w.Errors <- os.NewSyscallError("kevent", errno) continue } @@ -359,7 +359,7 @@ func (w *Watcher) readEvents() { w.sendDirectoryChangeEvents(fileEvent.Name) } else { // Send the event on the events channel - w.Event <- fileEvent + w.Events <- fileEvent } // Move to next event @@ -448,7 +448,7 @@ func (w *Watcher) sendDirectoryChangeEvents(dirPath string) { // Get all files files, err := ioutil.ReadDir(dirPath) if err != nil { - w.Error <- err + w.Errors <- err } // Search for new files @@ -462,7 +462,7 @@ func (w *Watcher) sendDirectoryChangeEvents(dirPath string) { fileEvent := new(FileEvent) fileEvent.Name = filePath fileEvent.create = true - w.Event <- fileEvent + w.Events <- fileEvent } w.femut.Lock() w.fileExists[filePath] = true diff --git a/fsnotify_linux.go b/fsnotify_linux.go index a899e1e..1d9319a 100644 --- a/fsnotify_linux.go +++ b/fsnotify_linux.go @@ -97,8 +97,8 @@ type Watcher struct { fd int // File descriptor (as returned by the inotify_init() syscall) watches map[string]*watch // Map of inotify watches (key: path) paths map[int]string // Map of watched paths (key: watch descriptor) - Error chan error // Errors are sent on this channel - Event chan *FileEvent // Events are returned on this channel + Errors chan error // Errors are sent on this channel + Events chan *FileEvent // Events are returned on this channel done chan bool // Channel for sending a "quit message" to the reader goroutine isClosed bool // Set to true when Close() is first called } @@ -113,8 +113,8 @@ func NewWatcher() (*Watcher, error) { fd: fd, watches: make(map[string]*watch), paths: make(map[int]string), - Event: make(chan *FileEvent), - Error: make(chan error), + Events: make(chan *FileEvent), + Errors: make(chan error), done: make(chan bool, 1), } @@ -191,7 +191,7 @@ func (w *Watcher) removeWatch(path string) error { } // readEvents reads from the inotify file descriptor, converts the -// received events into Event objects and sends them via the Event channel +// received events into Event objects and sends them via the Events channel func (w *Watcher) readEvents() { var ( buf [syscall.SizeofInotifyEvent * 4096]byte // Buffer for a maximum of 4096 raw events @@ -204,8 +204,8 @@ func (w *Watcher) readEvents() { select { case <-w.done: syscall.Close(w.fd) - close(w.Event) - close(w.Error) + close(w.Events) + close(w.Errors) return default: } @@ -215,17 +215,17 @@ func (w *Watcher) readEvents() { // If EOF is received if n == 0 { syscall.Close(w.fd) - close(w.Event) - close(w.Error) + close(w.Events) + close(w.Errors) return } if n < 0 { - w.Error <- os.NewSyscallError("read", errno) + w.Errors <- os.NewSyscallError("read", errno) continue } if n < syscall.SizeofInotifyEvent { - w.Error <- errors.New("inotify: short read in readEvents()") + w.Errors <- errors.New("inotify: short read in readEvents()") continue } @@ -255,7 +255,7 @@ func (w *Watcher) readEvents() { // Send the events that are not ignored on the events channel if !event.ignoreLinux() { - w.Event <- event + w.Events <- event } // Move to the next event in the buffer @@ -264,7 +264,7 @@ func (w *Watcher) readEvents() { } } -// Certain types of events can be "ignored" and not sent over the Event +// Certain types of events can be "ignored" and not sent over the Events // channel. Such as events marked ignore by the kernel, or MODIFY events // against files that do not exist. func (e *FileEvent) ignoreLinux() bool { diff --git a/fsnotify_symlink_test.go b/fsnotify_symlink_test.go index 39061f8..21253f9 100644 --- a/fsnotify_symlink_test.go +++ b/fsnotify_symlink_test.go @@ -23,7 +23,7 @@ func TestFsnotifyFakeSymlink(t *testing.T) { var errorsReceived counter // Receive errors on the error channel on a separate goroutine go func() { - for errors := range watcher.Error { + for errors := range watcher.Errors { t.Logf("Received error: %s", errors) errorsReceived.increment() } @@ -32,7 +32,7 @@ func TestFsnotifyFakeSymlink(t *testing.T) { // Count the CREATE events received var createEventsReceived, otherEventsReceived counter go func() { - for ev := range watcher.Event { + for ev := range watcher.Events { t.Logf("event received: %s", ev) if ev.IsCreate() { createEventsReceived.increment() diff --git a/fsnotify_test.go b/fsnotify_test.go index 36357c6..d9541f2 100644 --- a/fsnotify_test.go +++ b/fsnotify_test.go @@ -62,7 +62,7 @@ func TestFsnotifyMultipleOperations(t *testing.T) { // Receive errors on the error channel on a separate goroutine go func() { - for err := range watcher.Error { + for err := range watcher.Errors { t.Fatalf("error received: %s", err) } }() @@ -81,7 +81,7 @@ func TestFsnotifyMultipleOperations(t *testing.T) { addWatch(t, watcher, testDir) // Receive events on the event channel on a separate goroutine - eventstream := watcher.Event + eventstream := watcher.Events var createReceived, modifyReceived, deleteReceived, renameReceived counter done := make(chan bool) go func() { @@ -180,7 +180,7 @@ func TestFsnotifyMultipleCreates(t *testing.T) { // Receive errors on the error channel on a separate goroutine go func() { - for err := range watcher.Error { + for err := range watcher.Errors { t.Fatalf("error received: %s", err) } }() @@ -194,7 +194,7 @@ func TestFsnotifyMultipleCreates(t *testing.T) { addWatch(t, watcher, testDir) // Receive events on the event channel on a separate goroutine - eventstream := watcher.Event + eventstream := watcher.Events var createReceived, modifyReceived, deleteReceived counter done := make(chan bool) go func() { @@ -325,7 +325,7 @@ func TestFsnotifyDirOnly(t *testing.T) { // Receive errors on the error channel on a separate goroutine go func() { - for err := range watcher.Error { + for err := range watcher.Errors { t.Fatalf("error received: %s", err) } }() @@ -333,7 +333,7 @@ func TestFsnotifyDirOnly(t *testing.T) { testFile := filepath.Join(testDir, "TestFsnotifyDirOnly.testfile") // Receive events on the event channel on a separate goroutine - eventstream := watcher.Event + eventstream := watcher.Events var createReceived, modifyReceived, deleteReceived counter done := make(chan bool) go func() { @@ -430,13 +430,13 @@ func TestFsnotifyDeleteWatchedDir(t *testing.T) { // Receive errors on the error channel on a separate goroutine go func() { - for err := range watcher.Error { + for err := range watcher.Errors { t.Fatalf("error received: %s", err) } }() // Receive events on the event channel on a separate goroutine - eventstream := watcher.Event + eventstream := watcher.Events var deleteReceived counter go func() { for event := range eventstream { @@ -475,13 +475,13 @@ func TestFsnotifySubDir(t *testing.T) { // Receive errors on the error channel on a separate goroutine go func() { - for err := range watcher.Error { + for err := range watcher.Errors { t.Fatalf("error received: %s", err) } }() // Receive events on the event channel on a separate goroutine - eventstream := watcher.Event + eventstream := watcher.Events var createReceived, deleteReceived counter done := make(chan bool) go func() { @@ -567,7 +567,7 @@ func TestFsnotifyRename(t *testing.T) { // Receive errors on the error channel on a separate goroutine go func() { - for err := range watcher.Error { + for err := range watcher.Errors { t.Fatalf("error received: %s", err) } }() @@ -576,7 +576,7 @@ func TestFsnotifyRename(t *testing.T) { testFileRenamed := filepath.Join(testDir, "TestFsnotifyEvents.testfileRenamed") // Receive events on the event channel on a separate goroutine - eventstream := watcher.Event + eventstream := watcher.Events var renameReceived counter done := make(chan bool) go func() { @@ -649,7 +649,7 @@ func TestFsnotifyRenameToCreate(t *testing.T) { // Receive errors on the error channel on a separate goroutine go func() { - for err := range watcher.Error { + for err := range watcher.Errors { t.Fatalf("error received: %s", err) } }() @@ -658,7 +658,7 @@ func TestFsnotifyRenameToCreate(t *testing.T) { testFileRenamed := filepath.Join(testDir, "TestFsnotifyEvents.testfileRenamed") // Receive events on the event channel on a separate goroutine - eventstream := watcher.Event + eventstream := watcher.Events var createReceived counter done := make(chan bool) go func() { @@ -742,13 +742,13 @@ func TestFsnotifyRenameToOverwrite(t *testing.T) { // Receive errors on the error channel on a separate goroutine go func() { - for err := range watcher.Error { + for err := range watcher.Errors { t.Fatalf("error received: %s", err) } }() // Receive events on the event channel on a separate goroutine - eventstream := watcher.Event + eventstream := watcher.Events var eventReceived counter done := make(chan bool) go func() { @@ -825,7 +825,7 @@ func TestRemovalOfWatch(t *testing.T) { go func() { select { - case ev := <-watcher.Event: + case ev := <-watcher.Events: t.Fatalf("We received event: %v\n", ev) case <-time.After(500 * time.Millisecond): t.Log("No event received, as expected.") @@ -860,7 +860,7 @@ func TestFsnotifyAttrib(t *testing.T) { // Receive errors on the error channel on a separate goroutine go func() { - for err := range watcher.Error { + for err := range watcher.Errors { t.Fatalf("error received: %s", err) } }() @@ -868,7 +868,7 @@ func TestFsnotifyAttrib(t *testing.T) { testFile := filepath.Join(testDir, "TestFsnotifyAttrib.testfile") // Receive events on the event channel on a separate goroutine - eventstream := watcher.Event + eventstream := watcher.Events // The modifyReceived counter counts IsModify events that are not IsAttrib, // and the attribReceived counts IsAttrib events (which are also IsModify as // a consequence). diff --git a/fsnotify_windows.go b/fsnotify_windows.go index d685cda..8d6649f 100644 --- a/fsnotify_windows.go +++ b/fsnotify_windows.go @@ -47,7 +47,7 @@ const ( ) // Event is the type of the notification messages -// received on the watcher's Event channel. +// received on the watcher's Events channel. type FileEvent struct { mask uint32 // Mask of events cookie uint32 // Unique cookie associating related events (for rename) @@ -119,8 +119,8 @@ type Watcher struct { port syscall.Handle // Handle to completion port watches watchMap // Map of watches (key: i-number) input chan *input // Inputs to the reader are sent on this channel - Event chan *FileEvent // Events are returned on this channel - Error chan error // Errors are sent on this channel + Events chan *FileEvent // Events are returned on this channel + Errors chan error // Errors are sent on this channel isClosed bool // Set to true when Close() is first called quit chan chan<- error cookie uint32 @@ -136,8 +136,8 @@ func NewWatcher() (*Watcher, error) { port: port, watches: make(watchMap), input: make(chan *input, 1), - Event: make(chan *FileEvent, 50), - Error: make(chan error), + Events: make(chan *FileEvent, 50), + Errors: make(chan error), quit: make(chan chan<- error, 1), } go w.readEvents() @@ -356,7 +356,7 @@ func (w *Watcher) deleteWatch(watch *watch) { // Must run within the I/O thread. func (w *Watcher) startRead(watch *watch) error { if e := syscall.CancelIo(watch.ino.handle); e != nil { - w.Error <- os.NewSyscallError("CancelIo", e) + w.Errors <- os.NewSyscallError("CancelIo", e) w.deleteWatch(watch) } mask := toWindowsFlags(watch.mask) @@ -365,7 +365,7 @@ func (w *Watcher) startRead(watch *watch) error { } if mask == 0 { if e := syscall.CloseHandle(watch.ino.handle); e != nil { - w.Error <- os.NewSyscallError("CloseHandle", e) + w.Errors <- os.NewSyscallError("CloseHandle", e) } w.mu.Lock() delete(w.watches[watch.ino.volume], watch.ino.index) @@ -393,7 +393,7 @@ func (w *Watcher) startRead(watch *watch) error { } // readEvents reads from the I/O completion port, converts the -// received events into Event objects and sends them via the Event channel. +// received events into Event objects and sends them via the Events channel. // Entry point to the I/O thread. func (w *Watcher) readEvents() { var ( @@ -425,8 +425,8 @@ func (w *Watcher) readEvents() { if e := syscall.CloseHandle(w.port); e != nil { err = os.NewSyscallError("CloseHandle", e) } - close(w.Event) - close(w.Error) + close(w.Events) + close(w.Errors) ch <- err return case in := <-w.input: @@ -444,7 +444,7 @@ func (w *Watcher) readEvents() { switch e { case sys_ERROR_MORE_DATA: if watch == nil { - w.Error <- errors.New("ERROR_MORE_DATA has unexpectedly null lpOverlapped buffer") + w.Errors <- errors.New("ERROR_MORE_DATA has unexpectedly null lpOverlapped buffer") } else { // The i/o succeeded but the buffer is full. // In theory we should be building up a full packet. @@ -461,7 +461,7 @@ func (w *Watcher) readEvents() { // CancelIo was called on this handle continue default: - w.Error <- os.NewSyscallError("GetQueuedCompletionPort", e) + w.Errors <- os.NewSyscallError("GetQueuedCompletionPort", e) continue case nil: } @@ -469,8 +469,8 @@ func (w *Watcher) readEvents() { var offset uint32 for { if n == 0 { - w.Event <- &FileEvent{mask: sys_FS_Q_OVERFLOW} - w.Error <- errors.New("short read in readEvents()") + w.Events <- &FileEvent{mask: sys_FS_Q_OVERFLOW} + w.Errors <- errors.New("short read in readEvents()") break } @@ -528,13 +528,13 @@ func (w *Watcher) readEvents() { // Error! if offset >= n { - w.Error <- errors.New("Windows system assumed buffer larger than it is, events have likely been missed.") + w.Errors <- errors.New("Windows system assumed buffer larger than it is, events have likely been missed.") break } } if err := w.startRead(watch); err != nil { - w.Error <- err + w.Errors <- err } } } @@ -553,7 +553,7 @@ func (w *Watcher) sendEvent(name string, mask uint64) bool { select { case ch := <-w.quit: w.quit <- ch - case w.Event <- event: + case w.Events <- event: } return true }