Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Addrinfo#connect_internal
connect_internal(local_addrinfo, timeout=nil) { |socket| ... }
ext/socket/lib/socket.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/ext/socket/lib/socket.rb, line 54
def connect_internal(local_addrinfo, timeout=nil) # :yields: socket
sock = Socket.new(self.pfamily, self.socktype, self.protocol)
begin
sock.ipv6only! if self.ipv6?
sock.bind local_addrinfo if local_addrinfo
if timeout
case sock.connect_nonblock(self, exception: false)
when 0 # success or EISCONN, other errors raise
break
when :wait_writable
sock.wait_writable(timeout) or
raise Errno::ETIMEDOUT, 'user specified timeout'
end while true
else
sock.connect(self)
end
rescue Exception
sock.close
raise
end
if block_given?
begin
yield sock
ensure
sock.close
end
else
sock
end
end
creates a new Socket connected to the address of local_addrinfo.
If local_addrinfo is nil, the address of the socket is not bound.
The timeout specify the seconds for timeout. Errno::ETIMEDOUT is raised when timeout occur.
If a block is given the created socket is yielded for each address.
See also
#connect_from
#connect_to
#connect
#family_addrinfo
also in
4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0