$darkmode
Kourier 1.0.0
|
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) |
![]() | |
Object () | |
virtual | ~Object () |
void | disconnect () |
template<class T_PtrToReceiverOrSignal > | |
void | disconnect (T_PtrToReceiverOrSignal pReceiverOrSignal) |
void | scheduleForDeletion () |
template<class T > | |
T | tryCast () |
template<class T > | |
T | tryCast () const |
Additional Inherited Members | |
![]() | |
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) |
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.
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.
|
overridedefault |
Destroys the object.
|
inline |
clears data in read/write buffers and restores them to their initial states. This method preserves the read buffer's capacity.
|
inlinevirtual |
returns the size of the data IOChannel received from the channel and is available for reading.
|
inlinevirtual |
returns the size of the data IOChannel has to write to the channel.
Reimplemented in Kourier::TlsSocket.
|
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.
|
inline |
returns the char at index position on the read buffer. index must be at most dataAvailable() - 1.
|
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.
|
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.
|
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.
Signal Kourier::IOChannel::receivedData | ( | ) |
IOChannel emits receivedData when data is read from the channel. dataAvailable informs how many bytes are available for reading.
|
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.
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.
|
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.
|
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.
|
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.
|
inlinevirtual |
writes count bytes from the buffer pointed by pData into the write buffer.
Reimplemented in Kourier::TcpSocket.
|
inline |
writes data into the write buffer.