|
ESPHome 2026.9.0
|
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) |
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.
|
inline |
True when no backlogged data is waiting.
Definition at line 25 of file api_overflow_buffer.h.
| 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.
|
inline |
Free the retained storage, now if empty, otherwise once it has drained.
Definition at line 38 of file api_overflow_buffer.h.
|
inlinestaticconstexprprotected |
Definition at line 54 of file api_overflow_buffer.h.
| 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.
|
protected |
Definition at line 56 of file api_overflow_buffer.h.
|
staticconstexprprotected |
Definition at line 48 of file api_overflow_buffer.h.
|
protected |
Definition at line 58 of file api_overflow_buffer.h.
|
protected |
Definition at line 61 of file api_overflow_buffer.h.
|
staticconstexprprotected |
Definition at line 50 of file api_overflow_buffer.h.
|
protected |
Definition at line 57 of file api_overflow_buffer.h.
|
staticconstexprprotected |
Definition at line 47 of file api_overflow_buffer.h.
|
staticconstexprprotected |
Definition at line 53 of file api_overflow_buffer.h.
|
staticconstexprprotected |
Definition at line 52 of file api_overflow_buffer.h.
|
protected |
Definition at line 62 of file api_overflow_buffer.h.