ESPHome 2026.4.0-dev
Loading...
Searching...
No Matches
api_overflow_buffer.h
Go to the documentation of this file.
1#pragma once
2#include <array>
3#include <cstdint>
4#include <sys/types.h>
5
7#ifdef USE_API
8
12
13namespace esphome::api {
14
26 public:
29 struct Entry {
30 uint8_t *data;
31 uint16_t size; // Total size of the buffer
32 uint16_t offset; // Current send offset within the buffer
33
34 uint16_t remaining() const { return this->size - this->offset; }
35 const uint8_t *current_data() const { return this->data + this->offset; }
36
38 static ESPHOME_ALWAYS_INLINE void destroy(Entry *entry) {
39 delete[] entry->data;
40 delete entry; // NOLINT(cppcoreguidelines-owning-memory)
41 }
42 };
43
45
47 bool empty() const { return this->count_ == 0; }
48
50 bool full() const { return this->count_ >= API_MAX_SEND_QUEUE; }
51
53 uint8_t count() const { return this->count_; }
54
61
65 bool enqueue_iov(const struct iovec *iov, int iovcnt, uint16_t total_len, uint16_t skip);
66
67 protected:
68 std::array<Entry *, API_MAX_SEND_QUEUE> queue_{};
69 uint8_t head_{0};
70 uint8_t tail_{0};
71 uint8_t count_{0};
72};
73
74} // namespace esphome::api
75
76#endif // USE_API
Circular queue of heap-allocated byte buffers used as a TCP send backlog.
bool empty() const
True when no backlogged data is waiting.
std::array< Entry *, API_MAX_SEND_QUEUE > queue_
bool full() const
True when the queue has no room for another entry.
bool enqueue_iov(const struct iovec *iov, int iovcnt, uint16_t total_len, uint16_t skip)
Enqueue unsent IOV data into the backlog.
uint8_t count() const
Number of entries currently queued.
ssize_t try_drain(socket::Socket *socket)
Try to drain queued data to the socket.
__int64 ssize_t
Definition httplib.h:178
A single heap-allocated send-backlog entry.
uint16_t offset
uint16_t remaining() const
uint8_t * data
const uint8_t * current_data() const
static ESPHOME_ALWAYS_INLINE void destroy(Entry *entry)
Free this entry and its data buffer.
uint16_t size