TCPSocket.new supports "local_host" and "local_service".
@@ -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
