This commit is contained in:
J. Nick Koston
2026-02-23 21:27:03 -06:00
parent 6734aa1544
commit 661f826bf1
2 changed files with 7 additions and 2 deletions

View File

@@ -128,6 +128,10 @@ static void esphome_socket_event_callback(struct netconn *conn, enum netconn_evt
void esphome_lwip_fast_select_init(void) { s_main_loop_task = xTaskGetCurrentTaskHandle(); }
bool esphome_lwip_socket_has_data(int fd) {
// lwip_socket_dbg_get_socket() is a direct array lookup without the refcount that
// get_socket()/done_socket() uses. This is safe because the caller owns the socket
// lifetime: both has_data() and socket close happen on the main loop thread, so
// the sockets[] entry cannot be freed while we read it.
struct lwip_sock *sock = lwip_socket_dbg_get_socket(fd);
if (sock == NULL || sock->conn == NULL)
return false;

View File

@@ -14,8 +14,9 @@ extern "C" {
void esphome_lwip_fast_select_init(void);
/// Check if a LwIP socket has data ready via direct rcvevent read (~215 ns per socket).
/// Uses lwip_socket_dbg_get_socket() which is a direct array lookup — no locking, no refcount.
/// Safe for single-threaded polling from the main loop.
/// Uses lwip_socket_dbg_get_socket() a direct array lookup without the refcount that
/// get_socket()/done_socket() uses. Safe because the caller owns the socket lifetime:
/// both has_data reads and socket close/unregister happen on the main loop thread.
bool esphome_lwip_socket_has_data(int fd);
/// Hook a socket's netconn callback to notify the main loop task on receive events.