This is read(2)ing form a tty(4) device.  More specifically,
only non-canonical mode.  From X/Open 4.2:

        MIN represents the minimum number of bytes that should be
        received when the read() function returns successfully. TIME is
        a timer of 0.1 second granularity that is used to time out
        bursty and short-term data transmissions.

So TIME is `cc[VTIME] / 10' and this diff changes the timeout from
(TIME * hz) [ticks] to (TIME * 1000) [ms].

With stty(1) one can set mode and values, see the "[-]icanon", "min" and
"time" options:  Staying in the shell prompt won't exercise all
differences and the shell's mode mattters, but typing into cat(1) after
changing mode and values show immediate effects.

Besides running with this diff on X230 as daily driver, this is also how
I played around and tested.


Wondering why `t' is of type long even though it gets demoted to int
as timeout_add(9) expects it and given `cc[VTIME]' is of type u_char
(where U_CHAR_MAX = 0xff = 255), it follows that `cc[VTIME] * 1000'
never exceeds 255000 (much smaller than INT_MAX), so use int directly.

With this and `hz' gone, the comment seems obsolete, so remove it.

Am I missing something?
Feedback? OK?

Index: kern/tty.c
===================================================================
RCS file: /cvs/src/sys/kern/tty.c,v
retrieving revision 1.146
diff -u -p -r1.146 tty.c
--- kern/tty.c  1 Jun 2019 14:11:17 -0000       1.146
+++ kern/tty.c  8 Jul 2019 19:05:16 -0000
@@ -1498,14 +1498,7 @@ loop:    lflag = tp->t_lflag;
        s = spltty();
        if (!ISSET(lflag, ICANON)) {
                int m = cc[VMIN];
-               long t;
-
-               /*
-                * Note - since cc[VTIME] is a u_char, this won't overflow
-                * until we have 32-bit longs and a hz > 8388608.
-                * Hopefully this code and 32-bit longs are obsolete by then.
-                */
-               t = cc[VTIME] * hz / 10;
+               int t = cc[VTIME] * 1000 / 10;  /* milliseconds */
 
                qp = &tp->t_rawq;
                /*
@@ -1528,10 +1521,10 @@ loop:   lflag = tp->t_lflag;
 alloc_timer:
                                stime = malloc(sizeof(*stime), M_TEMP, 
M_WAITOK);
                                timeout_set(stime, ttvtimeout, tp);
-                               timeout_add(stime, t);
+                               timeout_add_msec(stime, t);
                        } else if (qp->c_cc > last_cc) {
                                /* got a character, restart timer */
-                               timeout_add(stime, t);
+                               timeout_add_msec(stime, t);
                        }
                } else {        /* m == 0 */
                        if (qp->c_cc > 0)

Reply via email to