Skip to content

Commit 1decadc

Browse files
committed
Remove IO#nread and `IO#ready?
1 parent f5c8113 commit 1decadc

File tree

5 files changed

+1
-196
lines changed

5 files changed

+1
-196
lines changed

ext/io/wait/extconf.rb

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
# frozen_string_literal: false
22
require 'mkmf'
33

4-
target = "io/wait"
54
have_func("rb_io_wait", "ruby/io.h")
65
have_func("rb_io_descriptor", "ruby/io.h")
7-
unless macro_defined?("DOSISH", "#include <ruby.h>")
8-
have_header(ioctl_h = "sys/ioctl.h") or ioctl_h = nil
9-
fionread = %w[sys/ioctl.h sys/filio.h sys/socket.h].find do |h|
10-
have_macro("FIONREAD", [h, ioctl_h].compact)
11-
end
12-
if fionread
13-
$defs << "-DFIONREAD_HEADER=\"<#{fionread}>\""
14-
create_makefile(target)
15-
end
16-
else
17-
if have_func("rb_w32_ioctlsocket", "ruby.h")
18-
have_func("rb_w32_is_socket", "ruby.h")
19-
create_makefile(target)
20-
end
21-
end
6+
create_makefile("io/wait")

ext/io/wait/wait.c

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,6 @@
1414
#include "ruby.h"
1515
#include "ruby/io.h"
1616

17-
#include <sys/types.h>
18-
#if defined(HAVE_UNISTD_H) && (defined(__sun))
19-
#include <unistd.h>
20-
#endif
21-
#if defined(HAVE_SYS_IOCTL_H)
22-
#include <sys/ioctl.h>
23-
#endif
24-
#if defined(FIONREAD_HEADER)
25-
#include FIONREAD_HEADER
26-
#endif
27-
28-
#ifdef HAVE_RB_W32_IOCTLSOCKET
29-
#define ioctl ioctlsocket
30-
#define ioctl_arg u_long
31-
#define ioctl_arg2num(i) ULONG2NUM(i)
32-
#else
33-
#define ioctl_arg int
34-
#define ioctl_arg2num(i) INT2NUM(i)
35-
#endif
36-
37-
#ifdef HAVE_RB_W32_IS_SOCKET
38-
#define FIONREAD_POSSIBLE_P(fd) rb_w32_is_socket(fd)
39-
#else
40-
#define FIONREAD_POSSIBLE_P(fd) ((void)(fd),Qtrue)
41-
#endif
42-
4317
#ifndef HAVE_RB_IO_WAIT
4418
static struct timeval *
4519
get_timeout(int argc, VALUE *argv, struct timeval *timerec)
@@ -66,41 +40,6 @@ wait_for_single_fd(rb_io_t *fptr, int events, struct timeval *tv)
6640
}
6741
#endif
6842

69-
/*
70-
* call-seq:
71-
* io.nread -> int
72-
*
73-
* Returns number of bytes that can be read without blocking.
74-
* Returns zero if no information available.
75-
*
76-
* You must require 'io/wait' to use this method.
77-
*/
78-
79-
static VALUE
80-
io_nread(VALUE io)
81-
{
82-
rb_io_t *fptr;
83-
int len;
84-
ioctl_arg n;
85-
86-
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, "IO#nread is deprecated; use wait_readable instead");
87-
GetOpenFile(io, fptr);
88-
rb_io_check_char_readable(fptr);
89-
len = rb_io_read_pending(fptr);
90-
if (len > 0) return INT2FIX(len);
91-
92-
#ifdef HAVE_RB_IO_DESCRIPTOR
93-
int fd = rb_io_descriptor(io);
94-
#else
95-
int fd = fptr->fd;
96-
#endif
97-
98-
if (!FIONREAD_POSSIBLE_P(fd)) return INT2FIX(0);
99-
if (ioctl(fd, FIONREAD, &n)) return INT2FIX(0);
100-
if (n > 0) return ioctl_arg2num(n);
101-
return INT2FIX(0);
102-
}
103-
10443
#ifdef HAVE_RB_IO_WAIT
10544
static VALUE
10645
io_wait_event(VALUE io, int event, VALUE timeout, int return_io)
@@ -125,36 +64,6 @@ io_wait_event(VALUE io, int event, VALUE timeout, int return_io)
12564
}
12665
#endif
12766

128-
/*
129-
* call-seq:
130-
* io.ready? -> truthy or falsy
131-
*
132-
* Returns a truthy value if input available without blocking, or a
133-
* falsy value.
134-
*
135-
* You must require 'io/wait' to use this method.
136-
*/
137-
138-
static VALUE
139-
io_ready_p(VALUE io)
140-
{
141-
rb_io_t *fptr;
142-
#ifndef HAVE_RB_IO_WAIT
143-
struct timeval tv = {0, 0};
144-
#endif
145-
146-
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, "IO#ready? is deprecated; use wait_readable instead");
147-
GetOpenFile(io, fptr);
148-
rb_io_check_char_readable(fptr);
149-
if (rb_io_read_pending(fptr)) return Qtrue;
150-
151-
#ifndef HAVE_RB_IO_WAIT
152-
return wait_for_single_fd(fptr, RB_WAITFD_IN, &tv) ? Qtrue : Qfalse;
153-
#else
154-
return io_wait_event(io, RUBY_IO_READABLE, RB_INT2NUM(0), 1);
155-
#endif
156-
}
157-
15867
/* Ruby 3.2+ can define these methods. This macro indicates that case. */
15968
#ifndef RUBY_IO_WAIT_METHODS
16069

@@ -424,9 +333,6 @@ Init_wait(void)
424333
RB_EXT_RACTOR_SAFE(true);
425334
#endif
426335

427-
rb_define_method(rb_cIO, "nread", io_nread, 0);
428-
rb_define_method(rb_cIO, "ready?", io_ready_p, 0);
429-
430336
#ifndef RUBY_IO_WAIT_METHODS
431337
rb_define_method(rb_cIO, "wait", io_wait, -1);
432338

ext/java/org/jruby/ext/io/wait/IOWaitLibrary.java

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -56,47 +56,6 @@ public void load(Ruby runtime, boolean wrap) {
5656
ioClass.defineAnnotatedMethods(IOWaitLibrary.class);
5757
}
5858

59-
@JRubyMethod
60-
public static IRubyObject nread(ThreadContext context, IRubyObject _io) {
61-
Ruby runtime = context.runtime;
62-
OpenFile fptr;
63-
int len;
64-
// ioctl_arg n;
65-
RubyIO io = (RubyIO)_io;
66-
67-
warnDeprecated(context, "IO#nread is deprecated; use wait_readable instead");
68-
fptr = io.getOpenFileChecked();
69-
fptr.checkReadable(context);
70-
len = fptr.readPending();
71-
if (len > 0) return runtime.newFixnum(len);
72-
// TODO: better effort to get available bytes from our channel
73-
// if (!FIONREAD_POSSIBLE_P(fptr->fd)) return INT2FIX(0);
74-
// if (ioctl(fptr->fd, FIONREAD, &n)) return INT2FIX(0);
75-
// if (n > 0) return ioctl_arg2num(n);
76-
// Because we can't get an actual system-level buffer available count, we fake it by returning 1 if ready
77-
return RubyNumeric.int2fix(runtime, fptr.readyNow(context) ? 1 : 0);
78-
}
79-
80-
/**
81-
* returns non-nil if input available without blocking, false if EOF or not open/readable, otherwise nil.
82-
*/
83-
@JRubyMethod(name = "ready?")
84-
public static IRubyObject ready(ThreadContext context, IRubyObject _io) {
85-
RubyIO io = (RubyIO)_io;
86-
OpenFile fptr;
87-
// ioctl_arg n;
88-
89-
warnDeprecated(context, "IO#ready? is deprecated; use wait_readable instead");
90-
fptr = io.getOpenFileChecked();
91-
fptr.checkReadable(context);
92-
if (fptr.readPending() != 0) return context.tru;
93-
// TODO: better effort to get available bytes from our channel
94-
// if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qnil;
95-
// if (ioctl(fptr->fd, FIONREAD, &n)) return Qnil;
96-
// if (n > 0) return Qtrue;
97-
return RubyBoolean.newBoolean(context, fptr.readyNow(context));
98-
}
99-
10059
@JRubyMethod(optional = 1)
10160
public static IRubyObject wait_readable(ThreadContext context, IRubyObject _io, IRubyObject[] argv) {
10261
RubyIO io = (RubyIO)_io;

test/io/wait/test_io_wait.rb

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
require 'timeout'
55
require 'socket'
66

7-
# For `IO#ready?` and `IO#nread`:
8-
require 'io/wait'
9-
107
class TestIOWait < Test::Unit::TestCase
118

129
def setup
@@ -22,33 +19,6 @@ def teardown
2219
@w.close unless @w.closed?
2320
end
2421

25-
def test_nread
26-
assert_equal 0, @r.nread
27-
@w.syswrite "."
28-
sleep 0.1
29-
assert_equal 1, @r.nread
30-
end
31-
32-
def test_nread_buffered
33-
@w.syswrite ".\n!"
34-
assert_equal ".\n", @r.gets
35-
assert_equal 1, @r.nread
36-
end
37-
38-
def test_ready?
39-
omit 'unstable on MinGW' if /mingw/ =~ RUBY_PLATFORM
40-
assert_not_predicate @r, :ready?, "shouldn't ready, but ready"
41-
@w.syswrite "."
42-
sleep 0.1
43-
assert_predicate @r, :ready?, "should ready, but not"
44-
end
45-
46-
def test_buffered_ready?
47-
@w.syswrite ".\n!"
48-
assert_equal ".\n", @r.gets
49-
assert_predicate @r, :ready?
50-
end
51-
5222
def test_wait
5323
omit 'unstable on MinGW' if /mingw/ =~ RUBY_PLATFORM
5424
assert_nil @r.wait(0)

test/io/wait/test_io_wait_uncommon.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,13 @@ def test_wait_writable_null
7676
check_dev(IO::NULL, :wait_writable)
7777
end
7878

79-
def test_after_ungetc_ready?
80-
check_dev(IO::NULL, mode: "r") {|fp|
81-
assert_respond_to fp, :ready?
82-
fp.ungetc(?a)
83-
assert_predicate fp, :ready?
84-
}
85-
end
86-
8779
def test_after_ungetc_wait_readable
8880
check_dev(IO::NULL, mode: "r") {|fp|
8981
fp.ungetc(?a)
9082
assert_predicate fp, :wait_readable
9183
}
9284
end
9385

94-
def test_after_ungetc_in_text_ready?
95-
check_dev(IO::NULL, mode: "rt") {|fp|
96-
fp.ungetc(?a)
97-
assert_predicate fp, :ready?
98-
}
99-
end
100-
10186
def test_after_ungetc_in_text_wait_readable
10287
check_dev(IO::NULL, mode: "rt") {|fp|
10388
fp.ungetc(?a)

0 commit comments

Comments
 (0)