mirror of
https://github.com/thoughtbot/capybara-webkit
synced 2023-03-27 23:22:28 -04:00
Make Connection#read non-blocking
* Ensure that Connection#read will not block Timeout::timeout for JRuby users.
This commit is contained in:
parent
cc6b910634
commit
22a81f6bb2
1 changed files with 12 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue