mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-12-08 00:00:58 -05:00
63 lines
1.3 KiB
Ruby
63 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "forwardable"
|
|
|
|
module HTTPX
|
|
class UNIX < TCP
|
|
extend Forwardable
|
|
|
|
def_delegator :@uri, :port, :scheme
|
|
|
|
# rubocop:disable Lint/MissingSuper
|
|
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
|
|
# rubocop:enable Lint/MissingSuper
|
|
|
|
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
|