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
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/FiberScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.cli.Options;
import org.jruby.util.io.OpenFile;

import java.nio.ByteBuffer;

Expand Down Expand Up @@ -55,12 +54,12 @@ public static IRubyObject ioWait(ThreadContext context, IRubyObject scheduler, I

// MRI: rb_fiber_scheduler_io_wait_readable
public static IRubyObject ioWaitReadable(ThreadContext context, IRubyObject scheduler, IRubyObject io) {
return ioWait(context, scheduler, io, asFixnum(context, OpenFile.READABLE), context.nil);
return ioWait(context, scheduler, io, asFixnum(context, RubyIO.IOEvent.IO_READABLE.value), context.nil);
}

// MRI: rb_fiber_scheduler_io_wait_writable
public static IRubyObject ioWaitWritable(ThreadContext context, IRubyObject scheduler, IRubyObject io) {
return ioWait(context, scheduler, io, asFixnum(context, OpenFile.WRITABLE), context.nil);
return ioWait(context, scheduler, io, asFixnum(context, RubyIO.IOEvent.IO_WRITABLE.value), context.nil);
}

// MRI: rb_fiber_scheduler_io_select
Expand Down
36 changes: 36 additions & 0 deletions spec/ruby/core/io/write_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,42 @@
end
end

describe "IO#write with Fiber scheduler" do
require_relative '../fiber/fixtures/scheduler'
require 'io/nonblock'

before :each do
@r, @w = IO.pipe
@w.nonblock = true
nil until @w.write_nonblock("x" * 65536, exception: false) == :wait_writable
Fiber.set_scheduler(FiberSpecs::LoggingScheduler.new)
end

after :each do
Fiber.set_scheduler(nil)
@r.close
@w.close
end

it "waits for the IO to become writable through the scheduler" do
writer = Fiber.schedule { @w.write("y") }

begin
event = Fiber.scheduler.events.last
event[:event].should == :io_wait
event[:fiber].should == writer
io, events, timeout = event[:args]
io.fileno.should == @w.fileno
events.should == IO::WRITABLE
timeout.should == nil
ensure
# let the writer finish, so closing the pipe does not wait on it
nil until @r.read_nonblock(65536, exception: false) == :wait_readable
writer.resume(IO::WRITABLE) while writer.alive?
end
end
end

platform_is :windows do
describe "IO#write on Windows" do
before :each do
Expand Down
Loading