TCPSocket.new supports "local_host" and "local_service".

This commit is contained in:
Tomoyuki Sahara
2017-02-08 19:04:11 +09:00
parent b2a0c9c6bf
commit 3dad125a1c
+6
View File
@@ -236,6 +236,12 @@ class TCPSocket
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