|
DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
|
Layer 4 UDP datagram service - the only place lwIP UDP is touched. More...
#include "network_drivers/transport/udp.h"#include <string.h>#include "lwip/pbuf.h"#include "lwip/priv/tcpip_priv.h"#include "lwip/udp.h"Go to the source code of this file.
Classes | |
| struct | UdpListener |
| struct | UdpCtx |
| struct | DetUdpPeer |
| struct | DetUdpCall |
Enumerations | |
| enum class | DetUdpOp : uint8_t { UDP_OP_LISTEN , UDP_OP_SEND , UDP_OP_SEND_OUT } |
Functions | |
| bool | det_udp_listen (uint16_t port, DetUdpHandler handler, void *ctx) |
Bind a UDP port and route incoming datagrams to handler. | |
| bool | det_udp_send (struct DetUdpPeer *peer, const uint8_t *data, size_t len) |
| Send a datagram back to the peer captured during the handler call. | |
| bool | det_udp_sendto (const char *dst_ip, uint16_t dst_port, const uint8_t *data, size_t len) |
| Send a UDP datagram to an arbitrary destination (outbound client). | |
| bool | det_udp_peer_addr (const struct DetUdpPeer *peer, char *ip_out, size_t ip_cap, uint16_t *port_out) |
| Copy a received peer's source IPv4 address (dotted-quad) and port out. | |
| bool | det_udp_listener_sendto (uint16_t listen_port, const char *dst_ip, uint16_t dst_port, const uint8_t *data, size_t len) |
Send a datagram from the listener bound on listen_port to an address. | |
Layer 4 UDP datagram service - the only place lwIP UDP is touched.
Definition in file udp.cpp.
|
strong |
| bool det_udp_listen | ( | uint16_t | port, |
| DetUdpHandler | handler, | ||
| void * | ctx | ||
| ) |
Bind a UDP port and route incoming datagrams to handler.
| port | UDP port to bind (e.g. 161 for SNMP, 53 for captive DNS). |
| handler | callback for each datagram. |
| ctx | opaque pointer forwarded to handler. |
Definition at line 151 of file udp.cpp.
References DetUdpCall::base, UdpListener::ctx, DETWS_MAX_UDP_LISTENERS, UdpListener::handler, UdpCtx::listeners, DetUdpCall::op, UdpListener::pcb, DetUdpCall::port, DetUdpCall::result, DetUdpCall::slot, UDP_OP_LISTEN, and UdpListener::used.
| bool det_udp_send | ( | struct DetUdpPeer * | peer, |
| const uint8_t * | data, | ||
| size_t | len | ||
| ) |
Send a datagram back to the peer captured during the handler call.
| peer | the token handed to the DetUdpHandler. |
| data | payload bytes. |
| len | payload length. |
Definition at line 178 of file udp.cpp.
References DetUdpPeer::addr, DetUdpCall::addr, DetUdpCall::base, DetUdpCall::data, UdpCtx::in_tcpip_thread, DetUdpCall::len, DetUdpCall::op, DetUdpPeer::pcb, DetUdpCall::pcb, DetUdpPeer::port, DetUdpCall::port, DetUdpCall::result, and UDP_OP_SEND.
| bool det_udp_sendto | ( | const char * | dst_ip, |
| uint16_t | dst_port, | ||
| const uint8_t * | data, | ||
| size_t | len | ||
| ) |
Send a UDP datagram to an arbitrary destination (outbound client).
Unlike det_udp_send() - which replies to the peer of a received datagram - this sends to a host given as a dotted-quad IPv4 string and port, using a single shared outbound PCB. Fire-and-forget; for clients such as the syslog sender. ESP32 only; a host build returns false.
| dst_ip | destination IPv4 address (e.g. "192.168.1.10"). |
| dst_port | destination UDP port. |
| data | payload bytes. |
| len | payload length. |
Definition at line 196 of file udp.cpp.
References DetUdpCall::addr, DetUdpCall::base, DetUdpCall::data, UdpCtx::in_tcpip_thread, DetUdpCall::len, DetUdpCall::op, UdpCtx::out, DetUdpCall::port, DetUdpCall::result, and UDP_OP_SEND_OUT.
| bool det_udp_peer_addr | ( | const struct DetUdpPeer * | peer, |
| char * | ip_out, | ||
| size_t | ip_cap, | ||
| uint16_t * | port_out | ||
| ) |
Copy a received peer's source IPv4 address (dotted-quad) and port out.
The DetUdpPeer token is valid only inside the handler; a service that wants to message the peer later (e.g. CoAP Observe notifications) captures its address here and sends with det_udp_listener_sendto().
Definition at line 224 of file udp.cpp.
References DetUdpPeer::addr, and DetUdpPeer::port.
| bool det_udp_listener_sendto | ( | uint16_t | listen_port, |
| const char * | dst_ip, | ||
| uint16_t | dst_port, | ||
| const uint8_t * | data, | ||
| size_t | len | ||
| ) |
Send a datagram from the listener bound on listen_port to an address.
Unlike det_udp_sendto() (a shared ephemeral source port), this uses the bound listener's PCB, so the datagram's source is listen_port - required when a peer matches replies by the server endpoint (CoAP Observe notifications come from :5683).
listen_port. Definition at line 234 of file udp.cpp.
References DetUdpCall::addr, DetUdpCall::base, DetUdpCall::data, DETWS_MAX_UDP_LISTENERS, UdpCtx::in_tcpip_thread, DetUdpCall::len, UdpCtx::listeners, DetUdpCall::op, UdpListener::pcb, DetUdpCall::pcb, DetUdpCall::port, DetUdpCall::result, UDP_OP_SEND, and UdpListener::used.