Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/async/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,16 @@ def io_wait(io, events, timeout = nil)
end

if ::IO::Event::Support.buffer?
# Read from the specified IO into the buffer.
# Read at most the specified number of bytes from the IO into the buffer.
#
# @public Since *Async v2* and Ruby with `IO::Buffer` support.
# @asynchronous May be non-blocking.
#
# @parameter io [IO] The IO object to read from.
# @parameter buffer [IO::Buffer] The buffer to read into.
# @parameter length [Integer] The minimum number of bytes to read.
# @parameter offset [Integer] The offset within the buffer to read into.
def io_read(io, buffer, length, offset = 0)
# @parameter length [Integer] The maximum number of bytes to read.
def io_read(io, buffer, offset, length)
fiber = Fiber.current

if timeout = io.timeout
Expand All @@ -354,22 +354,22 @@ def io_read(io, buffer, length, offset = 0)
end
end

@selector.io_read(fiber, io, buffer, length, offset)
@selector.io_read(fiber, io, buffer, offset, length)
ensure
timer&.cancel!
end

if RUBY_ENGINE != "ruby" || RUBY_VERSION >= "3.3.1"
# Write the specified buffer to the IO.
# Write at most the specified number of bytes from the buffer to the IO.
#
# @public Since *Async v2* and *Ruby v3.3.1* with `IO::Buffer` support.
# @asynchronous May be non-blocking.
#
# @parameter io [IO] The IO object to write to.
# @parameter buffer [IO::Buffer] The buffer to write from.
# @parameter length [Integer] The minimum number of bytes to write.
# @parameter offset [Integer] The offset within the buffer to write from.
def io_write(io, buffer, length, offset = 0)
# @parameter length [Integer] The maximum number of bytes to write.
def io_write(io, buffer, offset, length)
fiber = Fiber.current

if timeout = io.timeout
Expand All @@ -378,7 +378,7 @@ def io_write(io, buffer, length, offset = 0)
end
end

@selector.io_write(fiber, io, buffer, length, offset)
@selector.io_write(fiber, io, buffer, offset, length)
ensure
timer&.cancel!
end
Expand Down
6 changes: 5 additions & 1 deletion test/async/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@
scheduler.instance_variable_set(:@selector, selector)

expect do
scheduler.io_read(io, IO::Buffer.new(1024), 1024)
if defined?(IO::Buffer::VERSION) && IO::Buffer::VERSION >= 3
scheduler.io_read(io, IO::Buffer.new(1024), 0, 1024)
else
scheduler.io_read(io, IO::Buffer.new(1024), 1024, 0)
end
end.to raise_exception(::IO::TimeoutError)
ensure
scheduler&.close
Expand Down
Loading