def initialize(host, service, local_host=nil, local_service=nil)
if @init_with_fd
super(host, service)
else
s = nil
e = SocketError
Addrinfo.foreach(host, service) { |ai|
begin
s = Socket._socket(ai.afamily, Socket::SOCK_STREAM, 0)
if local_host or local_service
local_host ||= (ai.afamily == Socket::AF_INET) ? "0.0.0.0" : "::"
local_service ||= "0"
bi = Addrinfo.getaddrinfo(local_host, local_service, ai.afamily, ai.socktype)[0]
Socket._bind(s, bi.to_sockaddr)
end
Socket._connect(s, ai.to_sockaddr)
super(s, "r+")
return
rescue => e0
e = e0
end
}
raise e
end
end