|
ESPHome 2026.4.0-dev
|
Circular queue of heap-allocated byte buffers used as a TCP send backlog. More...
#include <api_overflow_buffer.h>
Data Structures | |
| struct | Entry |
| A single heap-allocated send-backlog entry. More... | |
Public Member Functions | |
| ~APIOverflowBuffer () | |
| bool | empty () const |
| True when no backlogged data is waiting. | |
| bool | full () const |
| True when the queue has no room for another entry. | |
| uint8_t | count () const |
| Number of entries currently queued. | |
| ssize_t | try_drain (socket::Socket *socket) |
| Try to drain queued data to the socket. | |
| bool | enqueue_iov (const struct iovec *iov, int iovcnt, uint16_t total_len, uint16_t skip) |
| Enqueue unsent IOV data into the backlog. | |
Protected Attributes | |
| std::array< Entry *, API_MAX_SEND_QUEUE > | queue_ {} |
| uint8_t | head_ {0} |
| uint8_t | tail_ {0} |
| uint8_t | count_ {0} |
Circular queue of heap-allocated byte buffers used as a TCP send backlog.
Under normal operation this buffer is never used — data goes straight from the frame helper to the socket. It only fills when the LWIP TCP send buffer is full (slow client, congested network, heavy logging). The queue drains automatically on subsequent write/loop calls once the socket becomes writable again.
Capacity is compile-time-fixed via API_MAX_SEND_QUEUE (set from Python config). If the queue fills completely the connection is marked failed.
Definition at line 25 of file api_overflow_buffer.h.
| esphome::api::APIOverflowBuffer::~APIOverflowBuffer | ( | ) |
Definition at line 7 of file api_overflow_buffer.cpp.
|
inline |
Number of entries currently queued.
Definition at line 53 of file api_overflow_buffer.h.
|
inline |
True when no backlogged data is waiting.
Definition at line 47 of file api_overflow_buffer.h.
| bool esphome::api::APIOverflowBuffer::enqueue_iov | ( | const struct iovec * | iov, |
| int | iovcnt, | ||
| uint16_t | total_len, | ||
| uint16_t | skip ) |
Enqueue unsent IOV data into the backlog.
Copies iov data starting at byte offset skip into a new entry. Returns false if the queue is full (caller should fail the connection).
Definition at line 42 of file api_overflow_buffer.cpp.
|
inline |
True when the queue has no room for another entry.
Definition at line 50 of file api_overflow_buffer.h.
| ssize_t esphome::api::APIOverflowBuffer::try_drain | ( | socket::Socket * | socket | ) |
Try to drain queued data to the socket.
Returns bytes-written > 0 on success/partial, 0 if all drained or no progress, -1 on error (caller must check errno to distinguish EWOULDBLOCK from hard errors). Callers only need to act on -1; 0 and positive values both mean "no error". Frees entries as they are fully sent.
Definition at line 14 of file api_overflow_buffer.cpp.
|
protected |
Definition at line 71 of file api_overflow_buffer.h.
|
protected |
Definition at line 69 of file api_overflow_buffer.h.
|
protected |
Definition at line 68 of file api_overflow_buffer.h.
|
protected |
Definition at line 70 of file api_overflow_buffer.h.