Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
MaxLengthStream Class Reference

Stream wrapper that limits the number of bytes sent to the child stream, and reports EOF after the given length. More...

#include <SyncStream.hxx>

Inheritance diagram for MaxLengthStream:
WrappedStream SyncStream

Public Member Functions

 MaxLengthStream (size_t length, SyncStream *delegate)
 
ssize_t write (const void *data, size_t len) override
 Main entry point to the data consumption.
 
- Public Member Functions inherited from WrappedStream
 WrappedStream (SyncStream *delegate)
 
void set_delegate (SyncStream *delegate)
 Overrides the target where to send the incoming data onwards.
 
int finalize (int status) override
 Called once after all data has been written to close the stream and release resources.
 
- Public Member Functions inherited from SyncStream
ssize_t write_all (const void *data, size_t len)
 Repeatedly writes until all data has been consumed or an error occurs.
 

Private Attributes

size_t remaining_
 How many bytes we still have to write.
 

Additional Inherited Members

- Static Protected Member Functions inherited from SyncStream
static const uint8_t * to_8 (const void *d)
 Converts a void pointer to an equivalent byte pointer.
 
static uint8_t * to_8 (void *d)
 Converts a void pointer to an equivalent byte pointer.
 
- Protected Attributes inherited from WrappedStream
std::unique_ptr< SyncStreamdelegate_
 Where to write the data to.
 

Detailed Description

Stream wrapper that limits the number of bytes sent to the child stream, and reports EOF after the given length.

Definition at line 186 of file SyncStream.hxx.

Constructor & Destructor Documentation

◆ MaxLengthStream()

MaxLengthStream::MaxLengthStream ( size_t  length,
SyncStream delegate 
)
inline
Parameters
lengthis the number of bytes after which to report error.
delegateis the wrapped stream. Takes ownership of the pointer.

Definition at line 191 of file SyncStream.hxx.

◆ ~MaxLengthStream()

MaxLengthStream::~MaxLengthStream ( )
inline

Definition at line 197 of file SyncStream.hxx.

Member Function Documentation

◆ write()

ssize_t MaxLengthStream::write ( const void *  data,
size_t  len 
)
inlineoverridevirtual

Main entry point to the data consumption.

Parameters
datais the pointer to a block of data to consume.
lenis the number of bytes to consume.
Returns
0 if the stream is completed/EOF (not consuming data anymore); negative value if there is an error; or the number of bytes consumed from the stream.

Implements SyncStream.

Definition at line 201 of file SyncStream.hxx.

Member Data Documentation

◆ remaining_

size_t MaxLengthStream::remaining_
private

How many bytes we still have to write.

Definition at line 222 of file SyncStream.hxx.


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