lib/httpx/io.rb in httpx-0.0.2 vs lib/httpx/io.rb in httpx-0.0.3
- old
+ new
@@ -173,22 +173,31 @@
# connect only works if initial @io is a socket
@io = @io.io if @io.respond_to?(:io)
@negotiated = false
end
+ def connected?
+ @state == :negotiated
+ end
+
def connect
super
if @keep_open
@state = :negotiated
return
end
return if @state == :negotiated ||
@state != :connected
- @io = OpenSSL::SSL::SSLSocket.new(@io, @ctx)
- @io.hostname = @hostname
- @io.sync_close = true
- @io.connect
+ unless @io.is_a?(OpenSSL::SSL::SSLSocket)
+ @io = OpenSSL::SSL::SSLSocket.new(@io, @ctx)
+ @io.hostname = @hostname
+ @io.sync_close = true
+ end
+ # TODO: this might block it all
+ @io.connect_nonblock
transition(:negotiated)
+ rescue ::IO::WaitReadable,
+ ::IO::WaitWritable
end
if RUBY_VERSION < "2.3"
def read(*)
super