Public Member Functions | |
WebSocketInputStreambuf (Socket socket, size_t dataLength, uint8_t *pMask=nullptr, size_t bufferSize=2048) | |
Create a Web Socket input record streambuf. More... | |
~WebSocketInputStreambuf () | |
Destructor. | |
int_type | underflow () |
Handle the request to read data from the stream but we need more data from the source. | |
void | discard () |
Discard data for the record that has not yet been read. More... | |
size_t | getRecordSize () |
Get the size of the expected record. More... | |
WebSocketInputStreambuf::WebSocketInputStreambuf | ( | Socket | socket, |
size_t | dataLength, | ||
uint8_t * | pMask = nullptr , |
||
size_t | bufferSize = 2048 |
||
) |
Create a Web Socket input record streambuf.
[in] | socket | The socket we will be reading from. |
[in] | dataLength | The size of a record. |
[in] | bufferSize | The size of the buffer we wish to allocate to hold data. |
void WebSocketInputStreambuf::discard | ( | ) |
Discard data for the record that has not yet been read.
We are working on a logical fixed length record in a socket stream. This means that we know in advance how big the record should be. If we have read some data from the stream and no longer wish to consume any further, we have to discard the remaining bytes in the stream before we can get to process the next record. This function discards the remainder of the data.
For example, if our record size is 1000 bytes and we have read 700 bytes and determine that we no longer need to continue, we can't just stop. There are still 300 bytes in the socket stream that need to be consumed/discarded before we can move on to the next record.
size_t WebSocketInputStreambuf::getRecordSize | ( | ) |
Get the size of the expected record.