Class: Mongo::Address::IPv6
- Inherits:
-
Object
- Object
- Mongo::Address::IPv6
- Defined in:
- build/ruby-driver-v2.19/lib/mongo/address/ipv6.rb
Overview
Sets up resolution with IPv6 support if the address is an ip address.
Constant Summary collapse
- MATCH =
The regular expression to use to match an IPv6 ip address.
Regexp.new('::').freeze
Instance Attribute Summary collapse
-
#host ⇒ String
readonly
Host The host.
-
#host_name ⇒ String
readonly
Host_name The original host name.
-
#port ⇒ Integer
readonly
Port The port.
Class Method Summary collapse
-
.parse(address) ⇒ Array<String, Integer>
Parse an IPv6 address into its host and port.
Instance Method Summary collapse
-
#initialize(host, port, host_name = nil) ⇒ IPv6
constructor
Initialize the IPv6 resolver.
-
#socket(socket_timeout, options = {}) ⇒ Mongo::Socket::SSL, Mongo::Socket::TCP
private
Get a socket for the provided address type, given the options.
Constructor Details
#initialize(host, port, host_name = nil) ⇒ IPv6
Initialize the IPv6 resolver.
86 87 88 89 90 |
# File 'build/ruby-driver-v2.19/lib/mongo/address/ipv6.rb', line 86 def initialize(host, port, host_name=nil) @host = host @port = port @host_name = host_name end |
Instance Attribute Details
#host ⇒ String (readonly)
Returns host The host.
28 29 30 |
# File 'build/ruby-driver-v2.19/lib/mongo/address/ipv6.rb', line 28 def host @host end |
#host_name ⇒ String (readonly)
Returns host_name The original host name.
31 32 33 |
# File 'build/ruby-driver-v2.19/lib/mongo/address/ipv6.rb', line 31 def host_name @host_name end |
#port ⇒ Integer (readonly)
Returns port The port.
34 35 36 |
# File 'build/ruby-driver-v2.19/lib/mongo/address/ipv6.rb', line 34 def port @port end |
Class Method Details
.parse(address) ⇒ Array<String, Integer>
Parse an IPv6 address into its host and port.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'build/ruby-driver-v2.19/lib/mongo/address/ipv6.rb', line 51 def self.parse(address) # IPAddr's parser handles IP address only, not port. # Therefore we need to handle the port ourselves if address =~ /[\[\]]/ parts = address.match(/\A\[(.+)\](?::(\d+))?\z/) if parts.nil? raise ArgumentError, "Invalid IPv6 address: #{address}" end host = parts[1] port = (parts[2] || 27017).to_i else host = address port = 27017 end # Validate host. # This will raise IPAddr::InvalidAddressError # on newer rubies which is a subclass of ArgumentError # if host is invalid begin IPAddr.new(host) rescue ArgumentError raise ArgumentError, "Invalid IPv6 address: #{address}" end [ host, port ] end |
Instance Method Details
#socket(socket_timeout, options = {}) ⇒ Mongo::Socket::SSL, Mongo::Socket::TCP
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get a socket for the provided address type, given the options.
133 134 135 136 137 138 139 |
# File 'build/ruby-driver-v2.19/lib/mongo/address/ipv6.rb', line 133 def socket(socket_timeout, = {}) if [:ssl] Socket::SSL.new(host, port, host_name, socket_timeout, Socket::PF_INET6, ) else Socket::TCP.new(host, port, socket_timeout, Socket::PF_INET6, ) end end |