Skip to content

Commit

Permalink
Use keyword args in IO::{read,write}_nonblock instead of hash handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadsherif committed Mar 6, 2016
1 parent bcbf8b6 commit 477db7c
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions core/io.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 477db7c

Please sign in to comment.