DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Terminal device control

TTY in raw mode

In raw mode, characters are read and returned as is; that is, without being processed. Reading from a TTY device in raw mode is faster than reading from a TTY device in canonical mode. In the interest of efficiency, raw mode should be used when characters do not need to be canonically processed.

Just as in canonical mode, TTY devices that are in raw mode must deal with the problem of what to do when reading from a device for which characters are not available. The O_NDELAY flag only applies to TTY devices that are in canonical mode. The same function is provided by the MIN and TIME values for raw TTY devices. By choosing appropriate values of MIN and TIME, a programmer can help maximize efficiency when reading from TTY devices in raw mode.

The following function inputs a TTY that has previously been opened in raw mode and sets the MIN and TIME options to be 0 so that reads will not be blocked when characters are not available.

 1  #include <termio.h>
 2
 3  extern struct termio old_term;
 4
 5  setup2(fid)
 6  int fid;
 7  {
 8        struct termio new_term;
 9
10       if (ioctl(fid, TCGETA, &old_term) == -1)
11        {
12                printf("ioctl get failed.\n");
13                exit(1);
14        }
15
16        new_term = old_term;
17        new_term.c_lflag &= ~ICANON;
18        new_term.c_cc[VMIN] = 0;
19        new_term.c_cc[VTIME] = 0;
20
21        if (ioctl(fid, TCSETA, &new_term) == -1)
22        {
23                printf("ioctl set failed.\n");
24                exit(1);
25        }
26  }

Improving TTY performance - raw mode


Next topic: TTY flow control
Previous topic: Improving TTY performance - canonical mode

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004