warren@ihnss.UUCP (Warren Montgomery) (09/18/84)
I have an application where I want to change the "local characters" associated with a tty synchronously with output. (i.e., wait until the output queue is empty, and then make the change). I have asked several local experts, and alas nobody has a way of doing it. There seems to be no direct way (i.e. no ioctl that does just this), and no indirect way (no ioctl that just waits until output becomes quiescent and nothing else). This is such an obvious thing to want to do, I can't believe that it is really impossible. For people familiar with the AT&T unix tty system, what I want is the equivalent of the TCSETAW ioctl. Does anybody have any hints on how to do this? Is there any way just to wait until the output queue is empty and then issue the proper ioctl? If there is something that works for 4.2, does it work in any of the other berkeley variants? Thanks for any advice you can give. -- Warren Montgomery ihnss!warren IH (8-367) x2494
chris@umcp-cs.UUCP (Chris Torek) (09/21/84)
If you do a TIOCSETP, that will wait for the output to drain; you
can then do TIOCSETC and SLTC and whatever else. So you might do
something like this:
/* Change the terminal characters (start, stop, etc) after the output
has drained. Since 4.2 doesn't provide a set-after-wait ioctl for
struct tchars, we have to use TIOCSETP to allow the output to drain.
To do this we need a TIOCGETP so that we don't actually change
anything. Furthermore, someone should ensure that all this is done
only in the foreground so that we don't get stopped and maybe have
the tty characteristics change between the GETP and the SETP. */
SetCharsAfterWait (fd, t)
int fd;
struct tchars *t;
{
struct sgttyb sg;
(void) ioctl (fd, TIOCGETP, &sg);
(void) ioctl (fd, TIOCSETP, &sg);
(void) ioctl (fd, TIOCSETC, t);
}
--
(This page accidently left blank.)
In-Real-Life: Chris Torek, Univ of MD Comp Sci (301) 454-7690
UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet: chris@umcp-cs ARPA: chris@maryland
gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (09/21/84)
TCSETAW is one thing that I couldn't figure out how to do right in the BRL UNIX System V emulation for 4.2BSD. If there is a way to mimic this on an unmodified 4.2BSD I also would like to hear about it. {decvax,esquire,research}!brl-bmd!gwyn (UUCP) gwyn@brl-vld.ARPA
warren@ihnss.UUCP (Warren Montgomery) (09/24/84)
Thanks to all who responded to my questions on 4.2BSD tty ioctls There are two imperfect solutions to the problem of how to wait for output to drain before getting an ioctl to take place: 1) Use TIOCSETP with the current parameters, and then set whatever you want. This works fine, but flushes the input queue, which was unacceptable in my application. 2) Use the poorly documented TIOCOUTQ ioctl to find the current size of the output queue and busy wait while it goes to zero. You can busy wait with less resource consumption by delaying for an amount of time computed to allow the queue to drain at full speed at the current baud rate. The most convenient way to do this is using select() with only the timeout value to do the waiting. A couple of people suggested using the select call directly, with the tty as one of the write file descriptors to wait for, but as other pointed out this does not work, since select waits only until the driver will accept more characters for output, not until output has drained. These seem to be the best options available. It's a shame that the Berkeley tty ioctls aren't more orthogonal, allowing independent control of more of the capabilities, but that's life! -- Warren Montgomery ihnss!warren IH (8-367) x2494