Opened 8 months ago

#1339 new defect

char-ready? returns #f even when input is available

Reported by: kooda Owned by:
Priority: minor Milestone: 5.0
Component: core libraries Version: 4.11.0
Keywords: Cc:
Estimated difficulty: insane

Description

The current implementation of char-ready? on stdio files returns #f if you have buffering enabled, didn’t consume the whole buffer and no more input is available from the system’s point of view, as it only asks the system via select or poll (see C_char_ready_p and C_check_fd_ready).

I’m afraid there’s no way to do better than this with stdio files, as there is no way of checking the state of the buffer.

The workaround I found was to simply disable buffering altogether, like so:

(set-buffering-mode! (current-input-port) #:none)

This bug probably requires a pretty big rework of ports.

Here is a little program that might show the erroneous behaviour:

(use posix)

(call-with-input-pipe "echo coucou"
  (lambda (p)
    (let loop ((c (read-char p)))
      (unless (eof-object? c)
        (print c)
        (when (char-ready? p) (loop (read-char p)))))))

Change History (0)

Note: See TracTickets for help on using tickets.