Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a read timeout.

  • Loading branch information...
commit cefc370c804f9648bb8f46e325245332d8d19a93 1 parent 37187ad
@benburkert authored
Showing with 9 additions and 4 deletions.
  1. +2 −1  lib/excon/errors.rb
  2. +7 −3 lib/excon/socket.rb
View
3  lib/excon/errors.rb
@@ -2,6 +2,7 @@ module Excon
module Errors
class Error < StandardError; end
+ class TimeoutError < Error; end
class Continue < Error; end # 100
class SwitchingProtocols < Error; end # 101
@@ -93,4 +94,4 @@ def self.status_error(request, response)
end
end
-end
+end
View
10 lib/excon/socket.rb
@@ -31,12 +31,16 @@ def write_io(io)
end
end
- def readable?
- select([socket], nil, nil, @timeout)
+ def readpartial(size = @chunk_size)
+ Timeout::timeout(@timeout) do
+ socket.readpartial(size)
+ end
+ rescue Timeout::Error
+ raise Errors::TimeoutError
end
def drain
- while chunk = socket.readpartial(@chunk_size)
+ while chunk = readpartial
yield chunk
end
Please sign in to comment.
Something went wrong with that request. Please try again.