Module nix::sys::termios [] [src]

An interface for controlling asynchronous communication ports

This interface provides a safe wrapper around the termios subsystem defined by POSIX. The underlying types are all implemented in libc for most platforms and either wrapped in safer types here or exported directly.

If you are unfamiliar with the termios API, you should first read the API documentation and then come back to understand how nix safely wraps it.

It should be noted that this API incurs some runtime overhead above the base libc definitions. As this interface is not used with high-bandwidth information, this should be fine in most cases. The primary cost when using this API is that the Termios datatype here duplicates the standard fields of the underlying termios struct and uses safe type wrappers for those fields. This means that when crossing the FFI interface to the underlying C library, data is first copied into the underlying termios struct, then the operation is done, and the data is copied back (with additional sanity checking) into the safe wrapper types. The termios struct is relatively small across all platforms (on the order of 32-64 bytes).

The following examples highlight some of the API use cases such that users coming from using C or reading the standard documentation will understand how to use the safe API exposed here.

Example disabling processing of the end-of-file control character:

termios.control_chars[VEOF as usize] = _POSIX_VDISABLE;

The flags within Termios are defined as bitfields using the bitflags crate. This provides an interface for working with bitfields that is similar to working with the raw unsigned integer types but offers type safety because of the internal checking that values will always be a valid combination of the defined flags.

An example showing some of the basic operations for interacting with the control flags:

termios.control_flags & CSIZE == CS5;
termios.control_flags |= CS5;

Structs

ControlFlags

Flags for setting the control mode of a terminal

InputFlags

Flags for configuring the input mode of a terminal

LocalFlags

Flags for setting any local modes

OutputFlags

Flags for configuring the output mode of a terminal

Termios

Stores settings for the termios API

Enums

BaudRate

Baud rates supported by the system

FlowArg

Specify how transmission flow should be altered

FlushArg

Specify a combination of the input and output buffers to flush

SetArg

Specify when a port configuration change should occur.

SpecialCharacterIndices

Indices into the termios.c_cc array for special characters.

Constants

BRKINT
BS0
BS1
BSDLY
CBAUD
CBAUDEX
CIBAUD
CLOCAL
CMSPAR
CR0
CR1
CR2
CR3
CRDLY
CREAD
CRTSCTS
CS5
CS6
CS7
CS8
CSIZE
CSTOPB
ECHO
ECHOCTL
ECHOE
ECHOK
ECHOKE
ECHONL
ECHOPRT
EXTPROC
FF0
FF1
FFDLY
FLUSHO
HUPCL
ICANON
ICRNL
IEXTEN
IGNBRK
IGNCR
IGNPAR
IMAXBEL
INLCR
INPCK
ISIG
ISTRIP
IUTF8
IXANY
IXOFF
IXON
NCCS
NL0
NL1
NLDLY
NOFLSH
OCRNL
OFDEL
OFILL
OLCUC
ONLCR
ONLRET
ONOCR
OPOST
PARENB
PARMRK
PARODD
PENDIN
TAB0
TAB1
TAB2
TAB3
TABDLY
TOSTOP
VT0
VT1
VTDLY
XTABS
_POSIX_VDISABLE

Functions

cfgetispeed

Get input baud rate (see cfgetispeed(3p)).

cfgetospeed

Get output baud rate (see cfgetospeed(3p)).

cfmakeraw

Configures the port to something like the "raw" mode of the old Version 7 terminal driver (see termios(3)).

cfsetispeed

Set input baud rate (see cfsetispeed(3p)).

cfsetospeed

Set output baud rate (see cfsetospeed(3p)).

cfsetspeed

Set both the input and output baud rates (see termios(3)).

tcdrain

Block until all output data is written (see tcdrain(3p)).

tcflow

Suspend or resume the transmission or reception of data (see tcflow(3p)).

tcflush

Discard data in the output or input queue (see tcflush(3p)).

tcgetattr

Return the configuration of a port tcgetattr(3p)).

tcgetsid

Get the session controlled by the given terminal (see tcgetsid(3)).

tcsendbreak

Send a break for a specific duration (see tcsendbreak(3p)).

tcsetattr

Set the configuration for a terminal (see tcsetattr(3p)).