Pipes and custom streams

The Pipe class can be used to provide custom streams for the ACSE and DIMSE services.

A separate thread must be used to feed a Pipe (to supply a custom reading stream) or to sink data from a Pipe (to provide a custom writing stream).

Pipe

class Pipe : public imebra::BaseStreamInput, public imebra::BaseStreamOutput

A Pipe can be used to push and pull data to/from an Imebra codec.

This is useful when an Imebra codec must be used with a data source or a data sink not supported by the library (e.g. a TLS stream).

In order to allow Imebra to read data from a custom data source:

  • allocate a Pipe class and use it as parameter for the StreamReader needed by the codec
  • from a secondary thread feed the data to the data source by calling feed()

In order to allow Imebra to write data to a custom data source:

  • allocate a Pipe class and use it as parameter for the StreamWriter needed by the codec
  • from a secondary thread read the data to feed to the data sink by calling sink()

Public Functions

Pipe(size_t circularBufferSize)

Constructor.

Parameters
  • circularBufferSize: the size of the buffer that stores the data fed to the Pipe until it is fetched

void feed(const ReadMemory &buffer)

Copy data into the Pipe so it can be retrieved by a codec via a StreamReader.

Parameters
  • buffer: the data to copy into the Pipe’s buffer

size_t sink(ReadWriteMemory &buffer)

Read data from the Pipe. The data can be pushed into the pipe via a StreamWriter.

Return
the number of bytes read from the pipe, which may be less than the buffer’s size
Parameters
  • buffer: a buffer that will contain the read data. The method will try to read as many bytes as the buffer size

void close(unsigned int timeoutMilliseconds)

Wait for the specified amount of time or until the internal buffer is empty (all the data fed has been retrieved by the StreamReader or by sink()), whichever comes first, then call terminate().

Subsequent read and write operations will fail by throwing the exception StreamClosedError.

Parameters
  • timeoutMilliseconds: the maximum time to wait until the internal buffer is empty, in milliseconds

void terminate()

Instruct any pending operation to terminate.

Current and subsequent read and write operations will fail by throwing the exception StreamClosedError.