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
|
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
|
||||||
|
|
Loading…
Reference in a new issue