Project

General

Profile

Actions

Feature #21625

open

Allow IO#wait_readable together with IO#ungetc

Added by YO4 (Yoshinao Muramatsu) about 3 hours ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:123389]

Description

Background

IO#wait_readable calles rb_io_check_byte_readable() in that C implementation, so that is treated as binary reading class operation.

open(IO::NULL, "rt") { |f| f.ungetc(?a); f.wait_readable }
# => in 'IO#wait_readable': byte oriented read for character buffered IO (IOError)

This is inconsistent with the behavior of IO#select.

open(IO::NULL, "rt") { |f| f.ungetc(?a); IO.select([f]) }
# => [[#<File:NUL (closed)>], [], []]

Proposal

Change IO#wait_readable into character reading class function.
This allows mixing usage of IO#wait_readable and IO#ungetc.

This change avoids the IOError that previously occurred, but in that case,
an exception is thrown when the binary read method is subsequently called.
Overall behavior remains unchanged, but exceptions will occur at more desirable locations.
If the method being called next is a character method, no exception will be thrown.
But that is the desired behavior.

related methods

IO#io_wait_priority may apply similar changes for consistency.
IO#ready? seems to have the same issue. This is in the io-wait default gem.
IO#wait already respects the character read buffer.

No data to display

Actions

Also available in: Atom PDF

Like0