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?
1 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.
-
1ok, thanks! I never really got the logic in the ixon/ixoff naming, I always wondered why they're not called "sendxoff" and "recvxoff" or something like that instead. (Anyway, now I can go back to being confused about other things!)– ilkkachuCommented Oct 4, 2019 at 9:16
-
What does
IXOFF
do for an ordinary (i.e., not pseudo) tty? Commented Oct 7, 2019 at 3:21 -
Also, your note about absence of need for flow control on pseudo terminals is not known to
gnome-terminal
(andxterm
) developers: pressing^S
in bash can be used to verify this. Commented Oct 7, 2019 at 3:23 -
@IgorLiferenko Whether the pty reacts to
^S
/^Q
is controlled by theIXON
, not theIXOFF
settings; I've expanded on that in the answer. The terminal emulator doesn't have to care about that at all -- it simply writes the^S
and^Q
characters into the master fd -- it's up to the tty driver to handle or not handle them.– user313992Commented Oct 7, 2019 at 4:52 -
So,
IXOFF
is the same asIXON
, but for the opposite side of the tty. Right? Commented Oct 7, 2019 at 5:09