I cannot understand why IO methods will not work in STDIN if they are correctly set to non-blocking mode:
require 'fcntl'
stdin_flags = STDIN.fcntl(Fcntl::F_GETFL)
p stdin_flags
p STDIN.fcntl(Fcntl::F_SETFL, stdin_flags | Fcntl::O_NONBLOCK)
p STDIN.fcntl(Fcntl::F_GETFL)
STDIN.readline
exit
IO.fcntlsuccessfully establishes a non-blocking mode, but all input-output functions, such as read, readline, gets, readcharignore mode and hangs when reading, when the input is received.
Setting the synchronization mode does not affect true.
If replaced STDIN.readlinewith a shell call system('read line'), it will work correctly. It will not wait or wait for input, depending on whether non-blocking mode has been set.
I know IO.read_nonblock, but I'm looking for an efficient way to read lines with a trailing newline. The call read_nonblockfor each individual character is very slow.
- () ?