diff --git a/lib/io/event/selector/select.rb b/lib/io/event/selector/select.rb index d99e8a3..e5e7f67 100644 --- a/lib/io/event/selector/select.rb +++ b/lib/io/event/selector/select.rb @@ -168,6 +168,8 @@ def again?(errno) if Support.fiber_scheduler_v3? # Ruby 3.3+, full IO::Buffer support. + # Read from the given IO to the buffer. + # # @parameter length [Integer] The minimum number of bytes to read. # @parameter offset [Integer] The offset into the buffer to read to. def io_read(fiber, io, buffer, length, offset = 0) @@ -196,6 +198,8 @@ def io_read(fiber, io, buffer, length, offset = 0) return total end + # Write to the given IO from the buffer. + # # @parameter length [Integer] The minimum number of bytes to write. # @parameter offset [Integer] The offset into the buffer to write from. def io_write(fiber, io, buffer, length, offset = 0) diff --git a/lib/io/event/support.rb b/lib/io/event/support.rb index b9a937e..42305ac 100644 --- a/lib/io/event/support.rb +++ b/lib/io/event/support.rb @@ -10,14 +10,23 @@ def self.buffer? IO.const_defined?(:Buffer) end + # To be removed on 31 Mar 2025. def self.fiber_scheduler_v1? IO.const_defined?(:Buffer) and !Fiber.respond_to?(:blocking) end + # To be removed on 31 Mar 2026. def self.fiber_scheduler_v2? + # Some interface changes were back-ported incorrectly: + # https://github.com/ruby/ruby/pull/10778 + # Specifically "Improvements to IO::Buffer read/write/pread/pwrite." + # Missing correct size calculation. + return false if RUBY_VERSION >= "3.2.5" + IO.const_defined?(:Buffer) and Fiber.respond_to?(:blocking) and IO::Buffer.instance_method(:read).arity == -1 end + # To become the default 31 Mar 2026. def self.fiber_scheduler_v3? if fiber_scheduler_v2? return true if RUBY_VERSION >= "3.3" diff --git a/test/io/event/selector/buffered_io.rb b/test/io/event/selector/buffered_io.rb index 4985733..9c4e209 100644 --- a/test/io/event/selector/buffered_io.rb +++ b/test/io/event/selector/buffered_io.rb @@ -41,11 +41,13 @@ it "can read and write at the specified offset" do writer = Fiber.new do buffer = IO::Buffer.new(128) + # We can't write 128 bytes because there are only +64 bytes from offset 64. expect(selector.io_write(Fiber.current, output, buffer, 128, 64)).to be == 64 end reader = Fiber.new do buffer = IO::Buffer.new(128) + # Only 64 bytes are available to read. expect(selector.io_read(Fiber.current, input, buffer, 1, 64)).to be == 64 end