Class: HTTPX::UNIX

Inherits:
TCP
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/httpx/io/unix.rb

Constant Summary

Constants included from Loggable

Loggable::COLORS

Instance Attribute Summary collapse

Attributes inherited from TCP

#addresses, #interests, #ip, #port, #state

Instance Method Summary collapse

Methods inherited from TCP

#close, #closed?, #connected?, #protocol, #read, #to_io, #write

Methods included from Loggable

#log, #log_exception

Constructor Details

#initialize(origin, addresses, options) ⇒ UNIX

Returns a new instance of UNIX.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/httpx/io/unix.rb', line 15

def initialize(origin, addresses, options)
  @addresses = addresses
  @hostname = origin.host
  @state = :idle
  @options = Options.new(options)
  @fallback_protocol = @options.fallback_protocol
  if @options.io
    @io = case @options.io
          when Hash
            @options.io[origin.authority]
          else
            @options.io
    end
    raise Error, "Given IO objects do not match the request authority" unless @io

    @path = @io.path
    @keep_open = true
    @state = :connected
  else
    if @options.transport_options
      # :nocov:
      warn ":#{__method__} is deprecated, use :addresses instead"
      @path = @options.transport_options[:path]
      # :nocov:
    else
      @path = addresses.first
    end
  end
  @io ||= build_socket
end

Instance Attribute Details

#pathObject (readonly) Also known as: host

Returns the value of attribute path.



11
12
13
# File 'lib/httpx/io/unix.rb', line 11

def path
  @path
end

Instance Method Details

#connectObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/httpx/io/unix.rb', line 46

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

#inspectObject

:nocov:



64
65
66
# File 'lib/httpx/io/unix.rb', line 64

def inspect
  "#<#{self.class}(path: #{@path}): (state: #{@state})>"
end