ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
client.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file client.h
6 * @brief Layer 4 UDP, the sending side: datagrams to an arbitrary destination.
7 *
8 * One shared outbound control block, created on first send.
9 *
10 * sendto() carries the caller's buffer to the stack's thread inside one marshaled call and reports
11 * what the stack did with it. Nothing is queued and nothing is copied on the way out.
12 *
13 * Nothing is bound here, so the source port is ephemeral and nothing is received. A service whose
14 * peer replies to the source endpoint binds a port on the listener side and sends with
15 * ::UdpListener sendto instead.
16 *
17 * Reached through ::UdpClient.
18 *
19 * @author Douglas Quigg (dstroy0)
20 * @date 2026
21 */
22
23#ifndef PROTOCORE_UDP_CLIENT_H
24#define PROTOCORE_UDP_CLIENT_H
25
26#include "shared/ip/ip.h" // protocore_ip: the destination, already an address
27
28#include "protocore_config.h"
29
31
32/**
33 * @brief The sending side of UDP.
34 *
35 * RFC 768 "User Interface": an operation that allows a datagram to be sent, specifying the data and
36 * the destination port and address. A caller sets the members the call takes, invokes it through
37 * ::UdpClient, and reads the outcome off the same handle.
38 *
39 * @var UdpClientNs::dst where the datagram goes
40 * @var UdpClientNs::dst_port its port
41 * @var UdpClientNs::data the octets to send
42 * @var UdpClientNs::len how many
43 * @var UdpClientNs::ok whether the stack took them
44 * @var UdpClientNs::sendto send a datagram to an address and port
45 *
46 * sendto() sends the caller's bytes from where they already are, and reports whether the stack took
47 * them. There is nothing between the caller and the wire: a refusal means the datagram did not
48 * leave, the caller's buffer is untouched, and the caller sends it again. Nothing is queued, so
49 * there is no drain to poll and no room to read.
50 */
51typedef struct
52{
54 uint16_t dst_port;
55 const uint8_t *data;
56 size_t len;
59
60/** @brief The operands and the outcome. */
62
63/** @brief The entries. */
64typedef struct
65{
66 void (*const sendto)(uint8_t *work);
68
69// What the table binds, defined once in the .c and taking one parameter each: everything
70// else an entry needs is an operand in UdpClientV or a region of the borrow at a fixed offset.
71void protocore_udp_client_sendto(uint8_t *work);
72
73// `static const`, initialised HERE rather than `extern` against a definition in the .c: a
74// const object whose initializer every translation unit can see is a COMPILE-TIME FACT, so
75// `UdpClient.sendto(work)` resolves to a named function and becomes a DIRECT call. An extern table
76// leaves the call indirect and the symbol live at every level, -O2 -flto included.
77static const UdpClientNs UdpClient __attribute__((unused)) = {
79};
80
81/**
82 * @brief The PROTOCORE_UDP_CLIENT_BORROW bytes this module's state lives in.
83 *
84 * Stated beside the namespace rather than on it: an entry takes a borrow, and this is where
85 * that borrow comes from. Taken once from the end of the pool, which no mark and no release
86 * walks, so the state lasts the life of the program.
87 *
88 * @return the span.
89 */
91
93
94#endif // PROTOCORE_UDP_CLIENT_H
Layer 3 (Network) - a family-tagged IP address (IPv4 or IPv6) with RFC-faithful text parsing,...
The entries.
Definition client.h:65
void(*const sendto)(uint8_t *work)
Definition client.h:66
const protocore_ip * dst
Definition client.h:53
uint16_t dst_port
Definition client.h:54
const uint8_t * data
Definition client.h:55
size_t len
Definition client.h:56
proto_bool ok
Definition client.h:57
A v4 or v6 address in network (big-endian) byte order.
Definition ip.h:56
UdpClientVars UdpClientV
The operands and the outcome.
void protocore_udp_client_sendto(uint8_t *work)
uint8_t * protocore_udp_client_span(void)
The PROTOCORE_UDP_CLIENT_BORROW bytes this module's state lives in.
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
Definition types.h:96
_Bool proto_bool
The truth value.
Definition types.h:64
#define PROTOCORE_END_DECLS
Definition types.h:97