Sha256: 676db3f072950b8f8fac8ec3ea440d72ae1a5ba19b38fff48fa98b6ff7886a91
Contents?: true
Size: 1.72 KB
Versions: 5
Compression:
Stored size: 1.72 KB
Contents
require "forwardable" module HTTP module Timeout class Null extend Forwardable def_delegators :@socket, :close, :closed? attr_reader :options, :socket def initialize(options = {}) @options = options end # Connects to a socket def connect(socket_class, host, port) @socket = socket_class.open(host, port) end # Starts a SSL connection on a socket def connect_ssl @socket.connect end # Configures the SSL connection and starts the connection def start_tls(host, ssl_socket_class, ssl_context) @socket = ssl_socket_class.new(socket, ssl_context) @socket.hostname = host if @socket.respond_to? :hostname= @socket.sync_close = true if @socket.respond_to? :sync_close= connect_ssl return unless ssl_context.verify_mode == OpenSSL::SSL::VERIFY_PEER @socket.post_connection_check(host) end # Read from the socket def readpartial(size) @socket.readpartial(size) end # Write to the socket def write(data) @socket << data end alias_method :<<, :write private # Retry reading def rescue_readable yield rescue IO::WaitReadable if IO.select([socket], nil, nil, read_timeout) retry else raise TimeoutError, "Read timed out after #{read_timeout} seconds" end end # Retry writing def rescue_writable yield rescue IO::WaitWritable if IO.select(nil, [socket], nil, write_timeout) retry else raise TimeoutError, "Write timed out after #{write_timeout} seconds" end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
http-0.9.3 | lib/http/timeout/null.rb |
http-0.9.2 | lib/http/timeout/null.rb |
http-0.9.1 | lib/http/timeout/null.rb |
http-0.9.0 | lib/http/timeout/null.rb |
http-0.9.0.pre | lib/http/timeout/null.rb |