ESPHome 2026.9.0
Loading...
Searching...
No Matches
esphome::api::APIOverflowBuffer Class Reference

TCP send backlog, only used when the socket send buffer is full. More...

#include <api_overflow_buffer.h>

Public Member Functions

bool empty () const
 True when no backlogged data is waiting.
 
ssize_t try_drain (socket::Socket *socket)
 Drain queued messages to the socket.
 
bool enqueue_iov (const struct iovec *iov, int iovcnt, size_t total_len, size_t skip)
 Queue iov data from byte offset skip as one message.
 
void release ()
 Free the retained storage, now if empty, otherwise once it has drained.
 

Static Protected Member Functions

static constexpr size_t reserve_for (size_t want)
 

Protected Attributes

APIBuffer buf_
 
uint16_t head_ {0}
 
uint8_t count_ {0}
 
bool draining_: 1 {false}
 
bool release_when_drained_: 1 {false}
 

Static Protected Attributes

static constexpr size_t LEN_PREFIX = 2
 
static constexpr size_t BYTES_PER_SLOT = 2048
 
static constexpr size_t GROW_QUANTUM = 256
 
static constexpr size_t MAX_LONE_BYTES = APIBuffer::MAX_SIZE & ~(GROW_QUANTUM - 1)
 
static constexpr size_t MAX_BYTES = std::min(API_MAX_SEND_QUEUE * BYTES_PER_SLOT, MAX_LONE_BYTES)
 

Detailed Description

TCP send backlog, only used when the socket send buffer is full.

One contiguous buffer per connection, allocated on the first stall and kept at its high-water mark so a lossy link does not churn the heap. Messages are stored as a 2 byte length prefix plus payload. API_MAX_SEND_QUEUE bounds queued messages and, at 2 KB per slot, queued bytes; exceeding either fails the connection.

Definition at line 22 of file api_overflow_buffer.h.

Member Function Documentation

◆ empty()

bool esphome::api::APIOverflowBuffer::empty ( ) const
inline

True when no backlogged data is waiting.

Definition at line 25 of file api_overflow_buffer.h.

◆ enqueue_iov()

bool esphome::api::APIOverflowBuffer::enqueue_iov ( const struct iovec * iov,
int iovcnt,
size_t total_len,
size_t skip )

Queue iov data from byte offset skip as one message.

Returns false when a limit is hit, allocation fails, or storage would move during a drain; the caller should fail the connection.

Definition at line 48 of file api_overflow_buffer.cpp.

◆ release()

void esphome::api::APIOverflowBuffer::release ( )
inline

Free the retained storage, now if empty, otherwise once it has drained.

Definition at line 38 of file api_overflow_buffer.h.

◆ reserve_for()

static constexpr size_t esphome::api::APIOverflowBuffer::reserve_for ( size_t want)
inlinestaticconstexprprotected

Definition at line 54 of file api_overflow_buffer.h.

◆ try_drain()

ssize_t esphome::api::APIOverflowBuffer::try_drain ( socket::Socket * socket)

Drain queued messages to the socket.

Returns bytes written, 0 for a re-entrant call, -1 on error (check errno for EWOULDBLOCK); callers only need to act on -1.

Definition at line 7 of file api_overflow_buffer.cpp.

Field Documentation

◆ buf_

APIBuffer esphome::api::APIOverflowBuffer::buf_
protected

Definition at line 56 of file api_overflow_buffer.h.

◆ BYTES_PER_SLOT

size_t esphome::api::APIOverflowBuffer::BYTES_PER_SLOT = 2048
staticconstexprprotected

Definition at line 48 of file api_overflow_buffer.h.

◆ count_

uint8_t esphome::api::APIOverflowBuffer::count_ {0}
protected

Definition at line 58 of file api_overflow_buffer.h.

◆ draining_

bool esphome::api::APIOverflowBuffer::draining_
protected

Definition at line 61 of file api_overflow_buffer.h.

◆ GROW_QUANTUM

size_t esphome::api::APIOverflowBuffer::GROW_QUANTUM = 256
staticconstexprprotected

Definition at line 50 of file api_overflow_buffer.h.

◆ head_

uint16_t esphome::api::APIOverflowBuffer::head_ {0}
protected

Definition at line 57 of file api_overflow_buffer.h.

◆ LEN_PREFIX

size_t esphome::api::APIOverflowBuffer::LEN_PREFIX = 2
staticconstexprprotected

Definition at line 47 of file api_overflow_buffer.h.

◆ MAX_BYTES

size_t esphome::api::APIOverflowBuffer::MAX_BYTES = std::min(API_MAX_SEND_QUEUE * BYTES_PER_SLOT, MAX_LONE_BYTES)
staticconstexprprotected

Definition at line 53 of file api_overflow_buffer.h.

◆ MAX_LONE_BYTES

size_t esphome::api::APIOverflowBuffer::MAX_LONE_BYTES = APIBuffer::MAX_SIZE & ~(GROW_QUANTUM - 1)
staticconstexprprotected

Definition at line 52 of file api_overflow_buffer.h.

◆ release_when_drained_

bool esphome::api::APIOverflowBuffer::release_when_drained_
protected

Definition at line 62 of file api_overflow_buffer.h.


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