|
ESPHome 2026.11.0-dev
|
UDP socket with receive support for LWIP raw API. More...
#include <lwip_raw_udp_impl.h>
Data Structures | |
| struct | UDPRxPacket |
Public Member Functions | |
| LWIPRawUDPImpl (sa_family_t family, struct udp_pcb *pcb) | |
| Caller (the factory) must hold the lwip lock; registers the recv callback. | |
| ~LWIPRawUDPImpl () | |
| int | close () |
| Close the socket, flushing any queued rx packets first. | |
| ssize_t | read (void *buf, size_t len) |
| Read the next queued packet, discarding source address info. | |
| ssize_t | recvfrom (void *buf, size_t len, struct sockaddr *src_addr, socklen_t *addrlen) |
| Read the next queued packet and return the source address. | |
| bool | ready () const |
| Returns true if there are packets available to read. | |
| uint16_t | get_rx_dropped () const |
| Number of packets dropped because the rx queue was full (saturating). | |
| int | bind (const struct sockaddr *name, socklen_t addrlen) |
| int | get_fd () const |
| int | getsockopt (int level, int optname, void *optval, socklen_t *optlen) |
| ssize_t | sendto (const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen) |
| Send a UDP packet to the specified destination. | |
| int | setblocking (bool blocking) |
| int | setsockopt (int level, int optname, const void *optval, socklen_t optlen) |
Protected Member Functions | |
| void | recv_fn_ (struct pbuf *p, const ip_addr_t *addr, u16_t port) |
Static Protected Member Functions | |
| static void | s_recv_fn (void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) |
Protected Attributes | |
| std::array< UDPRxPacket, UDP_RX_QUEUE_SIZE > | rx_queue_ {} |
| uint16_t | rx_dropped_ {0} |
| uint8_t | rx_read_idx_ {0} |
| uint8_t | rx_count_ {0} |
Static Protected Attributes | |
| static constexpr uint8_t | UDP_RX_QUEUE_SIZE = 4 |
| Ring buffer for received UDP packets. | |
| static constexpr uint8_t | UDP_RX_MASK = UDP_RX_QUEUE_SIZE - 1 |
UDP socket with receive support for LWIP raw API.
Extends LWIPRawUDPSendImpl with a fixed-size ring buffer for incoming packets. Inheritance is private (base dtor is non-virtual; converting to a base pointer would leak queued pbufs on destruction).
Definition at line 55 of file lwip_raw_udp_impl.h.
| esphome::socket::LWIPRawUDPImpl::LWIPRawUDPImpl | ( | sa_family_t | family, |
| struct udp_pcb * | pcb ) |
Caller (the factory) must hold the lwip lock; registers the recv callback.
Definition at line 205 of file lwip_raw_udp_impl.cpp.
| esphome::socket::LWIPRawUDPImpl::~LWIPRawUDPImpl | ( | ) |
Definition at line 210 of file lwip_raw_udp_impl.cpp.
Definition at line 26 of file lwip_raw_udp_impl.cpp.
| int esphome::socket::LWIPRawUDPImpl::close | ( | ) |
Close the socket, flushing any queued rx packets first.
Definition at line 216 of file lwip_raw_udp_impl.cpp.
|
inline |
Definition at line 38 of file lwip_raw_udp_impl.h.
|
inline |
Number of packets dropped because the rx queue was full (saturating).
Definition at line 85 of file lwip_raw_udp_impl.h.
| int esphome::socket::LWIPRawUDPSendImpl::getsockopt | ( | int | level, |
| int | optname, | ||
| void * | optval, | ||
| socklen_t * | optlen ) |
Definition at line 33 of file lwip_raw_udp_impl.cpp.
| ssize_t esphome::socket::LWIPRawUDPImpl::read | ( | void * | buf, |
| size_t | len ) |
Read the next queued packet, discarding source address info.
If buf is smaller than the packet, data is silently truncated (returns bytes copied). Note: unlike POSIX MSG_TRUNC, this does not return the original packet length on truncation.
Definition at line 231 of file lwip_raw_udp_impl.cpp.
|
inline |
Returns true if there are packets available to read.
Intentionally unlocked — same rationale as LWIPRawImpl::ready().
Definition at line 82 of file lwip_raw_udp_impl.h.
|
protected |
Definition at line 271 of file lwip_raw_udp_impl.cpp.
| ssize_t esphome::socket::LWIPRawUDPImpl::recvfrom | ( | void * | buf, |
| size_t | len, | ||
| struct sockaddr * | src_addr, | ||
| socklen_t * | addrlen ) |
Read the next queued packet and return the source address.
If buf is smaller than the packet, data is silently truncated (returns bytes copied). Note: unlike POSIX MSG_TRUNC, this does not return the original packet length on truncation.
Definition at line 233 of file lwip_raw_udp_impl.cpp.
|
staticprotected |
Definition at line 263 of file lwip_raw_udp_impl.cpp.
| ssize_t esphome::socket::LWIPRawUDPSendImpl::sendto | ( | const void * | buf, |
| size_t | len, | ||
| int | flags, | ||
| const struct sockaddr * | dest_addr, | ||
| socklen_t | addrlen ) |
Send a UDP packet to the specified destination.
Definition at line 30 of file lwip_raw_udp_impl.cpp.
| int esphome::socket::LWIPRawUDPSendImpl::setblocking | ( | bool | blocking | ) |
Definition at line 35 of file lwip_raw_udp_impl.cpp.
| int esphome::socket::LWIPRawUDPSendImpl::setsockopt | ( | int | level, |
| int | optname, | ||
| const void * | optval, | ||
| socklen_t | optlen ) |
Definition at line 32 of file lwip_raw_udp_impl.cpp.
|
protected |
Definition at line 108 of file lwip_raw_udp_impl.h.
|
protected |
Definition at line 106 of file lwip_raw_udp_impl.h.
|
protected |
Definition at line 105 of file lwip_raw_udp_impl.h.
|
protected |
Definition at line 107 of file lwip_raw_udp_impl.h.
|
staticconstexprprotected |
Definition at line 97 of file lwip_raw_udp_impl.h.
|
staticconstexprprotected |
Ring buffer for received UDP packets.
Both producer (recv callback) and consumer (main loop) are serialized by the lwip lock — the callback runs under lwip core lock, and consumer methods hold LWIP_LOCK(). All 4 slots are usable (no wasted slot for full/empty distinction). No heap allocation in the recv callback — packets are dropped if the queue is full.
Definition at line 96 of file lwip_raw_udp_impl.h.