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
response = ""
while !response.match(/\n/) && Thread.new { IO.select([@socket]) }.join do
response += @socket.read_nonblock(1)
until response.match(/\n/) do
response += read(1)
end
response
end
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
private