Skip to content

Commit fd74cb3

Browse files
connect, getaddrinfo: generalize for all kinds of strings [#4002].
1 parent 37c2ae3 commit fd74cb3

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

base/socket.jl

+5-3
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,12 @@ function _uv_hook_getaddrinfo(cb::Function, addrinfo::Ptr{Void}, status::Int32)
389389
ccall(:uv_freeaddrinfo,Void,(Ptr{Void},),freeaddrinfo)
390390
end
391391

392-
function getaddrinfo(cb::Function,host::ASCIIString)
392+
function getaddrinfo(cb::Function, host::ASCIIString)
393393
callback_dict[cb] = cb
394394
uv_error("getaddrinfo",ccall(:jl_getaddrinfo, Int32, (Ptr{Void}, Ptr{Uint8}, Ptr{Uint8}, Any),
395395
eventloop(), host, C_NULL, cb))
396396
end
397+
getaddrinfo(cb::Function, host::String) = getaddrinfo(cb,ascii(host))
397398

398399
function getaddrinfo(host::ASCIIString)
399400
c = Condition()
@@ -404,6 +405,7 @@ function getaddrinfo(host::ASCIIString)
404405
isa(ip,UVError) && throw(ip)
405406
return ip::IpAddr
406407
end
408+
getaddrinfo(host::String) = getaddrinfo(ascii(host))
407409

408410
const _sizeof_uv_interface_address = ccall(:jl_uv_sizeof_interface_address,Int32,())
409411

@@ -462,13 +464,13 @@ connect(sock::TcpSocket, port::Integer) = connect(sock,IPv4(127,0,0,1),port)
462464
connect(port::Integer) = connect(IPv4(127,0,0,1),port)
463465

464466
# Valid connect signatures for TCP
465-
connect(host::ASCIIString, port::Integer) = connect(TcpSocket(),host,port)
467+
connect(host::String, port::Integer) = connect(TcpSocket(),host,port)
466468
connect(addr::IpAddr, port::Integer) = connect(TcpSocket(),addr,port)
467469
connect(addr::InetAddr) = connect(TcpSocket(),addr)
468470

469471
default_connectcb(sock,status) = nothing
470472

471-
function connect!(sock::TcpSocket, host::ASCIIString, port::Integer)
473+
function connect!(sock::TcpSocket, host::String, port::Integer)
472474
@assert sock.status == StatusInit
473475
ipaddr = getaddrinfo(host)
474476
sock.status = StatusInit

base/stream.jl

+4-3
Original file line numberDiff line numberDiff line change
@@ -828,13 +828,14 @@ function listen(path::ByteString)
828828
sock
829829
end
830830

831-
function connect!(sock::Pipe,path::ByteString)
831+
function connect!(sock::Pipe, path::ByteString)
832832
@assert sock.status == StatusInit
833833
req = c_malloc(_sizeof_uv_connect)
834834
ccall(:uv_pipe_connect, Void, (Ptr{Void}, Ptr{Void}, Ptr{Uint8}, Ptr{Void}), req, sock.handle, path, uv_jl_connectcb::Ptr{Void})
835835
sock.status = StatusConnecting
836836
sock
837837
end
838+
connect!(sock::Pipe, path::String) = connect(sock,bytestring(path))
838839

839840
function connect(cb::Function,sock::AsyncStream,args...)
840841
sock.ccb = cb
@@ -852,6 +853,8 @@ function connect(sock::AsyncStream, args...)
852853
sock
853854
end
854855

856+
connect(path::String) = connect(Pipe(),path)
857+
855858
dup(x::RawFD) = RawFD(ccall((@windows? :_dup : :dup),Int32,(Int32,),x.fd))
856859
dup(src::RawFD,target::RawFD) = systemerror("dup",ccall((@windows? :_dup2 : :dup2),Int32,(Int32,Int32),src.fd,target.fd) == -1)
857860

@@ -875,5 +878,3 @@ for (x,writable,unix_fd,c_symbol) in ((:STDIN,false,0,:jl_uv_stdin),(:STDOUT,tru
875878
end
876879
end
877880
end
878-
879-
connect(path::ByteString) = connect(Pipe(),path)

0 commit comments

Comments
 (0)