# Copyright (C) 2014-2015 MongoDB, Inc. # # Licensed under the Apache License, Version 2.0 (the 'License'); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an 'AS IS' BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. module Mongo class Address # Sets up socket addresses. # # @since 2.0.0 class Unix # @return [ String ] host The original host name. attr_reader :host # @return [ nil ] port Will always be nil. attr_reader :port # @return [ String ] seed The seed address. attr_reader :seed # The regular expression to use to match a socket path. # # @since 2.0.0 MATCH = Regexp.new('\.sock').freeze # Initialize the socket resolver. # # @example Initialize the resolver. # Sock.new("/path/to/socket.sock") # # @param [ String ] address The socket path. # # @since 2.0.0 def initialize(address) @host = address @seed = address end # Get a socket for the provided address type, given the options. # # @example Get a Unix socket. # ipv4.socket(5) # # @param [ Float ] timeout The socket timeout. # @param [ Hash ] ssl_options SSL options - ignored. # # @return [ Pool::Socket::Unix ] The socket. # # @since 2.0.0 def socket(timeout, ssl_options = {}) Socket::Unix.new(host, timeout, Socket::AF_UNIX) end # Get the address as a string. # # @example Get the address as a string. # ipv4.to_s # # @return [ String ] The nice string. # # @since 2.0.0 alias :to_s :host end end end