|
ESPHome 2026.12.0-dev
|
A link with its own outgoing buffer. More...
#include <tcp_client_link.h>
Public Member Functions | |
| size_t | queue (const uint8_t *data, size_t len) |
| Copy into the outgoing buffer; returns how many bytes fit. | |
| uint8_t * | tx_tail () |
| Direct access to the buffer's free tail. | |
| bool | flush_tx () |
| Send the front of the buffer; true once it is empty. | |
Public Member Functions inherited from esphome::socket::TcpClientLinkBase | |
| void | set_host (const char *host) |
| void | set_port (uint16_t port) |
| void | set_reconnect_interval (uint32_t ms) |
| void | set_idle_timeout (uint32_t ms) |
| 0 leaves the link up. | |
| const char * | host () const |
| uint16_t | port () const |
| uint32_t | reconnect_interval () const |
| uint32_t | idle_timeout () const |
| void | begin (const char *tag) |
| Call from setup(). tag names this link's log lines. | |
| void | poll () |
| Connect state machine; call every loop while acting as a client. | |
| void | adopt (std::unique_ptr< Socket > sock) |
| Take over an accepted socket (the server side of a bridge). | |
| ssize_t | read (uint8_t *buf, size_t len) |
| Returns bytes moved, 0 when nothing can move now, -1 when the link dropped. | |
| void | tx_commit (size_t len) |
| size_t | tx_free () const |
| void | close () |
| Close without scheduling a reconnect (shutdown). | |
| void | note_io () |
| Restart the idle clock. | |
| uint32_t | last_io () const |
| When a byte last moved, or note_io() last ran. | |
| void | check_idle () |
| Close when no byte has moved for idle_timeout(). Inline: the close runs only once that time has passed. | |
| bool | connected () const |
| bool | connecting () const |
| A connect attempt is in flight. | |
| bool | ready () const |
| void | note_attempt () |
| Shared retry clock, also usable for a listen socket. | |
| bool | in_backoff () const |
Protected Attributes | |
| uint8_t | tx_ [TX_BUFFER_SIZE] {} |
Protected Attributes inherited from esphome::socket::TcpClientLinkBase | |
| StringRef | host_ |
| std::unique_ptr< Socket > | sock_ |
| const char * | tag_ {nullptr} |
| uint32_t | last_attempt_ms_ {0} |
| uint32_t | reconnect_interval_ms_ {5000} |
| uint32_t | last_io_ms_ {0} |
| uint32_t | idle_timeout_ms_ {0} |
| Ipv4Resolve | resolved_ |
| uint16_t | port_ {0} |
| uint16_t | tx_len_ {0} |
| bool | connected_ {false} |
Additional Inherited Members | |
Static Public Attributes inherited from esphome::socket::TcpClientLinkBase | |
| static constexpr size_t | TX_BUFFER_SIZE = 1024 |
Protected Member Functions inherited from esphome::socket::TcpClientLinkBase | |
| size_t | queue_ (uint8_t *tx, const uint8_t *data, size_t len) |
| queue() and flush_tx() of the subclasses, on the buffer they keep. | |
| bool | flush_tx_ (uint8_t *tx) |
| ssize_t | write_ (const uint8_t *buf, size_t len) |
| The raw stream write behind flush_tx(); drops the link on a fatal error. | |
| void | flush_tx_slow_ (uint8_t *tx) |
| void | poll_slow_ () |
| void | try_connect_ () |
| void | drop_ (const LogString *what, int err) |
| Close after a failure, log what and errno, schedule the next attempt. | |
| void | idle_close_ () |
| Log and close after check_idle() saw the timeout pass; schedules the next attempt like a failure. | |
A link with its own outgoing buffer.
Definition at line 112 of file tcp_client_link.h.
|
inline |
Send the front of the buffer; true once it is empty.
A partial write keeps the rest; inline no-op while nothing is queued.
Definition at line 121 of file tcp_client_link.h.
|
inline |
Copy into the outgoing buffer; returns how many bytes fit.
Definition at line 115 of file tcp_client_link.h.
|
inline |
Direct access to the buffer's free tail.
Fill at most tx_free() bytes, then tx_commit() the count; neither is bounds checked.
Definition at line 118 of file tcp_client_link.h.
|
protected |
Definition at line 124 of file tcp_client_link.h.