http 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58370408adc111fae0f96e4541839c2a0722ccf5
4
- data.tar.gz: f3f4ff7f0ba274d7f9c969db7f65d01b134f5711
3
+ metadata.gz: b2e1c7f1cbe78f39dff1f5194cd2fa58b9ffe5b4
4
+ data.tar.gz: 60ba195836aed0fb9a78c29ac67406d725e576d2
5
5
  SHA512:
6
- metadata.gz: 8c18ee7df2159660a8ff5909bdac66e61bcc8e598a1be9d5ae13f825cc704112c3a67aaef633396acd22ca395ac2762bc17b48faccf6472c27eb8c31b8e6cc16
7
- data.tar.gz: bb8e776f129502b8aa1b63be4ee1f935b430a2e4db3f8e613ff96d03059af8137e3760a1a553e4f85a76679a8e7e894ef175e6bc792aa199c46aa053a74f5967
6
+ metadata.gz: a2dc702c28b433e98d710e7330ca9379c3fb182dbee771b03a14c73710cbe3134a5f49177802bdd3696f3586531495ba194738954c7037801c4a31b924638204
7
+ data.tar.gz: 2354deaba38c163740dee33693564b18398fe0a3b3ebcfc18a93b717b11f78bba6d40d4055e7a670d040b135814ed2c98fca84cf9934e5a96527b21a9bd65389
data/.rubocop.yml CHANGED
@@ -1,3 +1,6 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+
1
4
  Metrics/BlockNesting:
2
5
  Max: 2
3
6
 
data/.travis.yml CHANGED
@@ -9,6 +9,7 @@ rvm:
9
9
  - 2.0.0
10
10
  - 2.1
11
11
  - 2.2
12
+ - 2.3.0
12
13
  - jruby
13
14
  - jruby-head
14
15
  - ruby-head
data/CHANGES.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.0.1 (2015-12-27)
2
+
3
+ * [#283](https://github.com/httprb/http/pull/283):
4
+ Use io/wait on supported platforms.
5
+ ([@tarcieri])
6
+
1
7
  ## 1.0.0 (2015-12-25)
2
8
 
3
9
  * [#265](https://github.com/httprb/http/pull/265/):
data/README.md CHANGED
@@ -320,8 +320,9 @@ versions:
320
320
  * Ruby 2.0.0
321
321
  * Ruby 2.1.x
322
322
  * Ruby 2.2.x
323
+ * Ruby 2.3.x
323
324
  * JRuby 1.7.x
324
- * JRuby 9000
325
+ * JRuby 9000+
325
326
 
326
327
  If something doesn't work on one of these versions, it's a bug.
327
328
 
@@ -104,16 +104,32 @@ module HTTP
104
104
  :eof
105
105
  end
106
106
 
107
- # Wait for a socket to become readable
108
- def wait_readable_or_timeout
109
- IO.select([@socket], nil, nil, time_left)
110
- log_time
111
- end
107
+ if RUBY_VERSION < "2.0.0"
108
+ # Wait for a socket to become readable
109
+ def wait_readable_or_timeout
110
+ IO.select([@socket], nil, nil, time_left)
111
+ log_time
112
+ end
112
113
 
113
- # Wait for a socket to become writable
114
- def wait_writable_or_timeout
115
- IO.select(nil, [@socket], nil, time_left)
116
- log_time
114
+ # Wait for a socket to become writable
115
+ def wait_writable_or_timeout
116
+ IO.select(nil, [@socket], nil, time_left)
117
+ log_time
118
+ end
119
+ else
120
+ require "io/wait"
121
+
122
+ # Wait for a socket to become readable
123
+ def wait_readable_or_timeout
124
+ @socket.to_io.wait_readable(time_left)
125
+ log_time
126
+ end
127
+
128
+ # Wait for a socket to become writable
129
+ def wait_writable_or_timeout
130
+ @socket.to_io.wait_writable(time_left)
131
+ log_time
132
+ end
117
133
  end
118
134
 
119
135
  # Due to the run/retry nature of nonblocking I/O, it's easier to keep track of time
@@ -50,26 +50,43 @@ module HTTP
50
50
  end
51
51
  alias_method :<<, :write
52
52
 
53
+ # These cops can be re-eanbled after we go Ruby 2.0+ only
54
+ # rubocop:disable Lint/UselessAccessModifier, Metrics/BlockNesting
55
+
53
56
  private
54
57
 
55
- # Retry reading
56
- def rescue_readable
57
- yield
58
- rescue IO::WaitReadable
59
- if IO.select([socket], nil, nil, read_timeout)
60
- retry
61
- else
58
+ if RUBY_VERSION < "2.0.0"
59
+ # Retry reading
60
+ def rescue_readable
61
+ yield
62
+ rescue IO::WaitReadable
63
+ retry if IO.select([socket], nil, nil, read_timeout)
64
+ raise TimeoutError, "Read timed out after #{read_timeout} seconds"
65
+ end
66
+
67
+ # Retry writing
68
+ def rescue_writable
69
+ yield
70
+ rescue IO::WaitWritable
71
+ retry if IO.select(nil, [socket], nil, write_timeout)
72
+ raise TimeoutError, "Write timed out after #{write_timeout} seconds"
73
+ end
74
+ else
75
+ require "io/wait"
76
+
77
+ # Retry reading
78
+ def rescue_readable
79
+ yield
80
+ rescue IO::WaitReadable
81
+ retry if socket.to_io.wait_readable(read_timeout)
62
82
  raise TimeoutError, "Read timed out after #{read_timeout} seconds"
63
83
  end
64
- end
65
84
 
66
- # Retry writing
67
- def rescue_writable
68
- yield
69
- rescue IO::WaitWritable
70
- if IO.select(nil, [socket], nil, write_timeout)
71
- retry
72
- else
85
+ # Retry writing
86
+ def rescue_writable
87
+ yield
88
+ rescue IO::WaitWritable
89
+ retry if socket.to_io.wait_writable(write_timeout)
73
90
  raise TimeoutError, "Write timed out after #{write_timeout} seconds"
74
91
  end
75
92
  end
@@ -59,14 +59,19 @@ module HTTP
59
59
  # Read data from the socket
60
60
  def readpartial(size)
61
61
  loop do
62
- result = socket.read_nonblock(size, :exception => false)
62
+ # JRuby may still raise exceptions on SSL sockets even though
63
+ # we explicitly specify `:exception => false`
64
+ result = rescue_readable do
65
+ socket.read_nonblock(size, :exception => false)
66
+ end
67
+
63
68
  if result.nil?
64
69
  return :eof
65
70
  elsif result != :wait_readable
66
71
  return result
67
72
  end
68
73
 
69
- unless IO.select([socket], nil, nil, read_timeout)
74
+ unless socket.to_io.wait_readable(read_timeout)
70
75
  fail TimeoutError, "Read timed out after #{read_timeout} seconds"
71
76
  end
72
77
  end
@@ -75,10 +80,15 @@ module HTTP
75
80
  # Write data to the socket
76
81
  def write(data)
77
82
  loop do
78
- result = socket.write_nonblock(data, :exception => false)
83
+ # JRuby may still raise exceptions on SSL sockets even though
84
+ # we explicitly specify `:exception => false`
85
+ result = rescue_writable do
86
+ socket.write_nonblock(data, :exception => false)
87
+ end
88
+
79
89
  return result unless result == :wait_writable
80
90
 
81
- unless IO.select(nil, [socket], nil, write_timeout)
91
+ unless socket.to_io.wait_writable(write_timeout)
82
92
  fail TimeoutError, "Read timed out after #{write_timeout} seconds"
83
93
  end
84
94
  end
data/lib/http/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module HTTP
2
- VERSION = "1.0.0".freeze
2
+ VERSION = "1.0.1".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-12-25 00:00:00.000000000 Z
14
+ date: 2015-12-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: http_parser.rb