Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Addrinfo#listen
(::Integer backlog) -> void
listen(backlog=Socket::SOMAXCONN) { |sock| ... }
ext/socket/lib/socket.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/ext/socket/lib/socket.rb, line 212
def listen(backlog=Socket::SOMAXCONN)
sock = Socket.new(self.pfamily, self.socktype, self.protocol)
begin
sock.ipv6only! if self.ipv6?
sock.setsockopt(:SOCKET, :REUSEADDR, 1) unless self.pfamily == Socket::PF_UNIX
sock.bind(self)
sock.listen(backlog)
rescue Exception
sock.close
raise
end
if block_given?
begin
yield sock
ensure
sock.close
end
else
sock
end
end
creates a listening socket bound to self.
See also
#ipv6_v4mapped?
#pfamily
#ipv6_v4compat?
#protocol
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0