$darkmode
Kourier 1.0.0
Kourier::IOChannel Class Referenceabstract

The IOChannel class represents a buffered input/output channel. More...

Public Member Functions

 IOChannel (const size_t readBufferCapacity=0)
 
 ~IOChannel () override=default
 
void clear ()
 
virtual size_t dataAvailable () const
 
virtual size_t dataToWrite () const
 
std::string_view peekAll ()
 
char peekChar (size_t index) const
 
virtual size_t read (char *pBuffer, size_t maxSize)
 
virtual std::string_view readAll ()
 
size_t readBufferCapacity () const
 
Signal receivedData ()
 
bool reset ()
 
Signal sentData (size_t count)
 
bool setReadBufferCapacity (size_t capacity)
 
virtual size_t skip (size_t maxSize)
 
std::string_view slice (size_t pos, size_t count)
 
virtual size_t write (const char *pData, size_t count)
 
size_t write (std::string_view data)
 
- Public Member Functions inherited from Kourier::Object
 Object ()
 
virtual ~Object ()
 
void disconnect ()
 
template<class T_PtrToReceiverOrSignal >
void disconnect (T_PtrToReceiverOrSignal pReceiverOrSignal)
 
void scheduleForDeletion ()
 
template<class T >
tryCast ()
 
template<class T >
tryCast () const
 

Additional Inherited Members

- Static Public Member Functions inherited from Kourier::Object
template<class T_PtrToSignal , class T_PtrToSlot >
static void connect (MetaInvocable< T_PtrToSignal >::T_Class *pSender, T_PtrToSignal pSignal, MetaInvocable< T_PtrToSlot >::T_Class *pReceiver, T_PtrToSlot pSlot)
 
template<class T_PtrToSignal , class T_PtrToSlot >
static void connect (MetaInvocable< T_PtrToSignal >::T_Class *pSender, T_PtrToSignal pSignal, Object *pReceiver, T_PtrToSlot pSlot)
 
template<class T_PtrToSignal , class T_PtrToSlot >
static void connect (MetaInvocable< T_PtrToSignal >::T_Class *pSender, T_PtrToSignal pSignal, T_PtrToSlot pSlot)
 
template<class T_PtrToSignal , class T_PtrToSlot >
static void disconnect (Object *pSender, T_PtrToSignal pSignal, Object *pReceiver, T_PtrToSlot pSlot)
 

Detailed Description

The IOChannel class represents a buffered input/output channel.

IOChannel is the base class of TcpSocket and TlsSocket. IOChannel uses internal buffers to store the data that has to be written to the channel and the data that was read from it.

IOChannel emits the receivedData signal whenever it reads a new data payload from the channel. To prevent reading too much data, in the IOChannel's constructor, you can set the capacity of the internal read buffer that IOChannel uses to store data from the channel.

Writing to IOChannel never fails, as IOChannel grows the internal write buffer it uses to store data to be written to the channel. IOChannel emits the sentData signal whenever it writes to the channel data from its internal buffer. You can use the sentData signal to adjust data writing according to the channel bandwidth to prevent too much memory usage.

Constructor & Destructor Documentation

◆ IOChannel()

Kourier::IOChannel::IOChannel ( const size_t  readBufferCapacity = 0)

Creates the IOChannel. You can use readBufferCapacity to limit the capacity of the read buffer IOChannel uses to store data read from the channel. The read buffer can grow up to readBufferCapacity if it is positive. If readBufferCapacity is zero, no limit is set on how much the read buffer can grow.

◆ ~IOChannel()

Kourier::IOChannel::~IOChannel ( )
overridedefault

Destroys the object.

Member Function Documentation

◆ clear()

Kourier::IOChannel::clear ( )
inline

clears data in read/write buffers and restores them to their initial states. This method preserves the read buffer's capacity.

◆ dataAvailable()

Kourier::IOChannel::dataAvailable ( ) const
inlinevirtual

returns the size of the data IOChannel received from the channel and is available for reading.

◆ dataToWrite()

Kourier::IOChannel::dataToWrite ( ) const
inlinevirtual

returns the size of the data IOChannel has to write to the channel.

Reimplemented in Kourier::TlsSocket.

◆ peekAll()

Kourier::IOChannel::peekAll ( )
inline

returns all data in the read buffer without removing it from the buffer. The returned string view becomes invalid after you write to the IOChannel.

◆ peekChar()

Kourier::IOChannel::peekChar ( size_t  index) const
inline

returns the char at index position on the read buffer. index must be at most dataAvailable() - 1.

◆ read()

Kourier::IOChannel::read ( char *  pBuffer,
size_t  maxSize 
)
inlinevirtual

reads up to maxSize from the read buffer into the buffer pointed by pBuffer. Returns the number of bytes read from the read buffer.

Reimplemented in Kourier::TcpSocket, and Kourier::TlsSocket.

◆ readAll()

Kourier::IOChannel::readAll ( )
inlinevirtual

returns all data in the read buffer. Writing to IOChannel after calling this method invalidates the returned data.

Reimplemented in Kourier::TcpSocket, and Kourier::TlsSocket.

◆ readBufferCapacity()

Kourier::IOChannel::readBufferCapacity ( ) const
inline

returns the read buffer capacity. A value of zero means that capacity is not limited. If the returned value is positive, the read buffer can grow up to the returned value.

◆ receivedData()

Signal Kourier::IOChannel::receivedData ( )

IOChannel emits receivedData when data is read from the channel. dataAvailable informs how many bytes are available for reading.

◆ reset()

Kourier::IOChannel::reset ( )
inline

restores internal read/write buffers to their initial capacity. Buffers must be empty to be restored. Returns true if both read and write buffers were restored.

◆ sentData()

Signal Kourier::IOChannel::sentData ( size_t  count)

IOChannel emits the sentData signal when data is written to the channel. count informs how many bytes were written. dataToWrite informs how many bytes are still pending to be written to the channel.

◆ setReadBufferCapacity()

Kourier::IOChannel::setReadBufferCapacity ( size_t  capacity)
inline

Sets the read buffer capacity. A value of zero means that capacity is not limited. The read buffer can grow to the given value if capacity is positive. Returns true if the capacity was successfully changed. Setting capacity can fail because this method does not delete data that is available to be read. Thus, this method fails if capacity is smaller than the data available in the read buffer.

◆ skip()

Kourier::IOChannel::skip ( size_t  maxSize)
inlinevirtual

removes up to maxSize from the beginning of the read buffer. Returns the number of bytes removed.

Reimplemented in Kourier::TcpSocket, and Kourier::TlsSocket.

◆ slice()

Kourier::IOChannel::slice ( size_t  pos,
size_t  count 
)
inline

returns a slice of count bytes of data on the read buffer starting at pos. Writing to IOChannel after calling this method invalidates the returned data.

◆ write() [1/2]

Kourier::IOChannel::write ( const char *  pData,
size_t  count 
)
inlinevirtual

writes count bytes from the buffer pointed by pData into the write buffer.

Reimplemented in Kourier::TcpSocket.

◆ write() [2/2]

Kourier::IOChannel::write ( std::string_view  data)
inline

writes data into the write buffer.