![]() |
TSDuck v3.45-4766
MPEG Transport Stream Toolkit
|
Interface class to read/write raw data from/to a stream. More...
#include <tsStreamInterface.h>

Public Member Functions | |
| virtual bool | asyncCompletedStream (NonBlockingDevice::IOSB *iosb)=0 |
| Update the status of an asynchronous readStream() or writeStream() after it completed. | |
| virtual bool | endOfStream ()=0 |
| Check if the end of stream was reached while reading. | |
| virtual bool | isReadStream ()=0 |
| Check if the stream is open for read. | |
| virtual bool | isWriteStream ()=0 |
| Check if the stream is open for write. | |
| virtual bool | readStream (void *addr, size_t max_size, size_t &ret_size, const AbortInterface *abort=nullptr, NonBlockingDevice::IOSB *iosb=nullptr)=0 |
| Read some data from the stream. | |
| virtual bool | readStream (void *addr, size_t size, const AbortInterface *abort=nullptr)=0 |
| Read complete data from the stream. | |
| virtual bool | writeStream (const void *addr, size_t size, NonBlockingDevice::IOSB *iosb=nullptr)=0 |
| Write data to the stream. | |
| virtual bool | writeStream (const void *addr, size_t size, size_t &written_size, NonBlockingDevice::IOSB *iosb=nullptr)=0 |
| Write some data to the stream. | |
Static Protected Member Functions | |
| template<class T > requires std::derived_from<T, StreamInterface> | |
| static bool | ReadStreamHelper (T *obj, void *addr, size_t size, const AbortInterface *abort) |
| Implementation helper for fixed-size version of readStream(). | |
| template<class T > requires std::derived_from<T, StreamInterface> | |
| static bool | WriteStreamHelper (T *obj, const void *addr, size_t size, NonBlockingDevice::IOSB *iosb) |
| Implementation helper for fixed-size version of writeStream(). | |
Interface class to read/write raw data from/to a stream.
|
pure virtual |
Write some data to the stream.
All bytes are written to the stream, blocking or retrying when necessary when the stream is in blocking mode. Return the number of actually written bytes if some error occurred before writing everything.
| [in] | addr | Address of the data to write. |
| [in] | size | Size in bytes of the data to write. |
| [out] | written_size | Actually written size in bytes. Can be less than size in case of error in the middle of the write. |
| [in,out] | iosb | Address of an IOSB structure. If non-null, the stream must be in non-blocking mode. When null, the stream must be in blocking mode (the default). See the description of ts::NonBlockingDevice::IOSB. Important: The parameter iosb should not be used by applications. It should be used only by "reactive classes", which work in combination with a Reactor. |
Implemented in ts::TCPConnection, ts::BinaryFile, ts::ForkPipe, and ts::TLSConnection.
|
pure virtual |
Write data to the stream.
All bytes are written to the stream, blocking or retrying when necessary when the stream is in blocking mode. The base implementation of writeStream() uses the virtual version with a written_size output parameter.
| [in] | addr | Address of the data to write. |
| [in] | size | Size in bytes of the data to write. |
| [in,out] | iosb | Address of an IOSB structure. If non-null, the stream must be in non-blocking mode. When null, the stream must be in blocking mode (the default). See the description of ts::NonBlockingDevice::IOSB. Important: The parameter iosb should not be used by applications. It should be used only by "reactive classes", which work in combination with a Reactor. |
Implemented in ts::TCPConnection, ts::BinaryFile, ts::ForkPipe, and ts::TLSConnection.
|
pure virtual |
Read some data from the stream.
Wait and read at least one byte. Don't try to read exactly max_size bytes. If ret_size is less than max_bytes, it is possible to read more.
| [out] | addr | Address of the buffer for the incoming data. |
| [in] | max_size | Maximum size in bytes of the buffer. |
| [out] | ret_size | Returned input size in bytes. If zero, end of file has been reached or an error occurred. |
| [in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
| [in,out] | iosb | Address of an IOSB structure. If non-null, the stream must be in non-blocking mode. When null, the stream must be in blocking mode (the default). See the description of ts::NonBlockingDevice::IOSB. Important: The parameter iosb should not be used by applications. It should be used only by "reactive classes", which work in combination with a Reactor. |
Implemented in ts::TCPConnection, ts::BinaryFile, ts::ForkPipe, and ts::TLSConnection.
|
pure virtual |
Read complete data from the stream.
Read exactly size bytes, waiting if necessary.
Synchronization: There is no iosb parameter because this method uses blocking I/O by design. An error is returned if the instance of the class which implements StreamInterface is in non-blocking mode.
| [out] | addr | Address of the buffer for the incoming data. |
| [in] | size | Size in bytes of the buffer. |
| [in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
Implemented in ts::TCPConnection, ts::BinaryFile, ts::ForkPipe, and ts::TLSConnection.
|
pure virtual |
Update the status of an asynchronous readStream() or writeStream() after it completed.
This method applies to asynchronous I/O only (Windows), not non-blocking I/O (UNIX).
| [in,out] | iosb | Address of the IOSB structure which was used when readStream() or writeStream() was called. |
Implemented in ts::TCPConnection, ts::BinaryFile, and ts::ForkPipe.
|
pure virtual |
Check if the stream is open for read.
Implemented in ts::TCPConnection, ts::BinaryFile, and ts::ForkPipe.
|
pure virtual |
Check if the stream is open for write.
Implemented in ts::TCPConnection, ts::BinaryFile, and ts::ForkPipe.
|
pure virtual |
Check if the end of stream was reached while reading.
Implemented in ts::TCPConnection, ts::BinaryFile, ts::ForkPipe, and ts::TSFile.
|
inlinestaticprotected |
Implementation helper for fixed-size version of writeStream().
Often, the fixed-size version can be implemented using the variable-size version. However, this works well at a given derivation stage only.
Assume that:
| T | A subclass of StreamInterface. Write data to the stream. All bytes are written to the stream, blocking or retrying when necessary when the stream is in blocking mode. The base implementation of writeStream() uses the virtual version with a written_size output parameter. |
| [in,out] | obj | Object of class T. |
| [in] | addr | Address of the data to write. |
| [in] | size | Size in bytes of the data to write. |
| [in,out] | iosb | Address of an IOSB structure. If non-null, the stream must be in non-blocking mode. When null, the stream must be in blocking mode (the default). See the description of ts::NonBlockingDevice::IOSB. Important: The parameter iosb should not be used by applications. It should be used only by "reactive classes", which work in combination with a Reactor. |
|
inlinestaticprotected |
Implementation helper for fixed-size version of readStream().
See writeStreamHelper() for a rationale.
| T | A subclass of StreamInterface. |
| [in,out] | obj | Object of class T. |
| [out] | addr | Address of the buffer for the incoming data. |
| [in] | size | Size in bytes of the buffer. |
| [in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |