summaryrefslogtreecommitdiffstats
path: root/sys/kern/tty.c
diff options
context:
space:
mode:
authorkn <kn@openbsd.org>2019-07-09 18:59:15 +0000
committerkn <kn@openbsd.org>2019-07-09 18:59:15 +0000
commit9af84a410835fd75fc87ecc7daf08145187a62a6 (patch)
treeeba32c5b476163668b64e16ef75913cab9265e9a /sys/kern/tty.c
parentGroup tls_{handshake,read,write,close}() return values documentation. (diff)
downloadwireguard-openbsd-9af84a410835fd75fc87ecc7daf08145187a62a6.tar.xz
wireguard-openbsd-9af84a410835fd75fc87ecc7daf08145187a62a6.zip
Use timeout_add_msec(9)
As per termios(4), "VTIME is a timer of 0.1 second granularity", so convert it to milliseconds by reducing by hz and multiplying with 1000. Furthermore, the specification (and our implementation) define members of the c_cc arry to be of type unsigned char, so both the previous as well as the now used arithmetic operations are guaranteed to not overflow. Since the timeout_add(9) API takes an int argument, the previous long type would always be demoted anyway, so change it to int directly. With this and hz gone, remove the obselete comment. While here, use more mnemonic variable names. Feedback and OK mpi
Diffstat (limited to 'sys/kern/tty.c')
-rw-r--r--sys/kern/tty.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index e4ad73ddd3d..3f892fe8df8 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.146 2019/06/01 14:11:17 mpi Exp $ */
+/* $OpenBSD: tty.c,v 1.147 2019/07/09 18:59:15 kn Exp $ */
/* $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $ */
/*-
@@ -1497,43 +1497,36 @@ 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 min = cc[VMIN];
+ int time = cc[VTIME] * 100; /* tenths of a second (ms) */
qp = &tp->t_rawq;
/*
* Check each of the four combinations.
- * (m > 0 && t == 0) is the normal read case.
+ * (min > 0 && time == 0) is the normal read case.
* It should be fairly efficient, so we check that and its
- * companion case (m == 0 && t == 0) first.
+ * companion case (min == 0 && time == 0) first.
*/
- if (t == 0) {
- if (qp->c_cc < m)
+ if (time == 0) {
+ if (qp->c_cc < min)
goto sleep;
goto read;
}
- if (m > 0) {
+ if (min > 0) {
if (qp->c_cc <= 0)
goto sleep;
- if (qp->c_cc >= m)
+ if (qp->c_cc >= min)
goto read;
if (stime == NULL) {
alloc_timer:
stime = malloc(sizeof(*stime), M_TEMP, M_WAITOK);
timeout_set(stime, ttvtimeout, tp);
- timeout_add(stime, t);
+ timeout_add_msec(stime, time);
} else if (qp->c_cc > last_cc) {
/* got a character, restart timer */
- timeout_add(stime, t);
+ timeout_add_msec(stime, time);
}
- } else { /* m == 0 */
+ } else { /* min == 0 */
if (qp->c_cc > 0)
goto read;
if (stime == NULL) {