Class: Rev::TCPSocket
- Defined in:
- lib/rev/socket.rb
Defined Under Namespace
Classes: TCPConnectResolver, TCPConnectSocket
Instance Attribute Summary collapse
-
#address_family ⇒ Object
readonly
Returns the value of attribute address_family.
-
#remote_addr ⇒ Object
readonly
Returns the value of attribute remote_addr.
-
#remote_host ⇒ Object
readonly
Returns the value of attribute remote_host.
-
#remote_port ⇒ Object
readonly
Returns the value of attribute remote_port.
Class Method Summary collapse
-
.connect(addr, port, *args) ⇒ Object
Perform a non-blocking connect to the given host and port.
Instance Method Summary collapse
-
#initialize(socket) ⇒ TCPSocket
constructor
A new instance of TCPSocket.
Methods inherited from Socket
#attach, #on_connect, #on_connect_failed
Methods inherited from BufferedIO
#close, #on_close, #on_read, #on_write_complete, #output_buffer_size, #write, #write_output_buffer
Methods inherited from IOWatcher
#attach, #detach, #disable, #enable, #on_readable, #on_writable
Methods inherited from Watcher
#attach, #attached?, #detach, #disable, #enable, event_callback, #evloop, watcher_delegate
Constructor Details
#initialize(socket) ⇒ TCPSocket
Returns a new instance of TCPSocket.
103 104 105 106 107 108 109 110 111 |
# File 'lib/rev/socket.rb', line 103 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 end |
Instance Attribute Details
#address_family ⇒ Object (readonly)
Returns the value of attribute address_family.
76 77 78 |
# File 'lib/rev/socket.rb', line 76 def address_family @address_family end |
#remote_addr ⇒ Object (readonly)
Returns the value of attribute remote_addr.
76 77 78 |
# File 'lib/rev/socket.rb', line 76 def remote_addr @remote_addr end |
#remote_host ⇒ Object (readonly)
Returns the value of attribute remote_host.
76 77 78 |
# File 'lib/rev/socket.rb', line 76 def remote_host @remote_host end |
#remote_port ⇒ Object (readonly)
Returns the value of attribute remote_port.
76 77 78 |
# File 'lib/rev/socket.rb', line 76 def remote_port @remote_port end |
Class Method Details
.connect(addr, port, *args) ⇒ Object
Perform a non-blocking connect to the given host and port
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rev/socket.rb', line 80 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) end if host = Rev::DNSResolver.hosts(addr) return connect(host, port, *args) end return allocate.instance_eval { @remote_host, @remote_addr, @remote_port = addr, addr, port @resolver = TCPConnectResolver.new(self, addr, port, *args) } end |