---
name: "TTYStream"
section: "3cc"
platform: "linux"
package: "libcommoncpp2-dev"
version: "1.0.13-5"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/TTYStream"
---

# TTYStream(3cc)

TTY streams are used to represent serial connections that are fully 'streamable' objects using C++ stream classes and friends. streamable tty serial I/O class.

## NAME

TTYStream - TTY streams are used to represent serial connections that are fully 'streamable' objects using C++ stream classes and friends. streamable tty serial I/O class.

## SYNOPSIS

`#include <serial.h>`

Inherits **Serial**.

Inherited by **TTYSession**, and **ttystream**.

### Public Methods

**TTYStream** (const char \*filename, **timeout\_t** to=0)\
 *Create and open a tty serial port.* virtual **~TTYStream** ()\
 *End the tty stream and cleanup.* void **setTimeout** (**timeout\_t** to)\
 *Set the timeout control.* void **interactive** (bool flag)\
 *Set tty mode to buffered or 'interactive'.* int **sync** (void)\
 *Flushes the stream input and out buffers, writes pending output.* bool **isPending** (**Pending** pend, **timeout\_t** **timeout**=TIMEOUT\_INF)\
 *Get the status of pending operations.*

### Protected Methods

**TTYStream** ()\
 *This constructor is used to derive 'ttystream', a more C++ style version of the TTYStream class.* void **allocate** (void)\
 *Used to allocate the buffer space needed for iostream operations.* void **endStream** (void)\
 *Used to terminate the buffer space and clean up the tty connection.* int **underflow** (void)\
 *This streambuf method is used to load the input buffer through the established tty serial port.* int **uflow** (void)\
 *This streambuf method is used for doing unbuffered reads through the establish tty serial port when in interactive mode.* int **overflow** (int ch)\
 *This streambuf method is used to write the output buffer through the established tty port.*

### Protected Attributes

char \* **gbuf**\
 char \* **pbuf**\
 **timeout\_t** **timeout**\

### Friends

TTYStream & **crlf** (TTYStream &)\
 TTYStream & **lfcr** (TTYStream &)\

## DETAILED DESCRIPTION

TTY streams are used to represent serial connections that are fully 'streamable' objects using C++ stream classes and friends. streamable tty serial I/O class.

The first application relevant serial I/O class is the TTYStream class. TTYStream offers a linearly buffered 'streaming' I/O session with the serial device. Furthermore, traditional C++ 'stream' operators (\<\< and \>\>) may be used with the serial device. A more 'true' to ANSI C++ library format 'ttystream' is also available, and this supports an 'open' method in which one can pass initial serial device parameters immediately following the device name in a single string, as in '/dev/tty3a:9600,7,e,1', as an example.

The **TTYSession** aggragates a TTYStream and a Common C++ **Thread** which is assumed to be the execution context that will be used to perform actual I/O operations. This class is very anagolous to **TCPSession**.

**Author:**  David Sugar \<dyfet@ostel.com\>

## CONSTRUCTOR & DESTRUCTOR DOCUMENTATION

### TTYStream::TTYStream ()` [protected]`

This constructor is used to derive 'ttystream', a more C++ style version of the TTYStream class.

### TTYStream::TTYStream (const char \* filename, timeout\_t to = 0)

Create and open a tty serial port.

**Parameters:**

- *filename*

  *char name of device to open.*

- *to*

  *default timeout.*

### virtual TTYStream::~TTYStream ()` [virtual]`

*End the tty stream and cleanup.*

## MEMBER FUNCTION DOCUMENTATION

### void TTYStream::allocate (void)` [protected]`

*Used to allocate the buffer space needed for iostream operations.*

*This is based on MAX\_INPUT.*

### void TTYStream::endStream (void)` [protected]`

*Used to terminate the buffer space and clean up the tty connection.*

*This function is called by the destructor.*

### void TTYStream::interactive (bool flag)

*Set tty mode to buffered or 'interactive'.*

*When interactive, all streamed I/O is directly sent to the serial port immediately.*

**Parameters:**

- *flag*

  *bool set to true to make interactive.*

### bool TTYStream::isPending (Pending pend, timeout\_t timeout = TIMEOUT\_INF)` [virtual]`

*Get the status of pending operations.*

*This can be used to examine if input or output is waiting, or if an error has occured on the serial device. If read buffer contains data then input is ready and if write buffer contains data it is first flushed then checked.*

**Returns:**  *true if ready, false if timeout.*

**Parameters:**

- *pend*

  *ready check to perform.*

- *timeout*

  *in milliseconds.*

*Reimplemented from* **Serial***.*

### int TTYStream::overflow (int ch)` [protected]`

*This streambuf method is used to write the output buffer through the established tty port.*

**Parameters:**

- *ch*

  *char to push through.*

**Returns:**  *char pushed through.*

### void TTYStream::setTimeout (timeout\_t to)` [inline]`

*Set the timeout control.*

**Parameters:**

- *to*

  *timeout to use.*

### int TTYStream::sync (void)

*Flushes the stream input and out buffers, writes pending output.*

**Returns:**  *0 on success.*

### int TTYStream::uflow (void)` [protected]`

*This streambuf method is used for doing unbuffered reads through the establish tty serial port when in interactive mode.*

*Also this method will handle proper use of buffers if not in interative mode.*

**Returns:**  *char from tty serial port, EOF also possible.*

### int TTYStream::underflow (void)` [protected]`

*This streambuf method is used to load the input buffer through the established tty serial port.*

**Returns:**  *char from get buffer, EOF also possible.*

## FRIENDS AND RELATED FUNCTION DOCUMENTATION

### TTYStream& crlf (TTYStream &)` [friend]`

### TTYStream& lfcr (TTYStream &)` [friend]`

## MEMBER DATA DOCUMENTATION

### char\* TTYStream::gbuf` [protected]`

### char \* TTYStream::pbuf` [protected]`

### timeout\_t TTYStream::timeout` [protected]`

## AUTHOR

*Generated automatically by Doxygen for CommonC++ from the source code.*
