class Coolio::TCPSocket
Constants
- PEERADDR_FAILED
Attributes
address_family[R]
remote_addr[R]
remote_host[R]
remote_port[R]
Public Class Methods
connect(addr, port, *args)
click to toggle source
Perform a non-blocking connect to the given host and port see examples/echo_client.rb addr is a string, can be an IP address or a hostname.
Calls superclass method
Coolio::Socket.connect
# File lib/cool.io/socket.rb, line 111 def self.connect(addr, port, *args) family = nil if (Resolv::IPv4.create(addr) rescue nil) family = ::Socket::AF_INET elsif(Resolv::IPv6.create(addr) rescue nil) family = ::Socket::AF_INET6 end if family return super(TCPConnectSocket.new(family, addr, port), *args) # this creates a 'real' write buffer so we're ok there with regards to already having a write buffer from the get go end if host = Coolio::DNSResolver.hosts(addr) return connect(host, port, *args) # calls this same function end precreate(addr, port, *args) end
new(socket)
click to toggle source
Calls superclass method
Coolio::Socket.new
# File lib/cool.io/socket.rb, line 142 def initialize(socket) unless socket.is_a?(::TCPSocket) or socket.is_a?(TCPConnectSocket) raise TypeError, "socket must be a TCPSocket" end super @address_family, @remote_port, @remote_host, @remote_addr = (socket.peeraddr rescue PEERADDR_FAILED) end
precreate(*args, &block)
click to toggle source
Similar to .new, but used in cases where the resulting object is in a “half-open” state. This is primarily used for when asynchronous DNS resolution is taking place. We don't actually have a handle to the socket we want to use to create the watcher yet, since we don't know the IP address to connect to.
# File lib/cool.io/socket.rb, line 102 def self.precreate(*args, &block) obj = allocate obj.__send__(:preinitialize, *args, &block) obj end
Public Instance Methods
peeraddr()
click to toggle source
# File lib/cool.io/socket.rb, line 152 def peeraddr [@address_family, @remote_port, @remote_host, @remote_addr] end
Private Instance Methods
preinitialize(addr, port, *args)
click to toggle source
Called by precreate during asyncronous DNS resolution
# File lib/cool.io/socket.rb, line 132 def preinitialize(addr, port, *args) @_write_buffer = ::IO::Buffer.new # allow for writing BEFORE DNS has resolved @remote_host, @remote_addr, @remote_port = addr, addr, port @_resolver = TCPConnectResolver.new(self, addr, port, *args) end