classPiiFifoBuffer
#include <PiiFifoBuffer.h>
A first in first out I/O device.
Inherits QIODevice
Description
PiiFifoBuffer is a thread-safe buffer that can be read and written simultaneously. It reads and writes data into a fixed array in memory. PiiFifoBuffer can work as a replacement to QBuffer in situations where the amount of incoming data is unlimited.
Constructors and destructor
|
(
Create a new fifo buffer. |
|
|
( )
Destroy the buffer. |
Public member functions
|
bool
|
( )
|
|
void
|
( )
Tell the buffer that everything has been written. |
|
bool
|
( )
Returns true. |
|
qint64
|
( )
|
|
bool
|
( )
Move both reading and writing position to the beginning of the buffer. |
|
bool
|
(
Move the reading position. |
|
void
|
(
Set the number of millisecond a reader/writer will halted if no data is available for reading or there is no free space for writing. |
|
unsigned long
|
( )
Get the current wait time. |
Protected member functions
|
qint64
|
( )
|
|
qint64
|
(
Read at most |
|
qint64
|
(
Write at most |
Function details
-
PiiFifoBuffer
(- qint64 size
Create a new fifo buffer.
Parameters
- size
-
the number of bytes to reserve for the memory buffer
-
~PiiFifoBuffer
()Destroy the buffer.
-
bool atEnd
() -
void finishWriting
()Tell the buffer that everything has been written.
This informs possible readers that there is no more data to come, which helps in avoiding unnecessary waiting. Call reset() to start writing again.
-
bool isSequential
()Returns true.
-
qint64 pos
() -
bool reset
()Move both reading and writing position to the beginning of the buffer.
-
bool seek
(- qint64 pos
Move the reading position.
Writing is always sequential, but reading position can be changed in certain limits. Seeking backwards is supported only within the unget buffer. Seeking forwards is equal to skipping data, and can happen as far as the writer provides new data to skip.
-
void setWaitTime
(- unsigned long readWaitTime
Set the number of millisecond a reader/writer will halted if no data is available for reading or there is no free space for writing.
Reading/writing will continue as soon as new data is available or something has been read out. Zero means that if data is not immediately available, reading/writing will fail. The default value is 100.
-
unsigned long waitTime
()Get the current wait time.
-
qint64 bytesAvailable
()[protected] -
qint64 readData
(- char * data
- qint64 maxSize
[protected]Read at most
maxSizebytes intodata.In any case, the number of bytes that can be read is less than or equal to the size of the memory buffer. If less data has been written to the buffer, the number of bytes written so far limits the number of readable bytes.
If the buffer is empty, the calling thread will be halted for at most
waitTimemilliseconds. The wait will be interrupted as soon as new data is available. The function returns the number of bytes read. -
qint64 writeData
(- const char * data
- qint64 maxSize
[protected]Write at most
maxSizebytes fromdata.The capacity of the internal buffer limits the amount of data that can be written. Once the buffer is full, no data can be written before something is read out.
If the buffer is full, the calling thread will be blocked for at most
waitTimemilliseconds. The functioning is analogous to readData().
Add a note
Not a single note added yet. Be the first, add yours.