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
|
@ -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 New Issue