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
4418static struct timeval *
4519get_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
10544static VALUE
10645io_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
0 commit comments