]> go.fuhry.dev Git - fsnotify.git/commitdiff
Windows - fix up handling of ERROR_MORE_DATA
authorChris Howey <chris@howey.me>
Mon, 17 Jun 2013 23:11:16 +0000 (18:11 -0500)
committerChris Howey <chris@howey.me>
Mon, 17 Jun 2013 23:11:16 +0000 (18:11 -0500)
fsnotify_windows.go

index fd70a2b965eb53ebb108c43433b74b40b5b5a1d3..04dd5a05125f7d3763a342a402308cdade85801d 100644 (file)
@@ -42,7 +42,7 @@ const (
 )
 
 const (
-       ERROR_MORE_DATA syscall.Errno = 234
+       sys_ERROR_MORE_DATA syscall.Errno = 234
 )
 
 // Event is the type of the notification messages
@@ -442,15 +442,14 @@ func (w *Watcher) readEvents() {
                }
 
                switch e {
-               case ERROR_MORE_DATA:
+               case sys_ERROR_MORE_DATA:
                        if watch == nil {
                                w.Error <- errors.New("ERROR_MORE_DATA has unexpectedly null lpOverlapped buffer")
                        } else {
                                //The i/o succeeded but buffer is full
                                //in theory we should be building up a full packet
                                //in practice we can get away with just carrying on
-                               //should be len(watch.buf) possibly?
-                               n = 4096
+                               n = uint32(unsafe.Sizeof(watch.buf))
                        }
                case syscall.ERROR_ACCESS_DENIED:
                        // Watched directory was probably removed
@@ -526,6 +525,12 @@ func (w *Watcher) readEvents() {
                                break
                        }
                        offset += raw.NextEntryOffset
+
+                       // Error!
+                       if offset >= n {
+                               w.Error <- errors.New("Windows system assumed buffer larger than it is, events have likely been missed.")
+                               break
+                       }
                }
 
                if err := w.startRead(watch); err != nil {