Skip to content

Commit

Permalink
Fix libuv bump
Browse files Browse the repository at this point in the history
Revert "Revert "Update libuv""

This reverts commit a72e8a5.

Revert "Revert libuv bumps"

This reverts commit 1a08064.
  • Loading branch information
vtjnash committed Jul 27, 2013
1 parent ddca020 commit 217ce61
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 210 deletions.
2 changes: 1 addition & 1 deletion base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ file_constants.jl: ../src/file_constants.h
$(QUIET_PERL) ${CC} -E -P -DJULIA ../src/file_constants.h | perl -nle 'print "$$1 0o$$2" if /^(\s*const\s+[A-z_]+\s+=)\s+(0[0-9]*)\s*$$/; print "$$1" if /^\s*(const\s+[A-z_]+\s+=\s+([1-9]|0x)[0-9A-z]*)\s*$$/' > $@

uv_constants.jl: ../src/uv_constants.h
$(QUIET_PERL) ${CC} -E -P "-I$(LIBUV_INC)" -DJULIA ../src/uv_constants.h | tail -n 12 > $@
$(QUIET_PERL) ${CC} -E -P "-I$(LIBUV_INC)" -DJULIA ../src/uv_constants.h | tail -n 16 > $@

build_h.jl.phony:
$(QUIET_PERL) $(CC) -E -P build.h -I../src/support | grep . > $@
Expand Down
43 changes: 17 additions & 26 deletions base/poll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ type FileMonitor
function FileMonitor(cb, file)
handle = c_malloc(_sizeof_uv_fs_event)
err = ccall(:jl_fs_event_init,Int32, (Ptr{Void}, Ptr{Void}, Ptr{Uint8}, Int32), eventloop(),handle,file,0)
if err == -1
if err < 0
c_free(handle)
throw(UVError("FileMonitor"))
throw(UVError("FileMonitor",err))
end
this = new(handle,cb,false,Condition())
associate_julia_struct(handle,this)
Expand Down Expand Up @@ -41,9 +41,9 @@ type PollingFileWatcher <: UVPollingWatcher
function PollingFileWatcher(cb, file)
handle = c_malloc(_sizeof_uv_fs_poll)
err = ccall(:uv_fs_poll_init,Int32,(Ptr{Void},Ptr{Void}),eventloop(),handle)
if err == -1
if err < 0
c_free(handle)
throw(UVError("PollingFileWatcher"))
throw(UVError("PollingFileWatcher",err))
end
this = new(handle, file, false, Condition(), cb)
associate_julia_struct(handle,this)
Expand Down Expand Up @@ -76,9 +76,9 @@ function FDWatcher(fd::RawFD)
error("FD is already being watched by another watcher")
end
err = ccall(:uv_poll_init,Int32,(Ptr{Void},Ptr{Void},Int32),eventloop(),handle,fd.fd)
if err == -1
if err < 0
c_free(handle)
throw(UVError("FDWatcher"))
throw(UVError("FDWatcher",err))
end
this = FDWatcher(handle,fd,false,Condition(),false,0)
associate_julia_struct(handle,this)
Expand All @@ -89,9 +89,9 @@ end
handle = c_malloc(_sizeof_uv_poll)
err = ccall(:uv_poll_init_socket,Int32,(Ptr{Void}, Ptr{Void}, Ptr{Void}),
eventloop(), handle, fd.handle)
if err == -1
if err < 0
c_free(handle)
throw(UVError("FDWatcher"))
throw(UVError("FDWatcher",err))
end
this = FDWatcher(handle,fd,false,Condition(),false,0)
associate_julia_struct(handle,this)
Expand All @@ -101,9 +101,9 @@ end

function fdw_wait_cb(fdw::FDWatcher,status,events)
if status == -1
notify(fdw.notify,(UV_error_t(_uv_lasterror(),_uv_lastsystemerror()),events))
notify_error(fdw.notify,UVError("FDWatcher",status))
else
notify(fdw.notify,(UV_error_t(int32(0),int32(0)),events))
notify(fdw.notify,events)
end
end

Expand All @@ -119,10 +119,7 @@ function _wait(fdw::FDWatcher,readable,writeable)
start_watching(fdw_wait_cb,fdw,events)
end
while true
err, events = wait(fdw.notify)
if err.uv_code != 0
throw(UVError("wait (FD)",err))
end
events = wait(fdw.notify)
if (readable && (events & UV_READABLE) != 0) ||
(writeable && (events & UV_WRITEABLE) != 0)
break
Expand Down Expand Up @@ -180,21 +177,18 @@ let
end

function pfw_wait_cb(pfw::PollingFileWatcher, status, prev, cur)
if status == -1
notify(pfw.notify,(UV_error_t(_uv_lasterror(),_uv_lastsystemerror()),prev,cur))
if status < 0
notify_error(pfw.notify,UVError("PollingFileWatcher",status))
else
notify(pfw.notify,(UV_error_t(int32(0),int32(0)),prev,cur))
notify(pfw.notify,(prev,cur))
end
end

function wait(pfw::PollingFileWatcher; interval=3.0)
if !pfw.open
start_watching(pfw_wait_cb,pfw,interval)
end
err,prev,curr = wait(pfw.notify)
if err.uv_code != 0
throw(UVError("wait (PollingFileWatcher)",err))
end
prev,curr = wait(pfw.notify)
if isempty(pfw.notify.waitq)
stop_watching(pfw)
end
Expand All @@ -203,9 +197,6 @@ end

function wait(m::FileMonitor)
err, filename, events = wait(m.notify)
if err.uv_code != 0
throw(UVError("wait (FileMonitor)",err))
end
filename, events
end

Expand Down Expand Up @@ -246,9 +237,9 @@ function _uv_hook_fseventscb(t::FileMonitor,filename::Ptr,events::Int32,status::
# bytestring(convert(Ptr{Uint8},filename)) - seems broken at the moment - got NULL
t.cb(status, events, status)
if status == -1
notify(t.notify,(UV_error_t(_uv_lasterror(),_uv_lastsystemerror()),bytestring(convert(Ptr{Uint8},filename)),events))
notify_error(t.notify,UVError("FileMonitor",status))
else
notify(t.notify,(UV_error_t(int32(0),int32(0)),bytestring(convert(Ptr{Uint8},filename)),events))
notify(t.notify,events)
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function _jl_spawn(cmd::Ptr{Uint8}, argv::Ptr{Ptr{Uint8}}, loop::Ptr{Void}, pp::
pp.cmd.detach, pp.cmd.env === nothing ? C_NULL : pp.cmd.env)
if error != 0
c_free(proc)
throw(UVError("spawn"))
throw(UVError("spawn",error))
end
associate_julia_struct(proc,pp)
return proc
Expand Down Expand Up @@ -451,6 +451,7 @@ end
_jl_kill(p::Process,signum::Integer) = ccall(:uv_process_kill,Int32,(Ptr{Void},Int32),p.handle,signum)
function kill(p::Process,signum::Integer)
if process_running(p)
@assert p.handle != C_NULL
_jl_kill(p, signum)
else
int32(-1)
Expand Down
47 changes: 21 additions & 26 deletions base/socket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,12 @@ type TcpSocket <: Socket
end
function TcpSocket()
this = TcpSocket(c_malloc(_sizeof_uv_tcp))
if 0 != ccall(:uv_tcp_init,Cint,(Ptr{Void},Ptr{Void}),
err = ccall(:uv_tcp_init,Cint,(Ptr{Void},Ptr{Void}),
eventloop(),this.handle)
if err != 0
c_free(this.handle)
this.handle = C_NULL
error(UVError("Failed to create tcp socket"))
error(UVError("Failed to create tcp socket",err))
end
associate_julia_struct(this.handle, this)
this.status = StatusInit
Expand All @@ -282,11 +283,12 @@ type TcpServer <: UVServer
end
function TcpServer()
this = TcpServer(c_malloc(_sizeof_uv_tcp))
if 0 != ccall(:uv_tcp_init,Cint,(Ptr{Void},Ptr{Void}),
err = ccall(:uv_tcp_init,Cint,(Ptr{Void},Ptr{Void}),
eventloop(),this.handle)
if err != 0
c_free(this.handle)
this.handle = C_NULL
error(UVError("Failed to create tcp server"))
error(UVError("Failed to create tcp server",err))
end
associate_julia_struct(this.handle, this)
this.status = StatusInit
Expand Down Expand Up @@ -332,16 +334,13 @@ accept(server::PipeServer) = accept(server, NamedPipe())
bind(sock::TcpServer, addr::InetAddr) = bind(sock,addr.host,addr.port)
bind(sock::TcpServer, host::IpAddr, port) = bind(sock, InetAddr(host,port))

const UV_SUCCESS = 0
const UV_EACCES = 3
const UV_EADDRINUSE = 5

function bind(sock::TcpServer, host::IPv4, port::Uint16)
@assert sock.status == StatusInit
if 0 != ccall(:jl_tcp_bind, Int32, (Ptr{Void}, Uint16, Uint32),
err = ccall(:jl_tcp_bind, Int32, (Ptr{Void}, Uint16, Uint32),
sock.handle, hton(port), hton(host.host))
if (err=_uv_lasterror()) != UV_EADDRINUSE && err != UV_EACCES
error(UVError("bind"))
if err < 0
if err != UV_EADDRINUSE && err != UV_EACCES
error(UVError("bind",err))
else
return false
end
Expand All @@ -352,10 +351,11 @@ end

function bind(sock::TcpServer, host::IPv6, port::Uint16)
@assert sock.status == StatusInit
if 0 != ccall(:jl_tcp_bind6, Int32, (Ptr{Void}, Uint16, Ptr{Uint128}),
err = ccall(:jl_tcp_bind6, Int32, (Ptr{Void}, Uint16, Ptr{Uint128}),
sock.handle, hton(port), &hton(host.host))
if (err=_uv_lasterror()) != UV_EADDRINUSE && err != UV_EACCES
error(UVError("bind"))
if err < 0
if err != UV_EADDRINUSE && err != UV_EACCES
error(UVError("bind",err))
else
return false
end
Expand All @@ -369,7 +369,7 @@ callback_dict = ObjectIdDict()
function _uv_hook_getaddrinfo(cb::Function, addrinfo::Ptr{Void}, status::Int32)
delete!(callback_dict,cb)
if status != 0 || addrinfo == C_NULL
cb(UVError("getaddrinfo callback"))
cb(UVError("getaddrinfo callback",status))
return
end
freeaddrinfo = addrinfo
Expand Down Expand Up @@ -414,7 +414,7 @@ function getipaddr()
addr, count = addr[1],count[1]
if err != 0
ccall(:uv_free_interface_addresses,Void,(Ptr{Uint8},Int32),addr,count)
throw(UVError("getlocalip",err,0))
throw(UVError("getlocalip",err))
end
for i = 0:(count-1)
current_addr = addr + i*_sizeof_uv_interface_address
Expand Down Expand Up @@ -479,12 +479,12 @@ end

##

listen(sock::UVServer; backlog::Integer=BACKLOG_DEFAULT) = (uv_error("listen",!listen!(sock;backlog=backlog)); sock)
listen(sock::UVServer; backlog::Integer=BACKLOG_DEFAULT) = (uv_error("listen",_listen(sock;backlog=backlog)); sock)

function listen(addr; backlog::Integer=BACKLOG_DEFAULT)
sock = TcpServer()
uv_error("listen",!bind(sock,addr))
uv_error("listen",!listen!(sock;backlog=backlog))
!bind(sock,addr) && error("Cannot bind to port (may already be in use or access denied)")
uv_error("listen",_listen(sock;backlog=backlog))
sock
end
listen(port::Integer; backlog::Integer=BACKLOG_DEFAULT) = listen(IPv4(uint32(0)),port;backlog=backlog)
Expand All @@ -505,7 +505,7 @@ function accept_nonblock(server::TcpServer,client::TcpSocket)
end
function accept_nonblock(server::TcpServer)
client = TcpSocket()
uv_error("accept", accept_nonblock(server, client) == -1)
uv_error("accept", accept_nonblock(server, client))
client
end

Expand All @@ -516,15 +516,10 @@ function open_any_tcp_port(cb::Callback,default_port)
while true
sock = TcpServer()
sock.ccb = cb
if (bind(sock,addr) && listen!(sock))
if (bind(sock,addr) && _listen(sock) == 0)
return (addr.port,sock)
end
err = _uv_lasterror()
system = _uv_lastsystemerror()
close(sock)
if (err != UV_SUCCESS && err != UV_EADDRINUSE && err != UV_EACCES)
throw(UVError("open_any_tcp_port",err,system))
end
addr.port += 1
if (addr.port==default_port)
error("Not a single port is available.")
Expand Down
4 changes: 1 addition & 3 deletions base/stat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ macro stat_call(sym,arg1type,arg)
quote
fill!(stat_buf,0)
r = ccall($(Expr(:quote,sym)), Int32, ($arg1type,Ptr{Uint8}), $arg, stat_buf)
uv_errno = _uv_lasterror(eventloop())
ENOENT, ENOTDIR = 34, 27
systemerror(:stat, r!=0 && uv_errno!=ENOENT && uv_errno!=ENOTDIR)
systemerror(:stat, r!=0 && r!=UV_ENOENT && r!=UV_ENOTDIR)
st = Stat(stat_buf)
if ispath(st) != (r==0)
error("WTF: stat returned zero type for a valid path!?")
Expand Down
Loading

0 comments on commit 217ce61

Please sign in to comment.