Class: RaptorIO::Socket::Comm
- Inherits:
-
Object
- Object
- RaptorIO::Socket::Comm
- Defined in:
- lib/raptor-io/socket/comm.rb
Overview
Provides the basic interface that a derived class must implement in order to be a routable socket creator.
See Local for an implementation using sockets created with standard Ruby Socket classes.
Subclasses must implement the following methods:
* `resolve`
* `create_tcp`
* `create_tcp_server`
* `create_udp`
* `create_udp_server`
* `support_ipv6?`
Defined Under Namespace
Class Method Summary collapse
Instance Method Summary collapse
-
#create(options) ⇒ RaptorIO::Socket
Creates a socket on this Comm based on the supplied uniform parameters.
-
#create_tcp(options) ⇒ RaptorIO::Socket::TCP
abstract
Connect to a host over TCP.
-
#create_tcp_server(options) ⇒ Object
abstract
Create a TCP server listening on :local_port.
-
#create_udp(options) ⇒ Object
abstract
Create a UDP socket bound to the given :peer_host.
-
#create_udp_server(options) ⇒ Object
abstract
Create a UDP server listening on :local_port.
-
#resolve(hostname) ⇒ Object
abstract
Resolves a hostname to an IP address using this comm.
-
#reverse_resolve(ip_address) ⇒ Object
abstract
Resolves an IP address to a hostname using this comm.
Class Method Details
.from_uri(uri, opts = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/raptor-io/socket/comm.rb', line 29 def self.from_uri(uri, opts = {}) raise ArgumentError unless uri.kind_of? URI prev_comm = opts[:prev_comm] || RaptorIO::Socket::Comm::Local.new comm = case uri.scheme.downcase when "sapni" uri.port ||= 3299 RaptorIO::Socket::Comm::SAPNI.new( sap_host: uri.host, sap_port: uri.port, sap_comm: prev_comm, ) when "socks" uri.port ||= 1080 RaptorIO::Socket::Comm::SOCKS.new( socks_host: uri.host, socks_port: uri.port, socks_comm: prev_comm, ) end comm end |
Instance Method Details
#create(options) ⇒ RaptorIO::Socket
Creates a socket on this Comm based on the supplied uniform parameters.
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/raptor-io/socket/comm.rb', line 64 def create( ) = .dup [:peer_host] = IPAddr.parse([:peer_host]) case .delete(:protocol) when :tcp [:server] ? create_tcp_server() : create_tcp() when :udp [:server] ? create_udp_server() : create_udp() end end |
#create_tcp(options) ⇒ RaptorIO::Socket::TCP
Connect to a host over TCP.
104 105 106 |
# File 'lib/raptor-io/socket/comm.rb', line 104 def create_tcp() raise NotImplementedError end |
#create_tcp_server(options) ⇒ Object
Create a TCP server listening on :local_port
127 128 129 |
# File 'lib/raptor-io/socket/comm.rb', line 127 def create_tcp_server() raise NotImplementedError end |
#create_udp(options) ⇒ Object
Create a UDP socket bound to the given :peer_host
116 117 118 |
# File 'lib/raptor-io/socket/comm.rb', line 116 def create_udp() raise NotImplementedError end |
#create_udp_server(options) ⇒ Object
Create a UDP server listening on :local_port
137 138 139 |
# File 'lib/raptor-io/socket/comm.rb', line 137 def create_udp_server() raise NotImplementedError end |
#resolve(hostname) ⇒ Object
Resolves a hostname to an IP address using this comm.
82 83 84 |
# File 'lib/raptor-io/socket/comm.rb', line 82 def resolve( hostname ) raise NotImplementedError end |
#reverse_resolve(ip_address) ⇒ Object
Resolves an IP address to a hostname using this comm.
91 92 93 |
# File 'lib/raptor-io/socket/comm.rb', line 91 def reverse_resolve( ip_address ) raise NotImplementedError end |