3#if defined(USE_SOCKET_IMPL_LWIP_TCP) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) || defined(USE_SOCKET_IMPL_BSD_SOCKETS)
14static constexpr int LISTEN_BACKLOG = 1;
21 this->
listen_->setsockopt(SOL_SOCKET, SO_REUSEADDR, &yes,
sizeof(yes));
26 if (this->
listen_->setblocking(
false) == 0 && local_len != 0 &&
27 this->listen_->bind(
reinterpret_cast<struct
sockaddr *
>(&local), local_len) == 0 &&
28 this->listen_->listen(LISTEN_BACKLOG) == 0) {
29 ESP_LOGI(this->
tag_,
"Listening on %u", link.
port());
36 ESP_LOGW(this->
tag_,
"Listen on %u failed: %d", link.
port(), err);
43 auto client = this->
listen_->accept_loop_monitored(
reinterpret_cast<struct
sockaddr *
>(&peer), &peer_len);
44 if (client ==
nullptr) {
46 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ECONNABORTED || errno == EINTR) {
52 ESP_LOGW(this->
tag_,
"Accept failed: %d", err);
56 const auto *sa =
reinterpret_cast<const struct
sockaddr *
>(&peer);
57#ifdef USE_SOCKET_IPV4_ALLOW
62 char text[SOCKADDR_STR_LEN];
64 link.
adopt(std::move(client));
65 ESP_LOGI(this->
tag_,
"Client connected from %s", text);
69#ifdef USE_SOCKET_IPV4_ALLOW
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
void dump_config(const char *tag) const
One config line per allowed network.
bool admit(const struct sockaddr *peer, socklen_t len, const char *tag, uint32_t now)
allows(peer), logging a refused peer at most once every REJECT_LOG_INTERVAL_MS.
A reconnecting TCP stream driven from loop().
void note_attempt()
Shared retry clock, also usable for a listen socket.
void adopt(std::unique_ptr< Socket > sock)
Take over an accepted socket (the server side of a bridge).
void dump_config() const
One config line per allowed network.
std::unique_ptr< ListenSocket > listen_
void try_listen_(TcpClientLink &link)
void accept_(TcpClientLink &link)
size_t format_sockaddr_to(const struct sockaddr *addr_ptr, socklen_t len, std::span< char, SOCKADDR_STR_LEN > buf)
Format sockaddr into caller-provided buffer, returns length written (excluding null)
socklen_t set_sockaddr_any(struct sockaddr *addr, socklen_t addrlen, uint16_t port)
Set a sockaddr to the any address and specified port for the IP version used by socket_ip().
std::unique_ptr< ListenSocket > socket_ip_loop_monitored(int type, int protocol)
Application App
Global storage of Application pointer - only one Application can exist.