Open Lighting Architecture
0.9.4
|
Write data to ConnectedDescriptors without blocking or losing data.
A NonBlockingSender handles writing data from IOStacks or IOQueues to a ConnectedDescriptor. On calling SendMessage() the data from the stack or queue is 0-copied to an internal buffer and then as much as possible is written to the ConnectedDescriptor using scatter/gather I/O calls (if available). If there is more data than fits in the descriptor's socket buffer, the remaining data is held in the internal buffer.
The internal buffer has a limit on the size. Once the limit is exceeded, calls to SendMessage() will return false. The limit is a soft limit however, a call to SendMessage() may cause the buffer to exceed the internal limit, provided the limit has not already been reached.
Public Member Functions | |
NonBlockingSender (ola::io::ConnectedDescriptor *descriptor, ola::io::SelectServerInterface *ss, ola::io::MemoryBlockPool *memory_pool, unsigned int max_buffer_size=DEFAULT_MAX_BUFFER_SIZE) | |
Create a new NonBlockingSender. | |
~NonBlockingSender () | |
Destructor. | |
bool | LimitReached () const |
Check if the limit for the internal buffer has been reached. | |
bool | SendMessage (class IOStack *stack) |
Send the contents of an IOStack on the ConnectedDescriptor. | |
bool | SendMessage (IOQueue *queue) |
Send the contents of an IOQueue on the ConnectedDescriptor. |
Static Public Attributes | |
static const unsigned int | DEFAULT_MAX_BUFFER_SIZE = 1024 |
The default max internal buffer size. |
ola::io::NonBlockingSender::NonBlockingSender | ( | ola::io::ConnectedDescriptor * | descriptor, |
ola::io::SelectServerInterface * | ss, | ||
ola::io::MemoryBlockPool * | memory_pool, | ||
unsigned int | max_buffer_size = DEFAULT_MAX_BUFFER_SIZE |
||
) |
Create a new NonBlockingSender.
descriptor | the ConnectedDescriptor to send on, ownership is not transferred. |
ss | the SelectServer to use to register for on-write events. |
memory_pool | the pool to return MemoryBlocks to |
max_buffer_size | the maximum amount of data to buffer. Note that because the underlying MemoryBlocks may be partially used, this does not reflect the actual amount of memory used (in pathological cases we may allocate up to max_buffer_size * memory_block_size bytes. |
bool ola::io::NonBlockingSender::LimitReached | ( | ) | const |
Check if the limit for the internal buffer has been reached.
bool ola::io::NonBlockingSender::SendMessage | ( | class IOStack * | stack | ) |
Send the contents of an IOStack on the ConnectedDescriptor.
stack | the IOStack to send. All data in this stack will be sent and the stack will be emptied. |
bool ola::io::NonBlockingSender::SendMessage | ( | IOQueue * | queue | ) |
Send the contents of an IOQueue on the ConnectedDescriptor.
queue | the IOQueue to send. All data in this queue will be sent and the queue will be emptied. |
|
static |
The default max internal buffer size.
Once this limit has been reached, calls to SendMessage() will return false.
1k is probably enough for userspace. The Linux kernel default is 4k, tunable via /proc/sys/net/core/wmem_{max,default}.