Sha256: 257b521500601abaea9ee03c12e687d96fb6d8ac39f8da7740bd5231a7883bc2

Contents?: true

Size: 1.19 KB

Versions: 25

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require "forwardable"

module HTTPX
  class UNIX < TCP
    extend Forwardable

    def_delegator :@uri, :port, :scheme

    def initialize(uri, addresses, options)
      @uri = uri
      @addresses = addresses
      @state = :idle
      @options = Options.new(options)
      @path = @options.transport_options[:path]
      @fallback_protocol = @options.fallback_protocol
      if @options.io
        @io = case @options.io
              when Hash
                @options.io[@path]
              else
                @options.io
        end
        unless @io.nil?
          @keep_open = true
          @state = :connected
        end
      end
      @io ||= build_socket
    end

    def hostname
      @uri.host
    end

    def connect
      return unless closed?

      begin
        if @io.closed?
          transition(:idle)
          @io = build_socket
        end
        @io.connect_nonblock(Socket.sockaddr_un(@path))
      rescue Errno::EISCONN
      end
      transition(:connected)
    rescue Errno::EINPROGRESS,
           Errno::EALREADY,
           ::IO::WaitReadable
    end

    private

    def build_socket
      Socket.new(Socket::PF_UNIX, :STREAM, 0)
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
httpx-0.12.0 lib/httpx/io/unix.rb
httpx-0.11.3 lib/httpx/io/unix.rb
httpx-0.11.2 lib/httpx/io/unix.rb
httpx-0.11.1 lib/httpx/io/unix.rb
httpx-0.11.0 lib/httpx/io/unix.rb
httpx-0.10.2 lib/httpx/io/unix.rb
httpx-0.10.1 lib/httpx/io/unix.rb
httpx-0.10.0 lib/httpx/io/unix.rb
httpx-0.9.0 lib/httpx/io/unix.rb
httpx-0.8.2 lib/httpx/io/unix.rb
httpx-0.8.1 lib/httpx/io/unix.rb
httpx-0.8.0 lib/httpx/io/unix.rb
httpx-0.7.0 lib/httpx/io/unix.rb
httpx-0.6.7 lib/httpx/io/unix.rb
httpx-0.6.6 lib/httpx/io/unix.rb
httpx-0.6.5 lib/httpx/io/unix.rb
httpx-0.6.4 lib/httpx/io/unix.rb
httpx-0.6.3 lib/httpx/io/unix.rb
httpx-0.6.2 lib/httpx/io/unix.rb
httpx-0.6.1 lib/httpx/io/unix.rb