Skip to content

Commit

Permalink
Remove Ruby < 2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ixti committed Mar 18, 2016
1 parent f7e028a commit d827859
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 70 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
39 changes: 10 additions & 29 deletions lib/http/timeout/global.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "timeout"
require "io/wait"

require "http/timeout/per_operation"

Expand Down Expand Up @@ -59,25 +60,21 @@ def write(data)
private

if RUBY_VERSION < "2.1.0"

def read_nonblock(size)
@socket.read_nonblock(size)
end

def write_nonblock(data)
@socket.write_nonblock(data)
end

else

def read_nonblock(size)
@socket.read_nonblock(size, :exception => false)
end

def write_nonblock(data)
@socket.write_nonblock(data, :exception => false)
end

end

# Perform the given I/O operation with the given argument
Expand All @@ -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
Expand Down
50 changes: 14 additions & 36 deletions lib/http/timeout/null.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "forwardable"
require "io/wait"

module HTTP
module Timeout
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d827859

Please sign in to comment.