Open Lighting Architecture: ola::io::NonBlockingSender Class Reference

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
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

## ◆ NonBlockingSender()

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

  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.

## Member Function Documentation

## ◆ LimitReached()

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.

## ◆ SendMessage() [1/2]

bool ola::io::NonBlockingSender::SendMessage | ( | class IOStack * | stack | ) |

Send the contents of an IOStack on the ConnectedDescriptor.

Parameters

  stack | the 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.

## ◆ SendMessage() [2/2]

bool ola::io::NonBlockingSender::SendMessage | ( | IOQueue * | queue | ) |

Send the contents of an IOQueue on the ConnectedDescriptor.

Parameters

  queue | the 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

## ◆ DEFAULT_MAX_BUFFER_SIZE

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:

- include/ola/io/NonBlockingSender.h
- common/io/NonBlockingSender.cpp