ESPHome
2026.4.0-dev
Loading...
Searching...
No Matches
esphome
components
api
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
6
#include "
esphome/core/defines.h
"
7
#ifdef USE_API
8
9
#include "
esphome/components/socket/headers.h
"
10
#include "
esphome/components/socket/socket.h
"
11
#include "
esphome/core/helpers.h
"
12
13
namespace
esphome::api
{
14
25
class
APIOverflowBuffer
{
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
44
~APIOverflowBuffer
();
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
60
ssize_t
try_drain
(
socket::Socket
*socket);
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
esphome::api::APIOverflowBuffer
Circular queue of heap-allocated byte buffers used as a TCP send backlog.
Definition
api_overflow_buffer.h:25
esphome::api::APIOverflowBuffer::count_
uint8_t count_
Definition
api_overflow_buffer.h:71
esphome::api::APIOverflowBuffer::empty
bool empty() const
True when no backlogged data is waiting.
Definition
api_overflow_buffer.h:47
esphome::api::APIOverflowBuffer::queue_
std::array< Entry *, API_MAX_SEND_QUEUE > queue_
Definition
api_overflow_buffer.h:68
esphome::api::APIOverflowBuffer::full
bool full() const
True when the queue has no room for another entry.
Definition
api_overflow_buffer.h:50
esphome::api::APIOverflowBuffer::enqueue_iov
bool enqueue_iov(const struct iovec *iov, int iovcnt, uint16_t total_len, uint16_t skip)
Enqueue unsent IOV data into the backlog.
Definition
api_overflow_buffer.cpp:42
esphome::api::APIOverflowBuffer::~APIOverflowBuffer
~APIOverflowBuffer()
Definition
api_overflow_buffer.cpp:7
esphome::api::APIOverflowBuffer::tail_
uint8_t tail_
Definition
api_overflow_buffer.h:70
esphome::api::APIOverflowBuffer::count
uint8_t count() const
Number of entries currently queued.
Definition
api_overflow_buffer.h:53
esphome::api::APIOverflowBuffer::try_drain
ssize_t try_drain(socket::Socket *socket)
Try to drain queued data to the socket.
Definition
api_overflow_buffer.cpp:14
esphome::api::APIOverflowBuffer::head_
uint8_t head_
Definition
api_overflow_buffer.h:69
esphome::socket::BSDSocketImpl
Definition
bsd_sockets_impl.h:22
defines.h
headers.h
helpers.h
ssize_t
__int64 ssize_t
Definition
httplib.h:178
esphome::api
Definition
api_buffer.cpp:3
socket.h
esphome::api::APIOverflowBuffer::Entry
A single heap-allocated send-backlog entry.
Definition
api_overflow_buffer.h:29
esphome::api::APIOverflowBuffer::Entry::offset
uint16_t offset
Definition
api_overflow_buffer.h:32
esphome::api::APIOverflowBuffer::Entry::remaining
uint16_t remaining() const
Definition
api_overflow_buffer.h:34
esphome::api::APIOverflowBuffer::Entry::data
uint8_t * data
Definition
api_overflow_buffer.h:30
esphome::api::APIOverflowBuffer::Entry::current_data
const uint8_t * current_data() const
Definition
api_overflow_buffer.h:35
esphome::api::APIOverflowBuffer::Entry::destroy
static ESPHOME_ALWAYS_INLINE void destroy(Entry *entry)
Free this entry and its data buffer.
Definition
api_overflow_buffer.h:38
esphome::api::APIOverflowBuffer::Entry::size
uint16_t size
Definition
api_overflow_buffer.h:31
iovec
Definition
headers.h:102
Generated by
1.12.0