Open Lighting Architecture  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Attributes | List of all members
ola::io::NonBlockingSender Class Reference

Detailed Description

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.

Constructor & Destructor Documentation

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.

Parameters
descriptorthe ConnectedDescriptor to send on, ownership is not transferred.
ssthe SelectServer to use to register for on-write events.
memory_poolthe pool to return MemoryBlocks to
max_buffer_sizethe 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.

Member Function Documentation

bool ola::io::NonBlockingSender::LimitReached ( ) const

Check if the limit for the internal buffer has been reached.

Returns
true if the limit has been reached, false otherwise.
bool ola::io::NonBlockingSender::SendMessage ( class IOStack stack)

Send the contents of an IOStack on the ConnectedDescriptor.

Parameters
stackthe IOStack to send. All data in this stack will be sent and the stack will be emptied.
Returns
true if the contents of the stack were buffered for transmit, false the limit for this NonBlockingSender had already been reached.
bool ola::io::NonBlockingSender::SendMessage ( IOQueue queue)

Send the contents of an IOQueue on the ConnectedDescriptor.

Parameters
queuethe IOQueue to send. All data in this queue will be sent and the queue will be emptied.
Returns
true if the contents of the stack were buffered for transmit, false the limit for this NonBlockingSender had already been reached.

Member Data Documentation

const unsigned int ola::io::NonBlockingSender::DEFAULT_MAX_BUFFER_SIZE = 1024
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}.


The documentation for this class was generated from the following files: