3#if defined(USE_SOCKET_IMPL_LWIP_TCP) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) || defined(USE_SOCKET_IMPL_BSD_SOCKETS)
18 this->
listen_->setsockopt(SOL_SOCKET, SO_REUSEADDR, &yes,
sizeof(yes));
23 if (this->
listen_->setblocking(
false) == 0 && local_len != 0 &&
24 this->listen_->bind(
reinterpret_cast<struct
sockaddr *
>(&local), local_len) == 0 &&
25 this->listen_->listen(backlog) == 0) {
26 ESP_LOGI(this->
tag_,
"Listening on %u", link.
port());
33 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) {
47 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ECONNABORTED || errno == ENOTCONN || errno == EINTR ||
48 errno == ENFILE || errno == EMFILE || errno == ENOBUFS || errno == ENOMEM) {
54 ESP_LOGW(this->
tag_,
"Accept failed: %d", err);
58 const auto *sa =
reinterpret_cast<const struct
sockaddr *
>(&peer);
59#ifdef USE_SOCKET_IPV4_ALLOW
64 char text[SOCKADDR_STR_LEN];
66 ESP_LOGI(this->
tag_,
"Client connected from %s", text);
71#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.
std::unique_ptr< Socket > accept(TcpClientLinkBase &link)
Accepts a waiting connection that the allow list admits, or returns nullptr.
void try_listen_(TcpClientLinkBase &link, uint8_t backlog)
void dump_config() const
One config line per allowed network.
std::unique_ptr< ListenSocket > listen_
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.