[socket] Add unified UDP recv loop-monitored factory functions

Add socket_udp_recv_loop_monitored() and socket_ip_udp_recv_loop_monitored()
so consumers can create UDP recv sockets with loop wake support using a single
API across all platforms, without #ifdef guards.
This commit is contained in:
J. Nick Koston
2026-04-09 08:56:11 -10:00
parent 2375faee88
commit 0a3f8c6d67
3 changed files with 36 additions and 0 deletions
@@ -1249,6 +1249,11 @@ std::unique_ptr<UDPRecvSocket> socket_udp_recv(int domain, int protocol) {
return sock;
}
std::unique_ptr<UDPRecvSocket> socket_udp_recv_loop_monitored(int domain, int protocol) {
// LWIPRawUDPRecvImpl has wake built into the recv callback, so no extra monitoring needed
return socket_udp_recv(domain, protocol);
}
std::unique_ptr<ListenSocket> socket_listen(int domain, int type, int protocol) {
if (type != SOCK_STREAM) {
ESP_LOGE(TAG, "Use socket_udp_recv() for UDP sockets on this platform");
+12
View File
@@ -101,6 +101,18 @@ std::unique_ptr<ListenSocket> socket_ip_loop_monitored(int type, int protocol) {
}
#endif
#ifdef USE_SOCKET_IMPL_LWIP_TCP
// LWIP_TCP has separate UDPRecvSocket type — needs out-of-line factory.
// BSD and LWIP_SOCKETS define this inline in socket.h.
std::unique_ptr<UDPRecvSocket> socket_ip_udp_recv_loop_monitored(int protocol) {
#if USE_NETWORK_IPV6
return socket_udp_recv_loop_monitored(AF_INET6, protocol);
#else
return socket_udp_recv_loop_monitored(AF_INET, protocol);
#endif /* USE_NETWORK_IPV6 */
}
#endif
#if !defined(USE_SOCKET_IMPL_LWIP_TCP)
// BSD and LWIP_SOCKETS: UDPSocket == UDPRecvSocket == Socket, so these just delegate.
std::unique_ptr<UDPSocket> socket_udp(int domain, int protocol) {
+19
View File
@@ -98,6 +98,25 @@ std::unique_ptr<UDPRecvSocket> socket_udp_recv(int domain, int protocol);
/// Create a UDP socket with receive support in the newest available IP domain.
std::unique_ptr<UDPRecvSocket> socket_ip_udp_recv(int protocol);
/// Create a UDP recv socket and monitor it for data in the main loop.
/// On LWIP_TCP platforms, wake is built into the recv callback so this just delegates to socket_udp_recv().
/// On BSD/LWIP_SOCKETS platforms, this registers the socket with the Application's select() loop.
#ifdef USE_SOCKET_IMPL_LWIP_TCP
std::unique_ptr<UDPRecvSocket> socket_udp_recv_loop_monitored(int domain, int protocol);
std::unique_ptr<UDPRecvSocket> socket_ip_udp_recv_loop_monitored(int protocol);
#else
inline std::unique_ptr<UDPRecvSocket> socket_udp_recv_loop_monitored(int domain, int protocol) {
return socket_loop_monitored(domain, SOCK_DGRAM, protocol);
}
inline std::unique_ptr<UDPRecvSocket> socket_ip_udp_recv_loop_monitored(int protocol) {
#if USE_NETWORK_IPV6
return socket_udp_recv_loop_monitored(AF_INET6, protocol);
#else
return socket_udp_recv_loop_monitored(AF_INET, protocol);
#endif
}
#endif
/// Create a socket and monitor it for data in the main loop.
/// Like socket() but also registers the socket with the Application's select() loop.
/// WARNING: These functions are NOT thread-safe. They must only be called from the main loop