Subject: Handshaking on input overflow
To: None <current-users@sun-lamp.cs.berkeley.edu>
From: Niklas Hallqvist <niklas@appli.se>
List: current-users
Date: 08/09/1994 16:04:26
I'm having problems with input overflows generating all sorts of peculiarities,
so I took a look at the source.  There were some strange things in there I'd
like to ask about:

/*
 * Send stop character on input overflow.
 */
static void
ttyblock(tp)
	register struct tty *tp;
{
	register int total;

	total = tp->t_rawq.c_cc + tp->t_canq.c_cc;
	if (tp->t_rawq.c_cc > TTYHOG) {
		ttyflush(tp, FREAD | FWRITE);
		CLR(tp->t_state, TS_TBLOCK);
	}
	/*
	 * Block further input iff: current input > threshold
	 * AND input is available to user program.
	 */
	if (total >= TTYHOG / 2 &&
	    !ISSET(tp->t_state, TS_TBLOCK) &&
	    !ISSET(tp->t_lflag, ICANON) || tp->t_canq.c_cc > 0 &&
# Shouldn't the disjunction above be parenthesized?

	    tp->t_cc[VSTOP] != _POSIX_VDISABLE) {
# This test ought to be combined with ISSET(tp->t_iflag, IXOFF), no?
# It would also seem it ought to be moved into the conditional below
# as the test is irrelevant for CHWFLOW cases

		if (putc(tp->t_cc[VSTOP], &tp->t_outq) == 0) {
			SET(tp->t_state, TS_TBLOCK);
			ttstart(tp);
		}

		/* try to block remote output via hardware flow control */
		if (ISSET(tp->t_cflag, CHWFLOW) && tp->t_hwiflow &&
		    (*tp->t_hwiflow)(tp, 1) != 0)
# Is it correct that t_hwiflow() should return non-zero on success?

			SET(tp->t_state, TS_TBLOCK);
	}
}

I haven't seen any serial devices supporting t_hwiflow, so I suspect the
code for controlling input via hw is untested, which makes the possible
bugs above understandable.

Niklas

Niklas Hallqvist	Phone: +46-(0)31-40 75 00
Applitron Datasystem	Fax:   +46-(0)31-83 39 50
Molndalsvagen 95	Email: niklas@appli.se
S-412 63  GOTEBORG, Sweden

------------------------------------------------------------------------------