A reconnecting TCP stream driven from loop().
More...
#include <tcp_client_link.h>
|
| 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 reconnecting TCP stream driven from loop().
Owns the socket, the DNS lookup, the retry backoff and the fill level of the outgoing buffer; TcpClientLink and TcpClientLinkSharedTx add where its bytes live. A fatal read/write error closes the link and schedules the next attempt; the caller sees the edge via connected().
Definition at line 23 of file tcp_client_link.h.
◆ adopt()
| void esphome::socket::TcpClientLinkBase::adopt |
( |
std::unique_ptr< Socket > | sock | ) |
|
Take over an accepted socket (the server side of a bridge).
Definition at line 102 of file tcp_client_link.cpp.
◆ begin()
| void esphome::socket::TcpClientLinkBase::begin |
( |
const char * | tag | ) |
|
◆ check_idle()
| void esphome::socket::TcpClientLinkBase::check_idle |
( |
| ) |
|
|
inline |
◆ close()
| void esphome::socket::TcpClientLinkBase::close |
( |
| ) |
|
◆ connected()
| bool esphome::socket::TcpClientLinkBase::connected |
( |
| ) |
const |
|
inline |
◆ connecting()
| bool esphome::socket::TcpClientLinkBase::connecting |
( |
| ) |
const |
|
inline |
◆ drop_()
| void esphome::socket::TcpClientLinkBase::drop_ |
( |
const LogString * | what, |
|
|
int | err ) |
|
protected |
Close after a failure, log what and errno, schedule the next attempt.
Definition at line 175 of file tcp_client_link.cpp.
◆ flush_tx_()
| bool esphome::socket::TcpClientLinkBase::flush_tx_ |
( |
uint8_t * | tx | ) |
|
|
inlineprotected |
◆ flush_tx_slow_()
| void esphome::socket::TcpClientLinkBase::flush_tx_slow_ |
( |
uint8_t * | tx | ) |
|
|
protected |
◆ host()
| const char * esphome::socket::TcpClientLinkBase::host |
( |
| ) |
const |
|
inline |
◆ idle_close_()
| void esphome::socket::TcpClientLinkBase::idle_close_ |
( |
| ) |
|
|
protected |
◆ idle_timeout()
| uint32_t esphome::socket::TcpClientLinkBase::idle_timeout |
( |
| ) |
const |
|
inline |
◆ in_backoff()
| bool esphome::socket::TcpClientLinkBase::in_backoff |
( |
| ) |
const |
|
inline |
◆ last_io()
| uint32_t esphome::socket::TcpClientLinkBase::last_io |
( |
| ) |
const |
|
inline |
◆ note_attempt()
| void esphome::socket::TcpClientLinkBase::note_attempt |
( |
| ) |
|
|
inline |
Shared retry clock, also usable for a listen socket.
Definition at line 74 of file tcp_client_link.h.
◆ note_io()
| void esphome::socket::TcpClientLinkBase::note_io |
( |
| ) |
|
|
inline |
Restart the idle clock.
A consumer that cannot take more bytes calls this, so a full buffer is not treated as a quiet peer.
Definition at line 58 of file tcp_client_link.h.
◆ poll()
| void esphome::socket::TcpClientLinkBase::poll |
( |
| ) |
|
|
inline |
Connect state machine; call every loop while acting as a client.
Inline no-op while connected or waiting out the backoff.
Definition at line 42 of file tcp_client_link.h.
◆ poll_slow_()
| void esphome::socket::TcpClientLinkBase::poll_slow_ |
( |
| ) |
|
|
protected |
◆ port()
| uint16_t esphome::socket::TcpClientLinkBase::port |
( |
| ) |
const |
|
inline |
◆ queue_()
| size_t esphome::socket::TcpClientLinkBase::queue_ |
( |
uint8_t * | tx, |
|
|
const uint8_t * | data, |
|
|
size_t | len ) |
|
protected |
queue() and flush_tx() of the subclasses, on the buffer they keep.
Definition at line 144 of file tcp_client_link.cpp.
◆ read()
| ssize_t esphome::socket::TcpClientLinkBase::read |
( |
uint8_t * | buf, |
|
|
size_t | len ) |
Returns bytes moved, 0 when nothing can move now, -1 when the link dropped.
Definition at line 110 of file tcp_client_link.cpp.
◆ ready()
| bool esphome::socket::TcpClientLinkBase::ready |
( |
| ) |
const |
|
inline |
◆ reconnect_interval()
| uint32_t esphome::socket::TcpClientLinkBase::reconnect_interval |
( |
| ) |
const |
|
inline |
◆ set_host()
| void esphome::socket::TcpClientLinkBase::set_host |
( |
const char * | host | ) |
|
|
inline |
◆ set_idle_timeout()
| void esphome::socket::TcpClientLinkBase::set_idle_timeout |
( |
uint32_t | ms | ) |
|
|
inline |
0 leaves the link up.
A full local buffer is not idle: the caller notes that with note_io(), because the peer may still be sending.
Definition at line 32 of file tcp_client_link.h.
◆ set_port()
| void esphome::socket::TcpClientLinkBase::set_port |
( |
uint16_t | port | ) |
|
|
inline |
◆ set_reconnect_interval()
| void esphome::socket::TcpClientLinkBase::set_reconnect_interval |
( |
uint32_t | ms | ) |
|
|
inline |
◆ try_connect_()
| void esphome::socket::TcpClientLinkBase::try_connect_ |
( |
| ) |
|
|
protected |
◆ tx_commit()
| void esphome::socket::TcpClientLinkBase::tx_commit |
( |
size_t | len | ) |
|
|
inline |
◆ tx_free()
| size_t esphome::socket::TcpClientLinkBase::tx_free |
( |
| ) |
const |
|
inline |
◆ write_()
| ssize_t esphome::socket::TcpClientLinkBase::write_ |
( |
const uint8_t * | buf, |
|
|
size_t | len ) |
|
protected |
The raw stream write behind flush_tx(); drops the link on a fatal error.
Definition at line 126 of file tcp_client_link.cpp.
◆ connected_
| bool esphome::socket::TcpClientLinkBase::connected_ {false} |
|
protected |
◆ host_
| StringRef esphome::socket::TcpClientLinkBase::host_ |
|
protected |
◆ idle_timeout_ms_
| uint32_t esphome::socket::TcpClientLinkBase::idle_timeout_ms_ {0} |
|
protected |
◆ last_attempt_ms_
| uint32_t esphome::socket::TcpClientLinkBase::last_attempt_ms_ {0} |
|
protected |
◆ last_io_ms_
| uint32_t esphome::socket::TcpClientLinkBase::last_io_ms_ {0} |
|
protected |
◆ port_
| uint16_t esphome::socket::TcpClientLinkBase::port_ {0} |
|
protected |
◆ reconnect_interval_ms_
| uint32_t esphome::socket::TcpClientLinkBase::reconnect_interval_ms_ {5000} |
|
protected |
◆ resolved_
| Ipv4Resolve esphome::socket::TcpClientLinkBase::resolved_ |
|
protected |
◆ sock_
| std::unique_ptr<Socket> esphome::socket::TcpClientLinkBase::sock_ |
|
protected |
◆ tag_
| const char* esphome::socket::TcpClientLinkBase::tag_ {nullptr} |
|
protected |
◆ TX_BUFFER_SIZE
| size_t esphome::socket::TcpClientLinkBase::TX_BUFFER_SIZE = 1024 |
|
staticconstexpr |
◆ tx_len_
| uint16_t esphome::socket::TcpClientLinkBase::tx_len_ {0} |
|
protected |
The documentation for this class was generated from the following files: