Skip to content

Commit

Permalink
correct overtyping of bind/socket functions (fix #9435)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Jan 14, 2015
1 parent 1763fef commit a36423a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
7 changes: 3 additions & 4 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ function _listen(sock::UVServer; backlog::Integer=BACKLOG_DEFAULT)
err
end

function bind(server::PipeServer, name::ASCIIString)
function bind(server::PipeServer, name::AbstractString)
@assert server.status == StatusInit
err = ccall(:uv_pipe_bind, Int32, (Ptr{Void}, Ptr{UInt8}),
server.handle, name)
Expand All @@ -894,22 +894,21 @@ function bind(server::PipeServer, name::ASCIIString)
end


function listen(path::ByteString)
function listen(path::AbstractString)
sock = PipeServer()
bind(sock, path) || error("could not listen on path $path")
uv_error("listen", _listen(sock))
sock
end

function connect!(sock::Pipe, path::ByteString)
function connect!(sock::Pipe, path::AbstractString)
@assert sock.status == StatusInit
req = c_malloc(_sizeof_uv_connect)
uv_req_set_data(req,C_NULL)
ccall(:uv_pipe_connect, Void, (Ptr{Void}, Ptr{Void}, Ptr{UInt8}, Ptr{Void}), req, sock.handle, path, uv_jl_connectcb::Ptr{Void})
sock.status = StatusConnecting
sock
end
connect!(sock::Pipe, path::AbstractString) = connect(sock,bytestring(path))

function connect(sock::AsyncStream, args...)
connect!(sock,args...)
Expand Down
20 changes: 11 additions & 9 deletions test/socket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ wait(c)

socketname = @windows ? "\\\\.\\pipe\\uv-test" : "testsocket"
@unix_only isfile(socketname) && Base.FS.unlink(socketname)
@async begin
s = listen(socketname)
Base.notify(c)
sock = accept(s)
write(sock,"Hello World\n")
close(s)
close(sock)
for T in (ASCIIString, UTF8String, UTF16String) # test for issue #9435
@async begin
s = listen(T(socketname))
Base.notify(c)
sock = accept(s)
write(sock,"Hello World\n")
close(s)
close(sock)
end
wait(c)
@test readall(connect(socketname)) == "Hello World\n"
end
wait(c)
@test readall(connect(socketname)) == "Hello World\n"

@test_throws Base.UVError getaddrinfo(".invalid")
@test_throws Base.UVError connect("localhost", 21452)
Expand Down

0 comments on commit a36423a

Please sign in to comment.