From d827859991779995d61455bd709cd6529b3e4e29 Mon Sep 17 00:00:00 2001 From: Alexey Zapparov Date: Fri, 18 Mar 2016 17:24:24 +0100 Subject: [PATCH] Remove Ruby < 2 support --- .travis.yml | 3 +-- README.md | 4 +-- lib/http/timeout/global.rb | 39 ++++++++--------------------- lib/http/timeout/null.rb | 50 +++++++++++--------------------------- 4 files changed, 26 insertions(+), 70 deletions(-) diff --git a/.travis.yml b/.travis.yml index dc05e0df..6ea1dd21 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,12 +4,11 @@ env: - JRUBY_OPTS="$JRUBY_OPTS --debug" language: ruby rvm: - - 1.9.3 - 2.0.0 - 2.1 - 2.2 - 2.3.0 - - jruby + - jruby-9.0.5.0 - jruby-head - ruby-head - rbx-2 diff --git a/README.md b/README.md index e8725d2d..7b1bd62c 100644 --- a/README.md +++ b/README.md @@ -151,13 +151,11 @@ In practice you'll want to bind the HTTP::Response::Body to a local variable (e. This library aims to support and is [tested against][travis] the following Ruby versions: -* Ruby 1.9.3 * Ruby 2.0.0 * Ruby 2.1.x * Ruby 2.2.x * Ruby 2.3.x -* JRuby 1.7.x -* JRuby 9000+ +* JRuby 9.0.5.0 If something doesn't work on one of these versions, it's a bug. diff --git a/lib/http/timeout/global.rb b/lib/http/timeout/global.rb index 55f417bc..342a67af 100644 --- a/lib/http/timeout/global.rb +++ b/lib/http/timeout/global.rb @@ -1,4 +1,5 @@ require "timeout" +require "io/wait" require "http/timeout/per_operation" @@ -59,7 +60,6 @@ def write(data) private if RUBY_VERSION < "2.1.0" - def read_nonblock(size) @socket.read_nonblock(size) end @@ -67,9 +67,7 @@ def read_nonblock(size) def write_nonblock(data) @socket.write_nonblock(data) end - else - def read_nonblock(size) @socket.read_nonblock(size, :exception => false) end @@ -77,7 +75,6 @@ def read_nonblock(size) def write_nonblock(data) @socket.write_nonblock(data, :exception => false) end - end # Perform the given I/O operation with the given argument @@ -104,32 +101,16 @@ def perform_io :eof end - if RUBY_VERSION < "2.0.0" - # Wait for a socket to become readable - def wait_readable_or_timeout - IO.select([@socket], nil, nil, time_left) - log_time - end - - # Wait for a socket to become writable - def wait_writable_or_timeout - IO.select(nil, [@socket], nil, time_left) - log_time - end - else - require "io/wait" - - # Wait for a socket to become readable - def wait_readable_or_timeout - @socket.to_io.wait_readable(time_left) - log_time - end + # Wait for a socket to become readable + def wait_readable_or_timeout + @socket.to_io.wait_readable(time_left) + log_time + end - # Wait for a socket to become writable - def wait_writable_or_timeout - @socket.to_io.wait_writable(time_left) - log_time - end + # Wait for a socket to become writable + def wait_writable_or_timeout + @socket.to_io.wait_writable(time_left) + log_time end # Due to the run/retry nature of nonblocking I/O, it's easier to keep track of time diff --git a/lib/http/timeout/null.rb b/lib/http/timeout/null.rb index 23f7ce81..5167251c 100644 --- a/lib/http/timeout/null.rb +++ b/lib/http/timeout/null.rb @@ -1,4 +1,5 @@ require "forwardable" +require "io/wait" module HTTP module Timeout @@ -50,45 +51,22 @@ def write(data) end alias << write - # These cops can be re-eanbled after we go Ruby 2.0+ only - # rubocop:disable Lint/UselessAccessModifier, Metrics/BlockNesting - private - if RUBY_VERSION < "2.0.0" - # Retry reading - def rescue_readable - yield - rescue IO::WaitReadable - retry if IO.select([@socket], nil, nil, read_timeout) - raise TimeoutError, "Read timed out after #{read_timeout} seconds" - end - - # Retry writing - def rescue_writable - yield - rescue IO::WaitWritable - retry if IO.select(nil, [@socket], nil, write_timeout) - raise TimeoutError, "Write timed out after #{write_timeout} seconds" - end - else - require "io/wait" - - # Retry reading - def rescue_readable - yield - rescue IO::WaitReadable - retry if @socket.to_io.wait_readable(read_timeout) - raise TimeoutError, "Read timed out after #{read_timeout} seconds" - end + # Retry reading + def rescue_readable + yield + rescue IO::WaitReadable + retry if @socket.to_io.wait_readable(read_timeout) + raise TimeoutError, "Read timed out after #{read_timeout} seconds" + end - # Retry writing - def rescue_writable - yield - rescue IO::WaitWritable - retry if @socket.to_io.wait_writable(write_timeout) - raise TimeoutError, "Write timed out after #{write_timeout} seconds" - end + # Retry writing + def rescue_writable + yield + rescue IO::WaitWritable + retry if @socket.to_io.wait_writable(write_timeout) + raise TimeoutError, "Write timed out after #{write_timeout} seconds" end end end