Skip to content

Commit

Permalink
Merge pull request JuliaLang#14627 from mmaxs/fix-MethodError-for-con…
Browse files Browse the repository at this point in the history
…nect

fix MethodError for connect(addr::Base.InetAddr{T<:Base.IPAddr})
  • Loading branch information
vtjnash committed Jan 19, 2016
2 parents ebdfb5e + 167aeaa commit 7382211
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/socket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ function connect!(sock::TCPSocket, host::IPv6, port::Integer)
sock.status = StatusConnecting
end

connect!(sock::TCPSocket, addr::InetAddr) = connect!(sock, addr.host, addr.port)

# Default Host to localhost
connect(sock::TCPSocket, port::Integer) = connect(sock,IPv4(127,0,0,1),port)
connect(port::Integer) = connect(IPv4(127,0,0,1),port)
Expand Down
30 changes: 30 additions & 0 deletions test/socket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,33 @@ let P = Pipe()
@test !isopen(P)
@test eof(P)
end

# test the method matching connect!(::TCPSocket, ::Base.InetAddr{T<:Base.IPAddr})
let
addr = Base.InetAddr(ip"127.0.0.1", 4444)

function test_connect(addr::Base.InetAddr)
srv = listen(addr)

@async try c = accept(srv); close(c) catch end
yield()

t0 = TCPSocket()
t = t0
@assert is(t,t0)

try
t = connect(addr)
finally
close(srv)
end

test = !is(t,t0)
close(t)

return test
end

@test test_connect(addr)
end

0 comments on commit 7382211

Please sign in to comment.