ESPHome 2026.3.0
Loading...
Searching...
No Matches
lwip_fast_select.c File Reference

Go to the source code of this file.

Functions

void esphome_lwip_fast_select_init (void)
 Initialize fast select — must be called from the main loop task during setup().
 
struct lwip_sock * esphome_lwip_get_sock (int fd)
 Look up a LwIP socket struct from a file descriptor.
 
void esphome_lwip_hook_socket (struct lwip_sock *sock)
 Hook a socket's netconn callback to notify the main loop task on receive events.
 
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_wake_main_loop (void)
 Wake the main loop task from another FreeRTOS task — costs <1 us.
 
void IRAM_ATTR esphome_lwip_wake_main_loop_from_isr (int *px_higher_priority_task_woken)
 Wake the main loop task from an ISR — costs <1 us.
 
void IRAM_ATTR esphome_lwip_wake_main_loop_any_context (void)
 Wake the main loop task from any context (ISR, thread, or main loop).
 

Function Documentation

◆ esphome_lwip_fast_select_init()

void esphome_lwip_fast_select_init ( void )

Initialize fast select — must be called from the main loop task during setup().

Saves the current task handle for xTaskNotifyGive() wake notifications.

Definition at line 187 of file lwip_fast_select.c.

◆ esphome_lwip_get_sock()

struct lwip_sock * esphome_lwip_get_sock ( int fd)

Look up a LwIP socket struct from a file descriptor.

Returns NULL if fd is invalid or the socket/netconn is not initialized. Use this at registration time to cache the pointer for esphome_lwip_socket_has_data().

Definition at line 204 of file lwip_fast_select.c.

◆ esphome_lwip_hook_socket()

void esphome_lwip_hook_socket ( struct lwip_sock * sock)

Hook a socket's netconn callback to notify the main loop task on receive events.

Wraps the original event_callback with one that also calls xTaskNotifyGive(). Must be called from the main loop after socket creation. The sock pointer must have been obtained from esphome_lwip_get_sock().

Definition at line 208 of file lwip_fast_select.c.

◆ esphome_lwip_set_nodelay()

bool esphome_lwip_set_nodelay ( struct lwip_sock * sock,
bool enable )

Set or clear TCP_NODELAY on a socket's tcp_pcb directly.

Must be called with the TCPIP core lock held (LwIPLock in C++). This bypasses lwip_setsockopt() overhead (socket lookups, switch cascade, hooks, refcounting) — just a direct pcb->flags bit set/clear. Returns true if successful, false if sock/conn/pcb is NULL or the socket is not TCP.

Definition at line 220 of file lwip_fast_select.c.

◆ esphome_lwip_wake_main_loop()

void esphome_lwip_wake_main_loop ( void )

Wake the main loop task from another FreeRTOS task — costs <1 us.

NOT ISR-safe — must only be called from task context.

Definition at line 236 of file lwip_fast_select.c.

◆ esphome_lwip_wake_main_loop_any_context()

void IRAM_ATTR esphome_lwip_wake_main_loop_any_context ( void )

Wake the main loop task from any context (ISR, thread, or main loop).

ESP32-only: uses xPortInIsrContext() to detect ISR context. LibreTiny lacks IRAM_ATTR support needed for ISR-safe paths.

Definition at line 255 of file lwip_fast_select.c.

◆ esphome_lwip_wake_main_loop_from_isr()

void IRAM_ATTR esphome_lwip_wake_main_loop_from_isr ( int * px_higher_priority_task_woken)

Wake the main loop task from an ISR — costs <1 us.

ISR-safe variant using vTaskNotifyGiveFromISR().

Parameters
px_higher_priority_task_wokenSet to pdTRUE if a context switch is needed.

Definition at line 244 of file lwip_fast_select.c.