ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
lwip_fast_select.h
Go to the documentation of this file.
1#pragma once
2
3// Fast socket monitoring for ESP32 and LibreTiny (LwIP >= 2.1.3)
4// Replaces lwip_select() with direct rcvevent reads and FreeRTOS task notifications.
5
6#include <stdbool.h>
7#include <stdint.h>
8
9// Forward declare lwip_sock for C++ callers that store cached pointers.
10// The full definition is only available in the .c file (lwip/priv/sockets_priv.h
11// conflicts with C++ compilation units).
12struct lwip_sock;
13
14// Byte offset of rcvevent (s16_t) within struct lwip_sock.
15// Verified at compile time in lwip_fast_select.c via _Static_assert.
16// Anonymous enum for a compile-time constant that works in both C and C++.
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
26struct lwip_sock *esphome_lwip_get_sock(int fd);
27
40static inline bool esphome_lwip_socket_has_data(struct lwip_sock *sock) {
41#ifdef ESPHOME_THREAD_MULTI_ATOMICS
42 return *(int16_t *) ((char *) sock + (int) ESPHOME_LWIP_SOCK_RCVEVENT_OFFSET) > 0;
43#else
44 return *(volatile int16_t *) ((char *) sock + (int) ESPHOME_LWIP_SOCK_RCVEVENT_OFFSET) > 0;
45#endif
46}
47
52void esphome_lwip_hook_socket(struct lwip_sock *sock);
53
58void esphome_fast_select_set_ota_listener_sock(struct lwip_sock *sock);
59
65bool esphome_lwip_set_nodelay(struct lwip_sock *sock, bool enable);
66
67#ifdef __cplusplus
68}
69#endif
bool esphome_lwip_set_nodelay(struct lwip_sock *sock, bool enable)
Set or clear TCP_NODELAY on a socket's tcp_pcb directly.
void esphome_lwip_hook_socket(struct lwip_sock *sock)
Hook a socket's netconn callback to notify the main loop task on receive events.
struct lwip_sock * esphome_lwip_get_sock(int fd)
Look up a LwIP socket struct from a file descriptor.
void esphome_fast_select_set_ota_listener_sock(struct lwip_sock *sock)
Set the listener netconn that the fast-select callback filters OTA wakes against.
@ ESPHOME_LWIP_SOCK_RCVEVENT_OFFSET