🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sun
Article #11224

Re: printer connections on Suns

#11224
From: Guy Harris
Date: Wed, 01 Mar 1989 21:04
53 lines
2789 bytes
>In my HP filter, I wait for the output to flush with this code:
>...
>	while(ioctl(fd, TIOCOUTQ, &outchars) == 0 && outchars > 0)

Wow.  That probably works (although I don't know that TIOCOUTQ will always
give the right answer), but under 3.x or 4.0 (or any V7/BSD-style tty
driver) the following should work better:

	struct sgtty sgttyb;

	(void) ioctl(fd, TIOCGETP, &sgttyb);
	(void) ioctl(fd, TIOCSETP, &sgttyb);

since, as it says in the 4.3-tahoe TTY(4):

	TIOCSETP
	     Set the parameters according to the pointed-to "sgttyb"
	     structure.  The interface delays until output is quiescent,
	     then throws away any unread characters, before changing the
	     modes.

Since you do a TIOCGETP followed immediately by a TIOCSETP, the modes
aren't changed; the only effects of the TIOCSETP are 1) it waits for
output to drain and 2) it flushes all input.  The latter is an unfortunate
side-effect, but it may not be a problem here.

I think all of the variants mentioned above, except 4.0, say much the same
thing.  4.0's TTCOMPAT(4M) basically says "TIOCSETP gets turned into a
TCSETSF", and 4.0's TERMIO(4) says about TCSETSF:

     TCSETSF        The argument is a pointer to a termios struc-
                    ture.   The  current  terminal parameters are
                    set from the values stored in that structure.
                    The change occurs after all characters queued
                    for output have been transmitted; all charac-
                    ters  queued for input are discarded and then
                    the change occurs.

which is basically the same set of side-effects as TIOCSETP.

In 4.0, though, and other systems that offer an S5-compatible tty driver,
there is an even better way; again from TERMIO(4):

     TCSBRK         The argument is an int value.  Wait  for  the
                    output  to drain.  If the argument is 0, then
                    send  a  break  (zero-valued  bits  for  0.25
                    seconds).

If the argument is *not* zero, no break is sent, so

	ioctl(fd, TCSBRK, 666);	/* insert your number here - beastly, eh? */

will just wait for output to drain.
Technical Details
Message-ID: <1038@auspex.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!csd4.milw.wisc.edu!leah!rpi!batcomputer!cornell!uw-beaver!rice!sun-spots-request
References: <8901130024.AA27274@> <1262@etive.ed.ac.uk> <1375@number1.step.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!csd4.milw.wisc.edu!leah!rpi!batcomputer!cornell!uw-beaver!rice!sun-spots-request
From: auspex!guy@uunet.uu.net (Guy Harris)
Newsgroups: comp.sys.sun
Subject: Re: printer connections on Suns
Message-ID: <1038@auspex.UUCP>
Date: 1 Mar 89 21:04:06 GMT
References: <8901130024.AA27274@> <1262@etive.ed.ac.uk> <1375@number1.step.UUCP>
Sender: usenet@rice.edu
Organization: Auspex Systems, Santa Clara
Lines: 53
Approved: Sun-Spots@rice.edu
Original-Date: 18 Feb 89 08:26:41 GMT
X-Sun-Spots-Digest: Volume 7, Issue 176, message 10 of 12