|
LibJuno 1.0.4
LibJuno is a lightweight C11 library designed specifically for embedded systems.
|
Linux/POSIX-specific derivation and initialiser for the UDP module. More...


Go to the source code of this file.
Typedefs | |
| typedef struct JUNO_UDP_LINUX_TAG | JUNO_UDP_LINUX_T |
Functions | |
| struct JUNO_UDP_LINUX_TAG | JUNO_MODULE_DERIVE (JUNO_UDP_ROOT_T, int _iSockFd;struct sockaddr_in _tAddr;) |
| Linux POSIX derivation of the UDP module. | |
| union JUNO_UDP_TAG | JUNO_MODULE (JUNO_UDP_API_T, JUNO_UDP_ROOT_T, JUNO_UDP_LINUX_T tLinux;) |
| Type-safe polymorphic handle for a UDP module instance. | |
| JUNO_STATUS_T | JunoUdp_LinuxInit (JUNO_UDP_T *ptUdp, const JUNO_UDP_CFG_T *ptCfg, JUNO_FAILURE_HANDLER_T pfcnFailureHandler, void *pvFailureUserData) |
| Initialise a Linux UDP module instance and open the socket (RAII). | |
Linux/POSIX-specific derivation and initialiser for the UDP module.
This header is the platform layer for the UDP socket module. It extends the freestanding interface (udp_api.h) with Linux/POSIX-specific state (socket file descriptor, peer/bind address) and provides a RAII initialiser that wires the vtable and opens the socket in a single call.
Do not include this header in freestanding translation units. It pulls in <sys/socket.h> and <netinet/in.h> which are POSIX-only.
Typical usage:
| typedef struct JUNO_UDP_LINUX_TAG JUNO_UDP_LINUX_T |
| union JUNO_UDP_TAG JUNO_MODULE | ( | JUNO_UDP_API_T | , |
| JUNO_UDP_ROOT_T | , | ||
| JUNO_UDP_LINUX_T tLinux; | |||
| ) |
Type-safe polymorphic handle for a UDP module instance.
Defined here (rather than in udp_api.h) because the union body requires JUNO_UDP_LINUX_T to be complete, and that type includes POSIX fields (struct sockaddr_in) that are not freestanding-compatible.
Callers allocate this union (stack or static) and pass it to JunoUdp_LinuxInit, which wires the vtable and opens the socket. All subsequent API calls use &tUdp.tRoot.
| struct JUNO_UDP_LINUX_TAG JUNO_MODULE_DERIVE | ( | JUNO_UDP_ROOT_T | , |
| int _iSockFd;struct sockaddr_in _tAddr; | |||
| ) |
Linux POSIX derivation of the UDP module.
Embeds JUNO_UDP_ROOT_T as its first member (tRoot, via JUNO_MODULE_DERIVE), enabling safe up-cast to the root for vtable dispatch. Owns the POSIX socket state that cannot be expressed in freestanding-compatible types and therefore cannot reside in the root.
Members:
_iSockFd — POSIX socket file descriptor; -1 when closed/invalid._tAddr — Peer address (sender) or bind address (receiver), populated by JunoUdp_LinuxInit.Callers allocate a JUNO_UDP_T union and pass it to JunoUdp_LinuxInit; they need not interact with this type directly.
| JUNO_STATUS_T JunoUdp_LinuxInit | ( | JUNO_UDP_T * | ptUdp, |
| const JUNO_UDP_CFG_T * | ptCfg, | ||
| JUNO_FAILURE_HANDLER_T | pfcnFailureHandler, | ||
| void * | pvFailureUserData | ||
| ) |
Initialise a Linux UDP module instance and open the socket (RAII).
Wires the internal Linux vtable (g_junoUdpLinuxApi) into the module, stores the failure handler, and immediately opens a POSIX UDP socket configured according to ptCfg. If bIsReceiver is true the socket is bound to the local port; otherwise it is connected to the remote address.
Callers do NOT pass ptApi — the vtable is selected internally.
On failure the socket is not opened and the module is left in a safe state with _iSockFd = -1.
Initialisation sequence:
ptUdp and ptCfg (returns JUNO_STATUS_NULLPTR_ERROR if NULL).JunoUdp_Init with the internal Linux vtable.ptCfg.ptUdp->tLinux.JUNO_STATUS_SUCCESS.| ptUdp | Caller-owned module union storage; must be non-NULL. |
| ptCfg | Socket configuration (address, port, role); must be non-NULL. |
| pfcnFailureHandler | Diagnostic callback invoked before any error return; may be NULL. |
| pvFailureUserData | Opaque user data pointer passed to the failure handler; may be NULL. |
JUNO_STATUS_SUCCESS on success; non-zero on failure (e.g., socket creation error).Wires s_tJunoUdpLinuxApi into the root via JunoUdp_Init, stores the failure handler, initialises _iSockFd to -1, then calls OpenSocket to create and bind/connect the POSIX socket.
On failure the socket is not opened and the module is left in a safe state with _iSockFd = -1.
| ptUdp | Caller-owned module union storage; must be non-NULL. |
| ptCfg | Socket configuration (address, port, role); must be non-NULL. |
| pfcnFailureHandler | Diagnostic callback invoked before any error return; may be NULL. |
| pvFailureUserData | Opaque user data pointer passed to the failure handler; may be NULL. |
JUNO_STATUS_SUCCESS on success; non-zero on failure.