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:
HoneyryderChuck 2017-11-29 21:26:47 +00:00
parent e5c183cb98
commit bd67d3d745
2 changed files with 20 additions and 6 deletions

View File

@ -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

View File

@ -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