tty patches for modem/fax control
Michael Anderson
mka@redes.int.com.mx
Mon Jun 2 17:59:00 GMT 1997
Following is the tty support code that I've been
working on. The code integrates Sergey Okhapkin's
patch, but no other changes. The files affected are:
fcntl.cc
fhandler.cc
fhandler.h
include/fcntl.h
include/sys/termios.h
termios.cc
The diff file, 0601tty.diff was produced by
restoring the original B18 distribution, applying
Sergey Okhapkin's patch and then diff'ing against
the changed version of the files listed above.
Patch, however, consistently fails to handle
fhandler.cc and fhandler.h (patch seems to be
generally buggy on my machine), so these two
files are included as separate attachments.
My tty projects seem to be working with these
code changes, but they should be considered
untested. No attempt has been made to accomodate
Win95 differences from WinNT. Consider these
changes to be a first attempt at the development
of a robust tty sub-system for eventual inclusion
in cygwin32, and anyone who wishes to test,
debug, correct, or re-implement is more than
welcome to have at it.
The code changes do not implement any part of
"struct termio"/ioctl() features, but rather the
"struct termios" and tcsetsttr() group of
functions. You will need to convert your code
from ioctl() to tc...() to use the new
features.
tcflush() has a previous implementation, which
is unchanged.
The tty features which have an implementation,
and their known limitations are listed:
1. The O_NDELAY flag to open() and fcntl()
causes the COMMTIMEOUTS structure to be
manipulated to put the file-handle in
blocking or non-blocking I/O mode. fcntl()
can be used to block/non-block in this
fashion:
/* non-blocking I/O */
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NDELAY);
/* blocking I/O */
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NDELAY);
O_NONBLOCK can be implemented by some
variation of:
#undef O_NONBLOCK
#define O_NONBLOCK O_NDELAY
Sergey Okhapkin has pointed-out that this
use of fcntl() may have an undesireable
side effect if used with the console or
(as yet non-existant) psuedo-ttys. The
fhandler_base class probably needs to be
augmented with an isaserialport() function
to clear this bug. I was afraid to change
the members of this class (I also wanted to
delete or enlarge the ofspeed and ifspeed
data members) thinking that it might break
already compiled programs. Is this correct?
2. tcgetattr() previously handled CBAUD (all
speeds through B38400, except B0), CSIZE,
ONLCR, and VTIME and VMIN for c_cc[].
New support is for B0, CLOCAL, CSTOPB,
PARENB, PARODD, INPCK, IGNPAR, IXON, IXOFF,
CRTSXOFF, CRTSCTS, and VSTART and VSTOP for
c_cc[].
3. tcsetattr() previously handled CBAUD
(except B0), CSIZE, PARENB, PARODD, IGNCR,
ONLCR, and VTIME and VMIN for c_cc[].
New support is for B0, CSTOPB, INPCK,
IGNPAR, IXON, IXOFF, CRTSXOFF, CRTSCTS,
and VSTART and VSTOP for c_cc[].
TCSANOW, TCSADRAIN, and TCSAFLUSH arguments
are implemented through calls to
FlushFileBuffers() and PurgeComm().
B0 should cause DTR to drop via a
call to EscapeCommFunction().
CLOCAL disables hardware flow-control and
DSR detection. CLOCAL does not disable
DTR lead control, which is often needed
for hanging-up a modem, nor does it affect
CD (carrier detect) in any way. This needs
an implementation so that the loss of
carrier generates the equivalent of SIGHUP.
Any ideas?
4. tcsendbreak() is implemented through calls to
SetCommBreak() and ClearCommBreak().
5. tcdrain() is implemented through a call to
FlushFileBuffers().
6. tcflow() is implemented for TCOOFF and TCOON
with a call to EscapeCommFunction(), and for
TCION and TCIOFF with a call to
TransmitCommChar(). The values in c_cc[VSTART]
and c_cc[VSTOP] are honored, if present,
otherwise 0x11 and 0x13 are used, respectively.
Because many of the termios flags are not supported,
a call to tcgetattr() will not return the same values
that the flags in the call to tcsetattr() specified.
Generally speaking, to more fully implement the tty
subsystem, more state needs to be held in the
fhandler_base or fhandler_tty class.
Good luck,
Mike Anderson
mka@redes.int.com.mk
Guanajuato, GTO, Mexico
More information about the Cygwin
mailing list