Yate: Stream Class Reference

Yate

Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Stream Class Referenceabstract

An abstract stream class capable of reading and writing. More...

`#include <yateclass.h>`

Inheritance diagram for Stream:

## Public Types
enum | SeekPos { SeekBegin , SeekEnd , SeekCurrent }

## Public Member Functions
virtual | ~Stream ()
int | error () const
virtual bool | terminate ()=0
virtual bool | canRetry () const
virtual bool | inProgress () const
virtual bool | valid () const =0
virtual bool | setBlocking (bool block=true)
virtual int | writeData (const void *buffer, int length)=0
int | writeData (const char *str)
int | writeData (const String &str)
int | writeData (const DataBlock &buf)
virtual int | readData (void *buffer, int length)=0
virtual int64_t | length ()
virtual int64_t | seek (SeekPos pos, int64_t offset=0)
int64_t | seek (int64_t offset)

## Static Public Member Functions
static bool | allocPipe (Stream *&reader, Stream *&writer)
static bool | allocPair (Stream *&str1, Stream *&str2)
static bool | supportsPipes ()
static bool | supportsPairs ()

## Protected Member Functions
| Stream ()
void | clearError ()

## Protected Attributes
int | m_error

## Detailed Description

An abstract stream class capable of reading and writing.

Base class for encapsulating system dependent stream capable objects

## Member Enumeration Documentation

## ◆ SeekPos

enum SeekPos

Enumerate seek start position

## Constructor & Destructor Documentation

## ◆ ~Stream()

virtual ~Stream | ( |  | ) |
| virtual

Destructor, terminates the stream

## ◆ Stream()

Stream | ( |  | ) |
| inlineprotected

Default constructor

Referenced by allocPair(), and allocPipe().

## Member Function Documentation

## ◆ allocPair()

bool allocPair | ( | Stream *& | str1,
|  | Stream *& | str2 )
| static

Allocate a new pair of bidirectionally connected streams

Parameters

  str1 | Reference of a pointer receiving the newly allocated 1st end of the pair
  str2 | Reference of a pointer receiving the newly allocated 2nd end of the pair

Returns
  True is the stream pair was created successfully

References Stream().

## ◆ allocPipe()

bool allocPipe | ( | Stream *& | reader,
|  | Stream *& | writer )
| static

Allocate a new pair of unidirectionally pipe connected streams

Parameters

  reader | Reference of a pointer receiving the newly allocated reading side of the pipe
  writer | Reference of a pointer receiving the newly allocated writing side of the pipe

Returns
  True is the stream pipe was created successfully

References Stream().

## ◆ canRetry()

virtual bool canRetry | ( |  | ) | const
| virtual

Check if the last error code indicates a retryable condition

Returns
  True if error was temporary and operation should be retried

Reimplemented in File, and Socket.

## ◆ clearError()

void clearError | ( |  | ) |
| inlineprotected

Clear the last error code

## ◆ error()

int error | ( |  | ) | const
| inline

Get the error code of the last operation on this stream

Returns
  Error code generated by the last operation on this stream

Referenced by File::exists(), File::getFileTime(), File::listDirectory(), File::md5(), File::mkDir(), File::remove(), File::rename(), File::rmDir(), and File::setFileTime().

## ◆ inProgress()

virtual bool inProgress | ( |  | ) | const
| virtual

Check if the last error code indicates a non blocking operation in progress

Returns
  True if a non blocking operation is in progress

Reimplemented in Socket.

## ◆ length()

virtual int64_t length | ( |  | ) |
| virtual

Find the length of the stream if it has one

Returns
  Length of the stream or zero if length is not defined

Reimplemented in File, and MemoryStream.

Referenced by Socket::applyFilters(), Socket::getOption(), Socket::readData(), readData(), Socket::recv(), Socket::recvFrom(), Socket::recvFrom(), SctpSocket::recvMsg(), Socket::send(), SctpSocket::sendMsg(), SctpSocket::sendTo(), Socket::sendTo(), Socket::sendTo(), Socket::setOption(), Socket::writeData(), and writeData().

## ◆ readData()

virtual int readData | ( | void * | buffer,
|  | int | length )
| pure virtual

Receive data from a connected stream

Parameters

  buffer | Buffer for data transfer
  length | Length of the buffer

Returns
  Number of bytes transferred, negative if an error occurred

Implemented in File, MemoryStream, and Socket.

References length().

## ◆ seek() [1/2]

int64_t seek | ( | int64_t | offset | ) |
| inline

Set the read/write pointer from begin of stream

Parameters

  offset | The position in stream to move the pointer

Returns
  The new position of the stream read/write pointer. Negative on failure

References seek().

## ◆ seek() [2/2]

virtual int64_t seek | ( | SeekPos | pos,
|  | int64_t | offset = 0 )
| virtual

Set the stream read/write pointer

Parameters

  pos | The seek start as enumeration
  offset | The number of bytes to move the pointer from starting position

Returns
  The new position of the stream read/write pointer. Negative on failure

Reimplemented in File, and MemoryStream.

Referenced by seek().

## ◆ setBlocking()

virtual bool setBlocking | ( | bool | block = true | ) |
| virtual

Set the blocking or non-blocking operation mode of the stream

Parameters

  block | True if I/O operations should block, false for non-blocking

Returns
  True if operation was successfull, false if an error occured

Reimplemented in File, and Socket.

## ◆ supportsPairs()

bool supportsPairs | ( |  | ) |
| static

Check if operating system supports bidirectional stream pairs

Returns
  True if bidirectional pairs can be created

## ◆ supportsPipes()

bool supportsPipes | ( |  | ) |
| static

Check if operating system supports unidirectional stream pairs

Returns
  True if unidirectional pipes can be created

## ◆ terminate()

virtual bool terminate | ( |  | ) |
| pure virtual

Closes the stream

Returns
  True if the stream was (already) closed, false if an error occured

Implemented in File, MemoryStream, and Socket.

## ◆ valid()

virtual bool valid | ( |  | ) | const
| pure virtual

Check if this stream is valid

Returns
  True if the stream is valid, false if it's invalid or closed

Implemented in File, MemoryStream, and Socket.

## ◆ writeData() [1/4]

int writeData | ( | const char * | str | ) |

Write a C string to a connected stream

Parameters

  str | String to send over the stream

Returns
  Number of bytes transferred, negative if an error occurred

## ◆ writeData() [2/4]

int writeData | ( | const DataBlock & | buf | ) |
| inline

Write a Data block to a connected stream

Parameters

  buf | DataBlock to send over the stream

Returns
  Number of bytes transferred, negative if an error occurred

References DataBlock::data(), DataBlock::length(), and writeData().

## ◆ writeData() [3/4]

int writeData | ( | const String & | str | ) |
| inline

Write a String to a connected stream

Parameters

  str | String to send over the stream

Returns
  Number of bytes transferred, negative if an error occurred

References String::c_str(), String::length(), and writeData().

## ◆ writeData() [4/4]

virtual int writeData | ( | const void * | buffer,
|  | int | length )
| pure virtual

Write data to a connected stream

Parameters

  buffer | Buffer for data transfer
  length | Length of the buffer

Returns
  Number of bytes transferred, negative if an error occurred

Implemented in File, MemoryStream, and Socket.

References length().

Referenced by writeData(), and writeData().

The documentation for this class was generated from the following file:

- yateclass.h