Skip to content

Commit

Permalink
Remove usage of IO internals.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed May 28, 2023
1 parent 614b209 commit 4fc9051
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions ext/io/wait/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
else
target = "io/wait"
have_func("rb_io_wait")
have_func("rb_io_descriptor")
unless macro_defined?("DOSISH", "#include <ruby.h>")
have_header(ioctl_h = "sys/ioctl.h") or ioctl_h = nil
fionread = %w[sys/ioctl.h sys/filio.h sys/socket.h].find do |h|
Expand Down
11 changes: 9 additions & 2 deletions ext/io/wait/wait.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,15 @@ io_nread(VALUE io)
rb_io_check_readable(fptr);
len = rb_io_read_pending(fptr);
if (len > 0) return INT2FIX(len);
if (!FIONREAD_POSSIBLE_P(fptr->fd)) return INT2FIX(0);
if (ioctl(fptr->fd, FIONREAD, &n)) return INT2FIX(0);

#ifdef HAVE_RB_IO_DESCRIPTOR
int fd = rb_io_descriptor(io);
#else
int fd = fptr->fd;
#endif

if (!FIONREAD_POSSIBLE_P(fd)) return INT2FIX(0);
if (ioctl(fd, FIONREAD, &n)) return INT2FIX(0);
if (n > 0) return ioctl_arg2num(n);
return INT2FIX(0);
}
Expand Down

0 comments on commit 4fc9051

Please sign in to comment.