Skip to content

Commit 258cb5a

Browse files
committed
Add IO constants READABLE, WRITABLE and PRIORITY
1 parent f61ed2f commit 258cb5a

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

spec/ruby/optional/capi/io_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
ruby_version_is "3.1" do
260260
describe "rb_io_maybe_wait_writable" do
261261
it "returns mask for events if operation was interrupted" do
262-
@o.rb_io_maybe_wait_writable(Errno::EINTR::Errno, @w_io, nil).should == 4 # IO::WRITABLE = 4
262+
@o.rb_io_maybe_wait_writable(Errno::EINTR::Errno, @w_io, nil).should == IO::WRITABLE
263263
end
264264

265265
it "returns 0 if there is no error condition" do
@@ -330,7 +330,7 @@
330330
ruby_version_is "3.1" do
331331
describe "rb_io_maybe_wait_readable" do
332332
it "returns mask for events if operation was interrupted" do
333-
@o.rb_io_maybe_wait_readable(Errno::EINTR::Errno, @r_io, nil, false).should == 1 # IO::READABLE = 1
333+
@o.rb_io_maybe_wait_readable(Errno::EINTR::Errno, @r_io, nil, false).should == IO::READABLE
334334
end
335335

336336
it "returns 0 if there is no error condition" do
@@ -344,7 +344,7 @@
344344
@w_io.write "rb_io_wait_readable"
345345
end
346346

347-
@o.rb_io_maybe_wait_readable(Errno::EAGAIN::Errno, @r_io, 1, true).should == 1 # IO::READABLE = 1
347+
@o.rb_io_maybe_wait_readable(Errno::EAGAIN::Errno, @r_io, IO::READABLE, true).should == IO::READABLE
348348
@o.instance_variable_get(:@read_data).should == "rb_io_wait_re"
349349

350350
thr.join
@@ -412,26 +412,26 @@
412412

413413
Thread.pass until start
414414

415-
@o.rb_io_maybe_wait(Errno::EAGAIN::Errno, @r_io, 1, nil).should == 1 # IO::READABLE = 1
415+
@o.rb_io_maybe_wait(Errno::EAGAIN::Errno, @r_io, IO::READABLE, nil).should == IO::READABLE
416416

417417
thr.join
418418
end
419419

420420
it "returns mask for events if operation was interrupted" do
421-
@o.rb_io_maybe_wait(Errno::EINTR::Errno, @w_io, 4, nil).should == 4 # IO::WRITABLE = 4
421+
@o.rb_io_maybe_wait(Errno::EINTR::Errno, @w_io, IO::WRITABLE, nil).should == IO::WRITABLE
422422
end
423423

424424
it "returns false if there is no error condition" do
425-
@o.rb_io_maybe_wait(0, @w_io, 4, nil).should == false # IO::WRITABLE = 4
425+
@o.rb_io_maybe_wait(0, @w_io, IO::WRITABLE, nil).should == false
426426
end
427427

428428
it "raises an IOError if the IO is closed" do
429429
@w_io.close
430-
-> { @o.rb_io_maybe_wait(0, @w_io, 4, nil) }.should raise_error(IOError, "closed stream") # IO::WRITABLE = 4
430+
-> { @o.rb_io_maybe_wait(0, @w_io, IO::WRITABLE, nil) }.should raise_error(IOError, "closed stream")
431431
end
432432

433433
it "raises an IOError if the IO is not initialized" do
434-
-> { @o.rb_io_maybe_wait(0, IO.allocate, 4, nil) }.should raise_error(IOError, "uninitialized stream") # IO::WRITABLE = 4
434+
-> { @o.rb_io_maybe_wait(0, IO.allocate, IO::WRITABLE, nil) }.should raise_error(IOError, "uninitialized stream")
435435
end
436436
end
437437
end

src/main/ruby/truffleruby/core/io.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ class EINPROGRESSWaitWritable < Errno::EINPROGRESS
7575
end
7676
end
7777

78+
READABLE = Truffle::Config['platform.poll.POLLIN']
79+
WRITABLE = Truffle::Config['platform.poll.POLLOUT']
80+
PRIORITY = Truffle::Config['platform.poll.POLLPRI']
81+
7882
# InternalBuffer provides a sliding window into a region of bytes.
7983
# The buffer is filled to the +used+ indicator, which is
8084
# always less than or equal to +total+. As bytes are taken

0 commit comments

Comments
 (0)