Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Commit

Permalink
using the new read_ and write_nonblock signature (ruby 2.1) in which …
Browse files Browse the repository at this point in the history
…one doesn't need to handle Wait* Exception (Closes #139)
  • Loading branch information
Tiago Cardoso committed Jan 8, 2016
1 parent 21ddab6 commit 5321f59
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions lib/celluloid/io/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ def sysread(length = nil, buffer = nil)
buffer ||= ''.force_encoding(Encoding::ASCII_8BIT)

@read_latch.synchronize do
begin
read_nonblock(length, buffer)
rescue ::IO::WaitReadable
wait_readable
retry
if RUBY_VERSION < '2.1'
begin
read_nonblock(length, buffer)
rescue ::IO::WaitReadable
wait_readable
retry
end
else
loop while read_nonblock(length, buffer, exception: false) == :wait_readable
end
end

Expand All @@ -57,13 +61,21 @@ def syswrite(string)

@write_latch.synchronize do
while total_written < length
begin
written = write_nonblock(remaining)
rescue ::IO::WaitWritable
wait_writable
retry
rescue EOFError
return total_written
if RUBY_VERSION < '2.1'
begin
written = write_nonblock(remaining)
rescue ::IO::WaitWritable
wait_writable
retry
rescue EOFError
return total_written
end
else
begin
loop while (written = write_nonblock(remaining, exception: false)) == :wait_writable
rescue EOFError
return total_written
end
end

total_written += written
Expand Down

0 comments on commit 5321f59

Please sign in to comment.