class IO::Endpoint::Wrapper

def build(*arguments, timeout: nil, reuse_address: true, reuse_port: nil, linger: nil)

Options Hash: (**reuse_address)
  • Allow (Boolean) -- this port to be bound in multiple processes.
  • Allow (Boolean) -- this port to be bound in multiple processes.
def build(*arguments, timeout: nil, reuse_address: true, reuse_port: nil, linger: nil)
	socket = ::Socket.new(*arguments)
	
	# Set the timeout:
	if timeout
		set_timeout(socket, timeout)
	end
	
	if reuse_address
		socket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
	end
	
	if reuse_port
		socket.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1)
	end
	
	if linger
		socket.setsockopt(SOL_SOCKET, SO_LINGER, linger)
	end
	
	yield socket if block_given?
	
	return socket
rescue
	socket&.close
end