---
name: "ost_SimpleTCPStream"
section: "3"
platform: "linux"
package: "libcommoncpp2-doc"
version: "1.8.1-10"
release: "Debian 11 (Bullseye)"
platforms: ["linux"]
url: "https://new.carta.tech/ost_SimpleTCPStream"
---

# ost\_SimpleTCPStream(3)

Simple TCP Stream, to be used with Common C++ Library.

## NAME

ost::SimpleTCPStream - Simple TCP Stream, to be used with Common C++ Library.

## SYNOPSIS

`#include <socket.h>`

Inherits **ost::Socket**.

### Public Member Functions

**SimpleTCPStream** (**TCPSocket** &server, size\_t size=512)\
 Create a TCP stream by accepting a connection from a bound TCP socket acting as a server.  **SimpleTCPStream** (const **IPV4Host** &host, **tpport\_t** port, size\_t size=512)\
 Create a TCP stream by connecting to a TCP socket (on a remote machine).  **SimpleTCPStream** (const **SimpleTCPStream** &source)\
 A copy constructor creates a new stream buffer.  virtual **~SimpleTCPStream** ()\
 Flush and empty all buffers, and then remove the allocated buffers.  bool **isPending** (**Pending** pend, **timeout\_t** timeout=**TIMEOUT\_INF**)\
 Get the status of pending stream data.  void **flush** ()\
 ssize\_t **read** (char \*bytes, size\_t length, **timeout\_t** timeout=0)\
 Read bytes into a buffer.  ssize\_t **write** (const char \*bytes, size\_t length, **timeout\_t** timeout=0)\
 Write bytes to buffer.  ssize\_t **peek** (char \*bytes, size\_t length, **timeout\_t** timeout=0)\
 Peek at the incoming data.

### Protected Member Functions

**SimpleTCPStream** ()\
 The constructor required for 'SimpleTCPStream', a more C++ style version of the **SimpleTCPStream** class.  void **endStream** (void)\
 Used to terminate the buffer space and cleanup the socket connection.  void **Connect** (const **IPV4Host** &host, **tpport\_t** port, size\_t size)\
 Create a TCP stream by connecting to a TCP socket (on a remote machine).

### Additional Inherited Members

## Detailed Description

Simple TCP Stream, to be used with Common C++ Library.

This source is derived from a proposal made by Ville Vainio (vvainio@tp.spt.fi).

**Author**

Mark S. Millard (msm@wizzer.com)

**Date**

2002-08-15 Copyright (C) 2002 Wizzer Works.

## Constructor & Destructor Documentation

### ost::SimpleTCPStream::SimpleTCPStream ()` [protected]`

The constructor required for 'SimpleTCPStream', a more C++ style version of the **SimpleTCPStream** class.

### ost::SimpleTCPStream::SimpleTCPStream (TCPSocket & server, size\_t size = `512`)

Create a TCP stream by accepting a connection from a bound TCP socket acting as a server. This performs an 'accept' call.

**Parameters**

*server* bound server tcp socket. \
 *size* of streaming input and output buffers.

### ost::SimpleTCPStream::SimpleTCPStream (const IPV4Host & host, tpport\_t port, size\_t size = `512`)

Create a TCP stream by connecting to a TCP socket (on a remote machine).

**Parameters**

*host* address of remote TCP server. \
 *port* number to connect. \
 *size* of streaming input and output buffers.

### ost::SimpleTCPStream::SimpleTCPStream (const SimpleTCPStream & source)

A copy constructor creates a new stream buffer.

**Parameters**

*source* A reference to the **SimpleTCPStream** to copy.

### virtual ost::SimpleTCPStream::~SimpleTCPStream ()` [virtual]`

Flush and empty all buffers, and then remove the allocated buffers.

## Member Function Documentation

### void ost::SimpleTCPStream::Connect (const IPV4Host & host, tpport\_t port, size\_t size)` [protected]`

Create a TCP stream by connecting to a TCP socket (on a remote machine).

**Parameters**

*host* address of remote TCP server. \
 *port* number to connect. \
 *size* of streaming input and output buffers.

### void ost::SimpleTCPStream::endStream (void)` [protected]`

Used to terminate the buffer space and cleanup the socket connection. This fucntion is called by the destructor.

### void ost::SimpleTCPStream::flush ()` [inline]`

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

Get the status of pending stream data. This method can be used to examine if input or output is waiting, or if an error or disconnect has occured on the stream. If a read buffer contains data then input is ready. If write buffer contains data, it is first flushed and then checked.

**Parameters**

*pend* Flag indicating means to pend. \
 *timeout* The length of time to wait.

Reimplemented from **ost::Socket**.

### ssize\_t ost::SimpleTCPStream::peek (char \* bytes, size\_t length, timeout\_t timeout = `0`)

Peek at the incoming data. The data is copied into the buffer but is not removed from the input queue. The function then returns the number of bytes currently pending to receive.

**Parameters**

*bytes* A pointer to buffer that will contain the bytes read. \
 *length* The number of bytes to read (exactly). \
 *timeout* Period to time out, in milleseconds.

**Returns**

The number of bytes pending on the input queue, 0 on EOF.

### ssize\_t ost::SimpleTCPStream::read (char \* bytes, size\_t length, timeout\_t timeout = `0`)

Read bytes into a buffer. \<long-description\>

**Parameters**

*bytes* A pointer to buffer that will contain the bytes read. \
 *length* The number of bytes to read (exactly). \
 *timeout* Period to time out, in milleseconds.

**Returns**

The number of bytes actually read, 0 on EOF.

### ssize\_t ost::SimpleTCPStream::write (const char \* bytes, size\_t length, timeout\_t timeout = `0`)

Write bytes to buffer. \<long-description\>

**Parameters**

*bytes* A pointer to a buffer containing the bytes to write. \
 *length* The number of bytes to write (exactly). \
 *timeout* Period to time out, in milleseconds.

**Returns**

The number of bytes actually written.

## Author

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