mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-05 00:02:38 -04:00
added nonblocking connection, which makes timeouts now much more acurate; force renovation of timeout, as per_operation's first is the connection one (after connection, pass to operation)
This commit is contained in:
parent
e5c183cb98
commit
bd67d3d745
@ -37,12 +37,13 @@ module HTTPX::Channel
|
||||
ctx.alpn_select_cb = lambda do |pr|
|
||||
pr.first unless pr.nil? || pr.empty?
|
||||
end if ctx.respond_to?(:alpn_select_cb=)
|
||||
|
||||
super
|
||||
return if @closed
|
||||
@io = OpenSSL::SSL::SSLSocket.new(@io, ctx)
|
||||
@io.hostname = uri.host
|
||||
@io.sync_close = true
|
||||
@io.connect # TODO: non-block variant missing
|
||||
rescue IO::WaitWritable
|
||||
end
|
||||
|
||||
def perform_io
|
||||
|
@ -1,5 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "ipaddr"
|
||||
require "forwardable"
|
||||
|
||||
module HTTPX::Channel
|
||||
@ -17,9 +18,10 @@ module HTTPX::Channel
|
||||
attr_reader :uri, :remote_ip, :remote_port
|
||||
|
||||
def to_io
|
||||
return @io.to_io if defined?(@io)
|
||||
connect
|
||||
set_processor
|
||||
if @closed
|
||||
connect
|
||||
set_processor unless @closed
|
||||
end
|
||||
@io.to_io
|
||||
end
|
||||
|
||||
@ -32,6 +34,8 @@ module HTTPX::Channel
|
||||
@pending = []
|
||||
@on_response = on_response
|
||||
set_remote_info
|
||||
addr = IPAddr.new(@remote_ip)
|
||||
@io = Socket.new(addr.family, :STREAM, 0)
|
||||
end
|
||||
|
||||
def protocol
|
||||
@ -68,7 +72,8 @@ module HTTPX::Channel
|
||||
end
|
||||
end
|
||||
|
||||
def call
|
||||
def call
|
||||
return if @closed
|
||||
dread
|
||||
dwrite
|
||||
nil
|
||||
@ -135,10 +140,18 @@ module HTTPX::Channel
|
||||
end
|
||||
|
||||
def connect
|
||||
@io = TCPSocket.new(@remote_ip, @remote_port)
|
||||
return unless @closed
|
||||
begin
|
||||
@io.connect_nonblock(Socket.sockaddr_in(@remote_port, @remote_ip))
|
||||
rescue Errno::EISCONN
|
||||
end
|
||||
@options.timeout # force renovation
|
||||
@read_buffer.clear
|
||||
@write_buffer.clear
|
||||
@closed = false
|
||||
rescue Errno::EINPROGRESS,
|
||||
Errno::EALREADY,
|
||||
IO::WaitReadable
|
||||
end
|
||||
|
||||
def set_processor
|
||||
|
Loading…
x
Reference in New Issue
Block a user