class RaptorIO::Socket::Comm::Local
Local
communication using Ruby ‘::Socket`s
Public Instance Methods
create_tcp( options )
click to toggle source
Connect to ‘:peer_host`
@option (see Comm#create_tcp) @return [Socket::TCP] @raise [RaptorIO::Socket::Error::ConnectTimeout]
# File lib/raptor-io/socket/comm/local.rb, line 47 def create_tcp( options ) phost = IPAddr.parse( options[:peer_host] ) # Passing an explicit ::Socket::IPPROTO_TCP is broken on jruby # See https://github.com/jruby/jruby/issues/785 socket = ::Socket.new(phost.family, ::Socket::SOCK_STREAM, 0) socket.do_not_reverse_lookup = true if options[:local_port] || options[:local_host] socket.bind(::Socket.pack_sockaddr_in(options[:local_port], options[:local_host])) end begin socket.connect_nonblock(::Socket.pack_sockaddr_in(options[:peer_port], phost.to_s)) rescue Errno::ECONNREFUSED, Errno::ECONNRESET raise RaptorIO::Socket::Error::ConnectionRefused rescue Errno::EINPROGRESS # This should almost always be raised with a call to # connect_nonblock. When the socket finishes connecting it # becomes available for writing. res = select(nil, [socket], nil, options[:connect_timeout] || 2) if res.nil? raise RaptorIO::Socket::Error::ConnectionTimeout end end if options[:ssl_context] RaptorIO::Socket::TCP::SSL.new(socket, options) else RaptorIO::Socket::TCP.new(socket, options) end end
create_tcp_server( options )
click to toggle source
Listen locally on ‘:local_port`
@option (see Comm#create_tcp_server)
# File lib/raptor-io/socket/comm/local.rb, line 83 def create_tcp_server( options ) socket = TCPServer.new( options[:local_host], options[:local_port] ) if (options[:context] = options.delete(:ssl_context)) RaptorIO::Socket::TCPServer::SSL.new( socket, options ) else RaptorIO::Socket::TCPServer.new( socket, options ) end end
resolve( hostname )
click to toggle source
Resolves a hostname to an IP address using this comm.
@param hostname [String]
# File lib/raptor-io/socket/comm/local.rb, line 31 def resolve( hostname ) ::Resolv.getaddress hostname end
reverse_resolve( ip_address )
click to toggle source
Resolves an IP address to a hostname using this comm.
@param [String] ip_address
# File lib/raptor-io/socket/comm/local.rb, line 38 def reverse_resolve( ip_address ) ::Resolv.getname ip_address end
support_ipv6?()
click to toggle source
Determine whether we support IPv6
We attempt to discover this by creating an unbound UDP socket with the AF_INET6 address family
# File lib/raptor-io/socket/comm/local.rb, line 12 def support_ipv6? return @supports_ipv6 unless @supports_ipv6.nil? @supports_ipv6 = false if ::Socket.const_defined?('AF_INET6') begin ::Socket.new(::Socket::AF_INET6, ::Socket::SOCK_DGRAM, ::Socket::IPPROTO_UDP).close @supports_ipv6 = true rescue end end @supports_ipv6 end