Setting termios VMIN > 0 and VTIME > 0 on non blocking file

Åke Rehnman ake.rehnman@gmail.com
Thu Mar 12 11:01:01 GMT 2020


On 2020-03-12 09:05, Thomas Dickey wrote:
> If not "correct", it's certainly inconsistent with all other systems.
> I noticed it recently:
>
> https://invisible-island.net/ncurses/tack/CHANGES.html#t20200220
>
> https://github.com/cygwinports/tack/issues/1
>
> It's either recently-broken, or just coincidence :-)


Beer fine for you Thomas for copying email-addresses in the reply :-)

Looking at Linux tty line discipline reveals the VMIN and VTIME are 
ignored if O_NONBLOCK flag is set.

         if (!input_available_p(tty, 0)) {
             up_read(&tty->termios_rwsem);
             tty_buffer_flush_work(tty->port);
             down_read(&tty->termios_rwsem);
             if (!input_available_p(tty, 0)) {
                 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) {
                     retval = -EIO;
                     break;
                 }
                 if (tty_hung_up_p(file))
                     break;
                 /*
                  * Abort readers for ttys which never actually
                  * get hung up.  See __tty_hangup().
                  */
                 if (test_bit(TTY_HUPPING, &tty->flags))
                     break;
                 if (!timeout)
                     break; *<= EXIT HERE if VTIME == 0*
                 if (file->f_flags & O_NONBLOCK) {
                     retval = -EAGAIN; *<==== EXIT HERE*
                     break;
                 }
                 if (signal_pending(current)) {
                     retval = -ERESTARTSYS;
                     break;
                 }
                 up_read(&tty->termios_rwsem);

                 timeout = wait_woken(&wait, TASK_INTERRUPTIBLE, *<=== 
BLOCKING HERE!*
                         timeout);

                 down_read(&tty->termios_rwsem);
                 continue;
             }
         }




More information about the Cygwin mailing list