Make Connection#read non-blocking

* Ensure that Connection#read will not block Timeout::timeout for JRuby
  users.
This commit is contained in:
Matthew Horan 2014-07-18 09:43:10 -04:00
parent cc6b910634
commit 22a81f6bb2
1 changed files with 12 additions and 5 deletions

View File

@ -36,16 +36,23 @@ module Capybara::Webkit
def gets def gets
response = "" response = ""
until response.match(/\n/) do
while !response.match(/\n/) && Thread.new { IO.select([@socket]) }.join do response += read(1)
response += @socket.read_nonblock(1)
end end
response response
end end
def read(length) def read(length)
@socket.read(length) response = ""
begin
while response.length < length do
response += @socket.read_nonblock(length - response.length)
end
rescue IO::WaitReadable
Thread.new { IO.select([@socket]) }.join
retry
end
response
end end
private private