From 53651c9d74f28186abdbca83cc170583704e0610 Mon Sep 17 00:00:00 2001 From: "Blake R. Johnson" Date: Wed, 4 Sep 2013 15:27:59 -0400 Subject: [PATCH 1/8] Export watch_file. Export watch_file, as this is the easiest API entry point between FileMonitor and PollingFileMonitor. Fix _uv_hook_fseventscb such that the condition is notified even if no callback is in the monitor. Also fix the value sent to notify() to match the expected return value in wait(). Fix watch_poll default callback. --- base/exports.jl | 3 +++ base/poll.jl | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/base/exports.jl b/base/exports.jl index 0d67f22e33427..a689485ef1502 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -1075,8 +1075,11 @@ export takebuf_array, takebuf_string, truncate, + UV_CHANGE, UV_READABLE, + UV_RENAME, UV_WRITABLE, + watch_file, WindowsRawSocket, write, writecsv, diff --git a/base/poll.jl b/base/poll.jl index 54b00b361a73d..6829459eab53d 100644 --- a/base/poll.jl +++ b/base/poll.jl @@ -24,8 +24,12 @@ function close(t::FileMonitor) end end +# Polling event flags const UV_READABLE = 1 const UV_WRITABLE = 2 +# Non-polling event flags +const UV_RENAME = 1 +const UV_CHANGE = 2 convert(::Type{Int32},fd::RawFD) = fd.fd @@ -237,14 +241,14 @@ function stop_watching(t::PollingFileWatcher) end function _uv_hook_fseventscb(t::FileMonitor,filename::Ptr,events::Int32,status::Int32) + fname = bytestring(convert(Ptr{Uint8},filename)) # seems broken at the moment - got NULL if isa(t.cb,Function) - # bytestring(convert(Ptr{Uint8},filename)) - seems broken at the moment - got NULL - t.cb(status, events, status) - if status == -1 - notify_error(t.notify,UVError("FileMonitor",status)) - else - notify(t.notify,events) - end + t.cb(fname, events, status) + end + if status < 0 + notify_error(t.notify,(UVError("FileMonitor",status), fname, events)) + else + notify(t.notify,(status, fname, events)) end end @@ -282,6 +286,7 @@ function poll_file(s, interval_seconds::Real, seconds::Real) wait(wt) == :poll end +watch_file(s; poll=false) = watch_file(false, s, poll=poll) function watch_file(cb, s; poll=false) if poll pfw = PollingFileWatcher(cb,s) From 9f0fe250bcd8842785a14f9c21fa06956e760c72 Mon Sep 17 00:00:00 2001 From: "Blake R. Johnson" Date: Wed, 4 Sep 2013 17:03:23 -0400 Subject: [PATCH 2/8] Document watch_file method. --- doc/stdlib/base.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index 65b9a5ec57210..4cddafbaecdc7 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -1429,6 +1429,10 @@ Network I/O Create a TcpServer on any port, using hint as a starting point. Returns a tuple of the actual port that the server was created on and the server itself. +.. function:: watch_file(cb=false, s; poll=false) + + Watch file or directory ``s`` and run callback ``cb`` when ``s`` is modified. The ``poll`` parameter specifies whether to use file system event monitoring or polling. The callback function ``cb`` should accept 3 arguments: ``(filename, events, status)`` where ``filename`` is the name of file that was modified, ``events`` can be ``UV_CHANGE`` or ``UV_RENAME`` when using file system event monitoring, or ``UV_READABLE`` or ``UV_WRITABLE`` when using polling, and ``status`` is always 0. Pass ``false`` for ``cb`` to not use a callback function. + .. function:: poll_fd(fd, seconds::Real; readable=false, writable=false) Poll a file descriptor fd for changes in the read or write availability and with a timeout given by the second argument. From b9f0863b9288abc842706f9038707770bc44d732 Mon Sep 17 00:00:00 2001 From: Blake Johnson Date: Thu, 5 Sep 2013 06:25:47 -0400 Subject: [PATCH 3/8] Add a test for wait(FileMonitor). --- test/file.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/file.jl b/test/file.jl index ad0ebeee28bcf..5b801c09c8e6b 100644 --- a/test/file.jl +++ b/test/file.jl @@ -90,6 +90,19 @@ function test_monitor(slval) close(fm) end +function test_monitor_wait(tval) + fm = watch_file(file) + @async begin + sleep(tval/10_000) + f = open(file,"a") + write(f,"Hello World\n") + close(f) + end + fname, events = wait(fm) + @test fname == basename(file) + @test events == UV_CHANGE +end + # Commented out the tests below due to issues 3015, 3016 and 3020 test_timeout(0.1) test_timeout(1) @@ -97,6 +110,7 @@ test_touch(0.1) test_touch(1) test_monitor(1) test_monitor(0.1) +test_monitor_wait(0.1) ########## # mmap # From 0f04d2872ca55d62245dd8d3dbf830d07172f311 Mon Sep 17 00:00:00 2001 From: "Blake R. Johnson" Date: Mon, 9 Sep 2013 14:18:50 -0400 Subject: [PATCH 4/8] Unexport new UV_ constants. --- base/exports.jl | 2 -- test/file.jl | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/base/exports.jl b/base/exports.jl index a689485ef1502..4b79cae4d6c33 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -1075,9 +1075,7 @@ export takebuf_array, takebuf_string, truncate, - UV_CHANGE, UV_READABLE, - UV_RENAME, UV_WRITABLE, watch_file, WindowsRawSocket, diff --git a/test/file.jl b/test/file.jl index 5b801c09c8e6b..cd75aa9a7834b 100644 --- a/test/file.jl +++ b/test/file.jl @@ -100,7 +100,7 @@ function test_monitor_wait(tval) end fname, events = wait(fm) @test fname == basename(file) - @test events == UV_CHANGE + @test events == Base.UV_CHANGE end # Commented out the tests below due to issues 3015, 3016 and 3020 From 84e9905386ecd522f8911dfb3456ed4fd7ed4d77 Mon Sep 17 00:00:00 2001 From: Blake Johnson Date: Tue, 10 Sep 2013 06:59:05 -0400 Subject: [PATCH 5/8] WIP: File watching event refactor. --- base/exports.jl | 2 -- base/poll.jl | 50 +++++++++++++++++++++++++++++++++++++------------ test/file.jl | 2 +- test/pollfd.jl | 4 ++-- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/base/exports.jl b/base/exports.jl index 4b79cae4d6c33..91e5f5136a23f 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -1075,8 +1075,6 @@ export takebuf_array, takebuf_string, truncate, - UV_READABLE, - UV_WRITABLE, watch_file, WindowsRawSocket, write, diff --git a/base/poll.jl b/base/poll.jl index 6829459eab53d..24ac16ef685b2 100644 --- a/base/poll.jl +++ b/base/poll.jl @@ -24,12 +24,37 @@ function close(t::FileMonitor) end end -# Polling event flags +immutable FileEvent + readable::Bool + writable::Bool + renamed::Bool + changed::Bool + timeout::Bool +end + +function |(FileEvent e1, FileEvent e2) + FileEvent( + e1.readable || e2.readable, + e1.writable || e2.writable, + e1.renamed || e2.renamed, + e1.changed || e2.changed, + e1.timeout || e2.timeout) +end + +# libuv polling event flags const UV_READABLE = 1 const UV_WRITABLE = 2 -# Non-polling event flags -const UV_RENAME = 1 -const UV_CHANGE = 2 +function pollevent(events) + timeout = (events & (UV_READABLE | UV_WRITABLE) == 0) + FileEvent((events & UV_READABLE) != 0, (events & UV_WRITABLE) != 0, false, false, timeout) +end + +function monitorevent(events) + # Non-polling event flags + const UV_RENAME = 1 + const UV_CHANGE = 2 + FileEvent(false, false, (events & UV_RENAME) != 0, (events & UV_CHANGE) != 0, false) +end convert(::Type{Int32},fd::RawFD) = fd.fd @@ -111,7 +136,7 @@ function fdw_wait_cb(fdw::FDWatcher,status,events) if status == -1 notify_error(fdw.notify,UVError("FDWatcher",status)) else - notify(fdw.notify,events) + notify(fdw.notify,pollevent(events)) end end @@ -128,8 +153,7 @@ function _wait(fdw::FDWatcher,readable,writable) end while true events = wait(fdw.notify) - if (readable && (events & UV_READABLE) != 0) || - (writable && (events & UV_WRITABLE) != 0) + if (readable && events.readable) || (writable && events.writable) break end end @@ -241,22 +265,24 @@ function stop_watching(t::PollingFileWatcher) end function _uv_hook_fseventscb(t::FileMonitor,filename::Ptr,events::Int32,status::Int32) - fname = bytestring(convert(Ptr{Uint8},filename)) # seems broken at the moment - got NULL + fname = bytestring(convert(Ptr{Uint8},filename)) + fileEvent = monitorevent(events) if isa(t.cb,Function) - t.cb(fname, events, status) + t.cb(fname, fileEvent, status) end if status < 0 - notify_error(t.notify,(UVError("FileMonitor",status), fname, events)) + notify_error(t.notify,(UVError("FileMonitor",status), fname, fileEvent)) else - notify(t.notify,(status, fname, events)) + notify(t.notify,(status, fname, fileEvent)) end end function _uv_hook_pollcb(t::FDWatcher,status::Int32,events::Int32) if isa(t.cb,Function) - t.cb(t,status, events) + t.cb(t, pollevent(events), status) end end + function _uv_hook_fspollcb(t::PollingFileWatcher,status::Int32,prev::Ptr,cur::Ptr) if isa(t.cb,Function) t.cb(t, status, Stat(convert(Ptr{Uint8},prev)), Stat(convert(Ptr{Uint8},cur))) diff --git a/test/file.jl b/test/file.jl index cd75aa9a7834b..d43af77ae35b4 100644 --- a/test/file.jl +++ b/test/file.jl @@ -100,7 +100,7 @@ function test_monitor_wait(tval) end fname, events = wait(fm) @test fname == basename(file) - @test events == Base.UV_CHANGE + @test events.changed == true end # Commented out the tests below due to issues 3015, 3016 and 3020 diff --git a/test/pollfd.jl b/test/pollfd.jl index 7fbe5e1acccc8..4bc99a943174f 100644 --- a/test/pollfd.jl +++ b/test/pollfd.jl @@ -15,7 +15,7 @@ function test_timeout(tval) tr = consume(t) t_elapsed = toq() - @test tr == 0 + @test tr.timeout == true tdiff = t_elapsed * 1000 @test tval <= tdiff @@ -32,7 +32,7 @@ function test_read(slval) tr = consume(t) t_elapsed = toq() - @test tr == UV_READABLE || (UV_READABLE | UV_WRITABLE) + @test tr.readable || tr.writable dout = Array(Uint8, 1) @test 1 == ccall(:read, Csize_t, (Cint, Ptr{Uint8},Csize_t), pipe_fds[1], dout, 1) From 6135236172a32ed3fbeedad821f135c4fbf1f9ad Mon Sep 17 00:00:00 2001 From: "Blake R. Johnson" Date: Tue, 10 Sep 2013 15:36:29 -0400 Subject: [PATCH 6/8] Re-passing tests. --- base/poll.jl | 80 ++++++++++++++++++++++++++++++---------------------- test/file.jl | 6 ++-- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/base/poll.jl b/base/poll.jl index 24ac16ef685b2..69a0d4b5e8164 100644 --- a/base/poll.jl +++ b/base/poll.jl @@ -25,37 +25,50 @@ function close(t::FileMonitor) end immutable FileEvent - readable::Bool - writable::Bool renamed::Bool changed::Bool timeout::Bool end -function |(FileEvent e1, FileEvent e2) +immutable FDEvent + readable::Bool + writable::Bool + timeout::Bool +end +FDEvent() = FDEvent(false, false, false) + +function fileevent(events) + # libuv file watching event flags + const UV_RENAME = 1 + const UV_CHANGE = 2 + timeout = (events & (UV_RENAME | UV_CHANGE) == 0) + FileEvent((events & UV_RENAME) != 0, (events & UV_CHANGE) != 0, timeout) +end + +function (|)(e1::FileEvent, e2::FileEvent) FileEvent( - e1.readable || e2.readable, - e1.writable || e2.writable, e1.renamed || e2.renamed, e1.changed || e2.changed, e1.timeout || e2.timeout) end -# libuv polling event flags +# libuv file descriptor event flags const UV_READABLE = 1 const UV_WRITABLE = 2 -function pollevent(events) +function fdevent(events) timeout = (events & (UV_READABLE | UV_WRITABLE) == 0) - FileEvent((events & UV_READABLE) != 0, (events & UV_WRITABLE) != 0, false, false, timeout) + FDEvent((events & UV_READABLE) != 0, (events & UV_WRITABLE) != 0, timeout) end -function monitorevent(events) - # Non-polling event flags - const UV_RENAME = 1 - const UV_CHANGE = 2 - FileEvent(false, false, (events & UV_RENAME) != 0, (events & UV_CHANGE) != 0, false) -end +fdtimeout() = FDEvent(false, false, true) +function (|)(e1::FDEvent, e2::FDEvent) + FDEvent( + e1.readable || e2.readable, + e1.writable || e2.writable, + e1.timeout || e2.timeout) +end +convert(::Type{Int32}, e::FDEvent) = e.readable*UV_READABLE + e.writable*UV_WRITABLE convert(::Type{Int32},fd::RawFD) = fd.fd #Wrapper for an OS file descriptor (for Windows) @@ -98,9 +111,9 @@ type FDWatcher <: UVPollingWatcher open::Bool notify::Condition cb::Callback - events::Int32 - FDWatcher(handle::Ptr,fd,open::Bool,notify::Condition,cb::Callback,events::Integer) = - new(handle,_get_osfhandle(fd),open,notify,cb,int32(events)) + events::FDEvent + FDWatcher(handle::Ptr,fd,open::Bool,notify::Condition,cb::Callback,events::FDEvent) = + new(handle,_get_osfhandle(fd),open,notify,cb,events) end function FDWatcher(fd::RawFD) handle = c_malloc(_sizeof_uv_poll) @@ -113,7 +126,7 @@ function FDWatcher(fd::RawFD) c_free(handle) throw(UVError("FDWatcher",err)) end - this = FDWatcher(handle,fd,false,Condition(),false,0) + this = FDWatcher(handle,fd,false,Condition(),false,FDEvent()) associate_julia_struct(handle,this) finalizer(this,close) this @@ -126,24 +139,23 @@ end c_free(handle) throw(UVError("FDWatcher",err)) end - this = FDWatcher(handle,fd,false,Condition(),false,0) + this = FDWatcher(handle,fd,false,Condition(),false,FDEvent()) associate_julia_struct(handle,this) finalizer(this,close) this end -function fdw_wait_cb(fdw::FDWatcher,status,events) +function fdw_wait_cb(fdw::FDWatcher, events::FDEvent, status) if status == -1 notify_error(fdw.notify,UVError("FDWatcher",status)) else - notify(fdw.notify,pollevent(events)) + notify(fdw.notify,events) end end function _wait(fdw::FDWatcher,readable,writable) - events = (readable ? UV_READABLE : 0) | - (writable ? UV_WRITABLE : 0) - if events == 0 + events = FDEvent(readable, writable, false) + if !readable && ! writable error("Must be watching for at least one event") end events |= fdw.events @@ -153,7 +165,7 @@ function _wait(fdw::FDWatcher,readable,writable) end while true events = wait(fdw.notify) - if (readable && events.readable) || (writable && events.writable) + if isa(events, FDEvent) && ((events.readable == readable) || (events.writable == writable)) break end end @@ -170,7 +182,7 @@ end let global fdwatcher_reinit - const empty_watcher = FDWatcher(C_NULL,RawFD(-1),false,Condition(),false,0) + const empty_watcher = FDWatcher(C_NULL,RawFD(-1),false,Condition(),false,FDEvent()) @unix_only begin local fdwatcher_array = Array(FDWatcher,0) function fdwatcher_reinit() @@ -208,7 +220,7 @@ let end end -function pfw_wait_cb(pfw::PollingFileWatcher, status, prev, cur) +function pfw_wait_cb(pfw::PollingFileWatcher, prev, cur, status) if status < 0 notify_error(pfw.notify,UVError("PollingFileWatcher",status)) else @@ -235,15 +247,15 @@ end close(t::UVPollingWatcher) = ccall(:jl_close_uv,Void,(Ptr{Void},),t.handle) -function start_watching(t::FDWatcher, events) +function start_watching(t::FDWatcher, events::FDEvent) associate_julia_struct(t.handle, t) @unix_only if ccall(:jl_uv_unix_fd_is_watched,Int32,(Int32,Ptr{Void},Ptr{Void}),t.fd,t.handle,eventloop()) == 1 error("Cannot watch an FD more than once on Unix") end uv_error("start_watching (FD)", - ccall(:jl_poll_start,Int32,(Ptr{Void},Int32),t.handle,events)) + ccall(:jl_poll_start,Int32,(Ptr{Void},Int32),t.handle,int32(events))) end -start_watching(f::Function, t::FDWatcher, events) = (t.cb = f; start_watching(t,events)) +start_watching(f::Function, t::FDWatcher, events::FDEvent) = (t.cb = f; start_watching(t,events)) function start_watching(t::PollingFileWatcher, interval) associate_julia_struct(t.handle, t) @@ -266,7 +278,7 @@ end function _uv_hook_fseventscb(t::FileMonitor,filename::Ptr,events::Int32,status::Int32) fname = bytestring(convert(Ptr{Uint8},filename)) - fileEvent = monitorevent(events) + fileEvent = fileevent(events) if isa(t.cb,Function) t.cb(fname, fileEvent, status) end @@ -279,13 +291,13 @@ end function _uv_hook_pollcb(t::FDWatcher,status::Int32,events::Int32) if isa(t.cb,Function) - t.cb(t, pollevent(events), status) + t.cb(t, fdevent(events), status) end end function _uv_hook_fspollcb(t::PollingFileWatcher,status::Int32,prev::Ptr,cur::Ptr) if isa(t.cb,Function) - t.cb(t, status, Stat(convert(Ptr{Uint8},prev)), Stat(convert(Ptr{Uint8},cur))) + t.cb(t, Stat(convert(Ptr{Uint8},prev)), Stat(convert(Ptr{Uint8},cur)), status) end end @@ -296,7 +308,7 @@ function poll_fd(s, seconds::Real; readable=false, writable=false) wt = Condition() @schedule (args = wait(s; readable=readable, writable=writable); notify(wt,(:poll,args))) - @schedule (sleep(seconds); notify(wt,(:timeout,0))) + @schedule (sleep(seconds); notify(wt,(:timeout,fdtimeout()))) _, ret = wait(wt) diff --git a/test/file.jl b/test/file.jl index d43af77ae35b4..afe23838663cd 100644 --- a/test/file.jl +++ b/test/file.jl @@ -54,7 +54,7 @@ function test_timeout(tval) tr = take(channel) t_elapsed = toq() - @test tr == 0 + @test tr == false tdiff = t_elapsed * 1000 @test tval <= tdiff @@ -72,7 +72,7 @@ function test_touch(slval) tr = take(channel) - # @test tr == 1 + @test tr == true end @@ -85,7 +85,7 @@ function test_monitor(slval) f = open(file,"a") write(f,"Hello World\n") close(f) - sleep(9slval/10_000) + sleep(slval/10_000) @test FsMonitorPassed close(fm) end From 4845bbc71f06a075cb17ec2950dfbe3073e056fc Mon Sep 17 00:00:00 2001 From: "Blake R. Johnson" Date: Wed, 11 Sep 2013 11:55:15 -0400 Subject: [PATCH 7/8] Refactor events with integer flag fields and accessors. --- base/exports.jl | 3 ++ base/poll.jl | 77 +++++++++++++++++++++---------------------------- test/file.jl | 2 +- test/pollfd.jl | 4 +-- 4 files changed, 39 insertions(+), 47 deletions(-) diff --git a/base/exports.jl b/base/exports.jl index 91e5f5136a23f..2bb61f91ddc9f 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -1014,6 +1014,7 @@ export # I/O and events accept, + changed, close, connect, countlines, @@ -1061,6 +1062,7 @@ export redirect_stderr, redirect_stdin, redirect_stdout, + renamed, seek, seekend, seekstart, @@ -1074,6 +1076,7 @@ export stop_timer, takebuf_array, takebuf_string, + timedout, truncate, watch_file, WindowsRawSocket, diff --git a/base/poll.jl b/base/poll.jl index 69a0d4b5e8164..248f83dc97d54 100644 --- a/base/poll.jl +++ b/base/poll.jl @@ -25,51 +25,40 @@ function close(t::FileMonitor) end immutable FileEvent - renamed::Bool - changed::Bool - timeout::Bool + flags::Int32 end +# libuv file watching event flags +const UV_RENAME = 1 +const UV_CHANGE = 2 +const FE_TIMEDOUT = 4 +renamed(f::FileEvent) = (f.flags & UV_RENAME) != 0 +changed(f::FileEvent) = (f.flags & UV_CHANGE) != 0 +timedout(f::FileEvent) = (f.flags & FE_TIMEDOUT) != 0 +FileEvent() = FileEvent(0) +FileEvent(flags::Integer) = FileEvent(int32(flags)) +FileEvent(renamed, changed, timedout) = FileEvent(renamed*UV_RENAME + changed*UV_CHANGE + timedout*FE_TIMEDOUT) immutable FDEvent - readable::Bool - writable::Bool - timeout::Bool + flags::Int32 end -FDEvent() = FDEvent(false, false, false) - -function fileevent(events) - # libuv file watching event flags - const UV_RENAME = 1 - const UV_CHANGE = 2 - timeout = (events & (UV_RENAME | UV_CHANGE) == 0) - FileEvent((events & UV_RENAME) != 0, (events & UV_CHANGE) != 0, timeout) -end - -function (|)(e1::FileEvent, e2::FileEvent) - FileEvent( - e1.renamed || e2.renamed, - e1.changed || e2.changed, - e1.timeout || e2.timeout) -end - # libuv file descriptor event flags const UV_READABLE = 1 const UV_WRITABLE = 2 -function fdevent(events) - timeout = (events & (UV_READABLE | UV_WRITABLE) == 0) - FDEvent((events & UV_READABLE) != 0, (events & UV_WRITABLE) != 0, timeout) -end - -fdtimeout() = FDEvent(false, false, true) - -function (|)(e1::FDEvent, e2::FDEvent) - FDEvent( - e1.readable || e2.readable, - e1.writable || e2.writable, - e1.timeout || e2.timeout) -end -convert(::Type{Int32}, e::FDEvent) = e.readable*UV_READABLE + e.writable*UV_WRITABLE -convert(::Type{Int32},fd::RawFD) = fd.fd +const FD_TIMEDOUT = 4 +isreadable(f::FDEvent) = (f.flags & UV_READABLE) != 0 +iswritable(f::FDEvent) = (f.flags & UV_WRITABLE) != 0 +timedout(f::FDEvent) = (f.flags & FD_TIMEDOUT) != 0 +FDEvent() = FDEvent(0) +FDEvent(flags::Integer) = FDEvent(int32(flags)) +FDEvent(isreadable, iswritable, timedout) = FDEvent(isreadable*UV_READABLE + iswritable*UV_WRITABLE + timedout*FD_TIMEDOUT) +fdtimeout() = FDEvent(FD_TIMEDOUT) + +(|)(a::FileEvent, b::FileEvent) = FileEvent(a.flags | b.flags) +(|)(a::FDEvent, b::FDEvent) = FDEvent(a.flags | b.flags) + +convert(::Type{Int32}, e::FileEvent) = int32(e.flags) +convert(::Type{Int32}, e::FDEvent) = int32(e.flags) +convert(::Type{Int32}, fd::RawFD) = fd.fd #Wrapper for an OS file descriptor (for Windows) @windows_only immutable WindowsRawSocket @@ -165,7 +154,7 @@ function _wait(fdw::FDWatcher,readable,writable) end while true events = wait(fdw.notify) - if isa(events, FDEvent) && ((events.readable == readable) || (events.writable == writable)) + if isa(events, FDEvent) && ((isreadable(events) == readable) || (iswritable(events) == writable)) break end end @@ -278,20 +267,20 @@ end function _uv_hook_fseventscb(t::FileMonitor,filename::Ptr,events::Int32,status::Int32) fname = bytestring(convert(Ptr{Uint8},filename)) - fileEvent = fileevent(events) + fe = FileEvent(events) if isa(t.cb,Function) - t.cb(fname, fileEvent, status) + t.cb(fname, fe, status) end if status < 0 - notify_error(t.notify,(UVError("FileMonitor",status), fname, fileEvent)) + notify_error(t.notify,(UVError("FileMonitor",status), fname, fe)) else - notify(t.notify,(status, fname, fileEvent)) + notify(t.notify,(status, fname, fe)) end end function _uv_hook_pollcb(t::FDWatcher,status::Int32,events::Int32) if isa(t.cb,Function) - t.cb(t, fdevent(events), status) + t.cb(t, FDEvent(events), status) end end diff --git a/test/file.jl b/test/file.jl index afe23838663cd..15b9f67f4a210 100644 --- a/test/file.jl +++ b/test/file.jl @@ -100,7 +100,7 @@ function test_monitor_wait(tval) end fname, events = wait(fm) @test fname == basename(file) - @test events.changed == true + @test changed(events) == true end # Commented out the tests below due to issues 3015, 3016 and 3020 diff --git a/test/pollfd.jl b/test/pollfd.jl index 4bc99a943174f..3676283060d95 100644 --- a/test/pollfd.jl +++ b/test/pollfd.jl @@ -15,7 +15,7 @@ function test_timeout(tval) tr = consume(t) t_elapsed = toq() - @test tr.timeout == true + @test timedout(tr) == true tdiff = t_elapsed * 1000 @test tval <= tdiff @@ -32,7 +32,7 @@ function test_read(slval) tr = consume(t) t_elapsed = toq() - @test tr.readable || tr.writable + @test isreadable(tr) || iswritable(tr) dout = Array(Uint8, 1) @test 1 == ccall(:read, Csize_t, (Cint, Ptr{Uint8},Csize_t), pipe_fds[1], dout, 1) From 3badc469abe4a1f32e5c64cb09b30e9fd6661ed2 Mon Sep 17 00:00:00 2001 From: "Blake R. Johnson" Date: Wed, 11 Sep 2013 13:08:53 -0400 Subject: [PATCH 8/8] Fix logic bug in FDWatcher wait() --- base/poll.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/poll.jl b/base/poll.jl index 248f83dc97d54..f496e90d425b5 100644 --- a/base/poll.jl +++ b/base/poll.jl @@ -154,7 +154,7 @@ function _wait(fdw::FDWatcher,readable,writable) end while true events = wait(fdw.notify) - if isa(events, FDEvent) && ((isreadable(events) == readable) || (iswritable(events) == writable)) + if isa(events, FDEvent) && ((readable && isreadable(events)) || (writable && iswritable(events))) break end end