TTY – Difference Between IXON and IXOFF TTY Attributes

ptytty

To be specific, let's speak in pseudo-terminal terms. Suppose we have file descriptors master and slave for a pseudo-terminal pair (suppose it is a controlling tty). Disabling IXON on master (or slave, which works the same) means that when we do write(master, &control_s_code, 1), read(slave, &byte, 1) will get this code. The same concerns control_q_code. The question is: what does disabling IXOFF do?

Best Answer

IXOFF is not implemented on pseudo-ttys, and setting IXOFF on a pseudo-tty has no effect whatsoever.

IXOFF should cause the tty driver to send a VSTOP character to the other side when its input queue is full (which should prevent it from sending in more data), and a VSTART character when it has processed it and there's place for more data.

This is different from IXON, which will cause the tty driver to respect the VSTART/VSTOP characters sent from the other side, and upon receiving a VSTOP (^S) character, stop any transmission until a VSTART (^Q) character is received.

In the case of a pseudo-tty, the "other side" is the master pty, eg. your terminal emulator; when you press ^S, it's the IXON, not the IXOFF setting which will cause the slave tty to stop echoing back the entered characters and displaying the data written to it (which will be queued until the output queue is full, when any write(2) to the slave tty will either block or return EAGAIN).

Implementing flow control on pseudo-ttys is not needed, because the kernel always knows (by checking a struct field or similar) whether the input queue of the slave has filled up, and can just block the process writing to the master pty.

The software flow control is only useful when using a real serial connection without out-of-band signals like RTS/CTS: unlike any Unix, TCP or other "pipe" abstraction, a wire is not buffering and will not fill up and block until the receiver has read all the state changes off it.