Skip to content

Commit e5854b4

Browse files
authored
Remove usage of IO internals. (#25)
1 parent 614b209 commit e5854b4

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

ext/io/wait/extconf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
else
77
target = "io/wait"
88
have_func("rb_io_wait")
9+
have_func("rb_io_descriptor")
910
unless macro_defined?("DOSISH", "#include <ruby.h>")
1011
have_header(ioctl_h = "sys/ioctl.h") or ioctl_h = nil
1112
fionread = %w[sys/ioctl.h sys/filio.h sys/socket.h].find do |h|

ext/io/wait/wait.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,15 @@ io_nread(VALUE io)
8787
rb_io_check_readable(fptr);
8888
len = rb_io_read_pending(fptr);
8989
if (len > 0) return INT2FIX(len);
90-
if (!FIONREAD_POSSIBLE_P(fptr->fd)) return INT2FIX(0);
91-
if (ioctl(fptr->fd, FIONREAD, &n)) return INT2FIX(0);
90+
91+
#ifdef HAVE_RB_IO_DESCRIPTOR
92+
int fd = rb_io_descriptor(io);
93+
#else
94+
int fd = fptr->fd;
95+
#endif
96+
97+
if (!FIONREAD_POSSIBLE_P(fd)) return INT2FIX(0);
98+
if (ioctl(fd, FIONREAD, &n)) return INT2FIX(0);
9299
if (n > 0) return ioctl_arg2num(n);
93100
return INT2FIX(0);
94101
}

0 commit comments

Comments
 (0)