Skip to content

Commit

Permalink
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions core/io.rb
Original file line number Diff line number Diff line change
@@ -2046,15 +2046,10 @@ def read_all
#
# If the read buffer is not empty, read_nonblock reads from the
# buffer like readpartial. In this case, read(2) is not called.
def read_nonblock(size, buffer=nil, opts={})
def read_nonblock(size, buffer=nil, exception: true)
raise ArgumentError, "illegal read size" if size < 0
ensure_open

if buffer.is_a?(Hash)
opts = buffer
buffer = nil
end

buffer = StringValue buffer if buffer

if @ibuffer.size > 0
@@ -2064,7 +2059,7 @@ def read_nonblock(size, buffer=nil, opts={})
begin
str = read_if_available(size)
rescue EAGAINWaitReadable => exc
raise exc unless opts[:exception] == false
raise exc if exception

return :wait_readable
end
@@ -2073,7 +2068,7 @@ def read_nonblock(size, buffer=nil, opts={})
buffer.replace(str) if buffer
return str
else
raise EOFError, "stream closed" unless opts[:exception] == false
raise EOFError, "stream closed" if exception
end
end

@@ -2602,7 +2597,7 @@ def write(data)
data.bytesize
end

def write_nonblock(data, opts={})
def write_nonblock(data, exception: true)
ensure_open_and_writable

data = String data
@@ -2612,7 +2607,7 @@ def write_nonblock(data, opts={})

raw_write(data)
rescue EAGAINWaitWritable => exc
raise exc unless opts[:exception] == false
raise exc if exception

return :wait_writable
end

0 comments on commit 477db7c

Please sign in to comment.