class Async::Socket
def self.connect(remote_address, local_address = nil, protocol: 0, task: Task.current)
(**protcol)
-
The
(Integer
) -- socket protocol to use.
Parameters:
-
local_address
(Addrinfo
) -- The local address to bind to before connecting. -
remote_address
(Addrinfo
) -- The remote address to connect to.
def self.connect(remote_address, local_address = nil, protocol: 0, task: Task.current) socket = ::Socket.new(remote_address.afamily, remote_address.socktype, protocol) if local_address socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, true) socket.bind(local_address) if local_address end if block_given? task.with(socket) do |wrapper| wrapper.connect(remote_address.to_sockaddr) yield wrapper end else task.bind(socket).connect(remote_address.to_sockaddr) return socket end end