mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-08 00:02:42 -04:00
io: #build_socket as factory; re-building it in connect if closed (for when the server closes the socket)
This commit is contained in:
parent
f68f338e53
commit
d5b981a0bb
@ -15,7 +15,6 @@ module HTTPX
|
|||||||
@uri = uri
|
@uri = uri
|
||||||
@ip = TCPSocket.getaddress(@uri.host)
|
@ip = TCPSocket.getaddress(@uri.host)
|
||||||
@port = @uri.port
|
@port = @uri.port
|
||||||
addr = IPAddr.new(@ip)
|
|
||||||
if options.io
|
if options.io
|
||||||
@io = case options.io
|
@io = case options.io
|
||||||
when Hash
|
when Hash
|
||||||
@ -25,7 +24,7 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
@keep_open = !@io.nil?
|
@keep_open = !@io.nil?
|
||||||
end
|
end
|
||||||
@io ||= Socket.new(addr.family, :STREAM, 0)
|
@io ||= build_socket
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_io
|
def to_io
|
||||||
@ -39,10 +38,12 @@ module HTTPX
|
|||||||
def connect
|
def connect
|
||||||
return if @connected || @keep_open
|
return if @connected || @keep_open
|
||||||
begin
|
begin
|
||||||
|
@io = build_socket if @io.closed?
|
||||||
@io.connect_nonblock(Socket.sockaddr_in(@port, @ip))
|
@io.connect_nonblock(Socket.sockaddr_in(@port, @ip))
|
||||||
rescue Errno::EISCONN
|
rescue Errno::EISCONN
|
||||||
end
|
end
|
||||||
@connected = true
|
@connected = true
|
||||||
|
log { "connected" }
|
||||||
|
|
||||||
rescue Errno::EINPROGRESS,
|
rescue Errno::EINPROGRESS,
|
||||||
Errno::EALREADY,
|
Errno::EALREADY,
|
||||||
@ -95,6 +96,18 @@ module HTTPX
|
|||||||
def closed?
|
def closed?
|
||||||
!@keep_open && !@connected
|
!@keep_open && !@connected
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def build_socket
|
||||||
|
addr = IPAddr.new(@ip)
|
||||||
|
Socket.new(addr.family, :STREAM, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
def log(&msg)
|
||||||
|
return unless $HTTPX_DEBUG
|
||||||
|
$stderr << (+"io: " << msg.call << "\n")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class SSL < TCP
|
class SSL < TCP
|
||||||
|
Loading…
x
Reference in New Issue
Block a user