mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-10 00:02:10 -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|
|
ctx.alpn_select_cb = lambda do |pr|
|
||||||
pr.first unless pr.nil? || pr.empty?
|
pr.first unless pr.nil? || pr.empty?
|
||||||
end if ctx.respond_to?(:alpn_select_cb=)
|
end if ctx.respond_to?(:alpn_select_cb=)
|
||||||
|
|
||||||
super
|
super
|
||||||
|
return if @closed
|
||||||
@io = OpenSSL::SSL::SSLSocket.new(@io, ctx)
|
@io = OpenSSL::SSL::SSLSocket.new(@io, ctx)
|
||||||
@io.hostname = uri.host
|
@io.hostname = uri.host
|
||||||
@io.sync_close = true
|
@io.sync_close = true
|
||||||
@io.connect # TODO: non-block variant missing
|
@io.connect # TODO: non-block variant missing
|
||||||
|
rescue IO::WaitWritable
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform_io
|
def perform_io
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "ipaddr"
|
||||||
require "forwardable"
|
require "forwardable"
|
||||||
|
|
||||||
module HTTPX::Channel
|
module HTTPX::Channel
|
||||||
@ -17,9 +18,10 @@ module HTTPX::Channel
|
|||||||
attr_reader :uri, :remote_ip, :remote_port
|
attr_reader :uri, :remote_ip, :remote_port
|
||||||
|
|
||||||
def to_io
|
def to_io
|
||||||
return @io.to_io if defined?(@io)
|
if @closed
|
||||||
connect
|
connect
|
||||||
set_processor
|
set_processor unless @closed
|
||||||
|
end
|
||||||
@io.to_io
|
@io.to_io
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -32,6 +34,8 @@ module HTTPX::Channel
|
|||||||
@pending = []
|
@pending = []
|
||||||
@on_response = on_response
|
@on_response = on_response
|
||||||
set_remote_info
|
set_remote_info
|
||||||
|
addr = IPAddr.new(@remote_ip)
|
||||||
|
@io = Socket.new(addr.family, :STREAM, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def protocol
|
def protocol
|
||||||
@ -68,7 +72,8 @@ module HTTPX::Channel
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
|
return if @closed
|
||||||
dread
|
dread
|
||||||
dwrite
|
dwrite
|
||||||
nil
|
nil
|
||||||
@ -135,10 +140,18 @@ module HTTPX::Channel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def connect
|
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
|
@read_buffer.clear
|
||||||
@write_buffer.clear
|
@write_buffer.clear
|
||||||
@closed = false
|
@closed = false
|
||||||
|
rescue Errno::EINPROGRESS,
|
||||||
|
Errno::EALREADY,
|
||||||
|
IO::WaitReadable
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_processor
|
def set_processor
|
||||||
|
Loading…
x
Reference in New Issue
Block a user