|
nros platform-cffi
Canonical C ABI for porting the nros platform abstraction
|
Canonical C ABI for the nros platform networking surface. More...

Go to the source code of this file.
Macros | |
| #define | NROS_PLATFORM_NET_SOCKET_EOF ((size_t) -2) |
| #define | NROS_PLATFORM_NET_SOCKET_ERROR ((size_t) -1) |
Functions | |
| void | nros_platform_network_poll (void) |
| int8_t | nros_platform_socket_accept (const void *sock_in, void *sock_out) |
| void | nros_platform_socket_close (void *sock) |
| int8_t | nros_platform_socket_set_non_blocking (const void *sock) |
| int8_t | nros_platform_socket_wait_event (void *peers, void *mutex) |
| void | nros_platform_tcp_close (void *sock) |
| int8_t | nros_platform_tcp_create_endpoint (void *ep, const uint8_t *address, const uint8_t *port) |
| void | nros_platform_tcp_free_endpoint (void *ep) |
| int8_t | nros_platform_tcp_listen (void *sock, const void *endpoint) |
| int8_t | nros_platform_tcp_open (void *sock, const void *endpoint, uint32_t timeout_ms) |
| int8_t | nros_platform_tcp_open_within (void *sock, const void *endpoint, uint32_t timeout_ms, int32_t connect_timeout_ms) |
| size_t | nros_platform_tcp_read (const void *sock, uint8_t *buf, size_t len) |
| size_t | nros_platform_tcp_read_exact (const void *sock, uint8_t *buf, size_t len) |
| size_t | nros_platform_tcp_send (const void *sock, const uint8_t *buf, size_t len) |
| int8_t | nros_platform_tcp_set_rx_notify (const void *sock, void(*notify)(void *ctx), void *ctx) |
| void | nros_platform_udp_close (void *sock) |
| int8_t | nros_platform_udp_create_endpoint (void *ep, const uint8_t *address, const uint8_t *port) |
| void | nros_platform_udp_free_endpoint (void *ep) |
| int8_t | nros_platform_udp_listen (void *sock, const void *endpoint, uint32_t timeout_ms) |
| void | nros_platform_udp_mcast_close (void *sockrecv, void *socksend, const void *rep, const void *lep) |
| int8_t | nros_platform_udp_mcast_listen (void *sock, const void *endpoint, uint32_t timeout_ms, const uint8_t *iface, const uint8_t *join) |
| int8_t | nros_platform_udp_mcast_open (void *sock, const void *endpoint, void *lep, uint32_t timeout_ms, const uint8_t *iface) |
| size_t | nros_platform_udp_mcast_read (const void *sock, uint8_t *buf, size_t len, const void *lep, void *addr) |
| size_t | nros_platform_udp_mcast_read_exact (const void *sock, uint8_t *buf, size_t len, const void *lep, void *addr) |
| size_t | nros_platform_udp_mcast_send (const void *sock, const uint8_t *buf, size_t len, const void *endpoint) |
| int8_t | nros_platform_udp_open (void *sock, const void *endpoint, uint32_t timeout_ms) |
| size_t | nros_platform_udp_read (const void *sock, uint8_t *buf, size_t len) |
| size_t | nros_platform_udp_read_exact (const void *sock, uint8_t *buf, size_t len) |
| int32_t | nros_platform_udp_readiness_handle (const void *sock) |
| size_t | nros_platform_udp_send (const void *sock, const uint8_t *buf, size_t len, const void *endpoint) |
| void | nros_platform_udp_set_recv_timeout (const void *sock, uint32_t timeout_ms) |
| int8_t | nros_platform_udp_set_rx_notify (const void *sock, void(*notify)(void *ctx), void *ctx) |
Canonical C ABI for the nros platform networking surface.
Companion to <nros/platform.h>; sits beside the core 39-symbol platform ABI as the network interface zenoh-pico and the XRCE-DDS transports use. Carved into a separate header because bare-metal targets without a network stack can omit it.
Sockets and endpoints are opaque storage pointers. The application allocates the bytes (size known to the implementor; matches zenoh-pico's _z_sys_net_socket_t / _z_sys_net_endpoint_t). The implementation writes its handle into the supplied storage. read_* and send return (size_t) -1 on error, otherwise the number of bytes transferred (zero is a valid short-read result).
Read functions inherit the socket's recv timeout (set via set_recv_timeout). 0 ms means block indefinitely; non-zero is an upper bound on per-call duration.
nros_platform_udp_listen and udp_multicast_* are optional. A platform that doesn't implement them supplies a stub that returns -1 (or (size_t) -1 on the read/send variants); higher layers detect the failure and fall back. network_poll exists for platforms with a non-OS network stack (smoltcp on bare-metal) — POSIX / Zephyr / NuttX / FreeRTOS+lwIP / ThreadX+NetXDuo provide a no-op stub.
| #define NROS_PLATFORM_NET_SOCKET_EOF ((size_t) -2) |
What a TCP read returns when the peer closed the stream (end-of-stream): distinct from NROS_PLATFORM_NET_SOCKET_ERROR and from 0, which means "nothing read yet". A port returns it only when it KNOWS the peer closed (a BSD recv that returns 0 for a non-empty buffer); one whose read returns 0 for a timeout keeps returning 0. zenoh-pico closes the session on it, which starts a reconnect; without it a client whose router died polls the dead socket forever. Equal to zenoh-pico's _Z_LINK_READ_EOF.
| #define NROS_PLATFORM_NET_SOCKET_ERROR ((size_t) -1) |
| void nros_platform_network_poll | ( | void | ) |
Pump the underlying network stack to process pending I/O. No-op on platforms with a kernel-driven socket layer (POSIX, Zephyr, lwIP, NetX Duo). Bare-metal smoltcp targets advance the stack from this entry point.
| int8_t nros_platform_socket_accept | ( | const void * | sock_in, |
| void * | sock_out ) |
Accept a pending connection from sock_in into sock_out.
| void nros_platform_socket_close | ( | void * | sock | ) |
Socket-layer shutdown + close. Distinct from nros_platform_tcp_close because zenoh-pico's helper layer exposes both.
| int8_t nros_platform_socket_set_non_blocking | ( | const void * | sock | ) |
Switch a socket to non-blocking mode.
| int8_t nros_platform_socket_wait_event | ( | void * | peers, |
| void * | mutex ) |
Wait for socket events on a multi-peer set. Optional on platforms without a poll/select primitive.
| void nros_platform_tcp_close | ( | void * | sock | ) |
Close a TCP socket.
| int8_t nros_platform_tcp_create_endpoint | ( | void * | ep, |
| const uint8_t * | address, | ||
| const uint8_t * | port ) |
Resolve (address, port) strings into the caller-allocated endpoint storage at ep. Both strings are NUL-terminated.
| void nros_platform_tcp_free_endpoint | ( | void * | ep | ) |
Release any resources held by the endpoint at ep.
| int8_t nros_platform_tcp_listen | ( | void * | sock, |
| const void * | endpoint ) |
Open a listening TCP socket bound to endpoint.
| int8_t nros_platform_tcp_open | ( | void * | sock, |
| const void * | endpoint, | ||
| uint32_t | timeout_ms ) |
Open a TCP client connection to endpoint.
| int8_t nros_platform_tcp_open_within | ( | void * | sock, |
| const void * | endpoint, | ||
| uint32_t | timeout_ms, | ||
| int32_t | connect_timeout_ms ) |
nros_platform_tcp_open whose connect gives up after connect_timeout_ms. timeout_ms keeps its meaning in nros_platform_tcp_open. A negative connect_timeout_ms states no bound: the call then behaves exactly as nros_platform_tcp_open, connect limit included. zenoh-pico passes what is left of a client's connect budget ([knobs.zenoh.limits] connect_timeout_ms), so a peer that drops the SYN ends the attempt at the budget instead of at the stack's own SYN-retry limit. A port that cannot bound its connect says so in its implementation and keeps its own limit.
| size_t nros_platform_tcp_read | ( | const void * | sock, |
| uint8_t * | buf, | ||
| size_t | len ) |
Read up to len bytes. Returns bytes received (0: nothing yet), NROS_PLATFORM_NET_SOCKET_EOF when the peer closed the stream, or NROS_PLATFORM_NET_SOCKET_ERROR on error.
| size_t nros_platform_tcp_read_exact | ( | const void * | sock, |
| uint8_t * | buf, | ||
| size_t | len ) |
Read exactly len bytes. Returns len on success, NROS_PLATFORM_NET_SOCKET_EOF when the peer closed the stream first, or NROS_PLATFORM_NET_SOCKET_ERROR on error.
| size_t nros_platform_tcp_send | ( | const void * | sock, |
| const uint8_t * | buf, | ||
| size_t | len ) |
Send up to len bytes, waiting at most about the socket's timeout (the timeout_ms it was opened with) for the stack to take them. Returns the bytes taken, which may be fewer than len and is 0 when the stack took none in that time, or NROS_PLATFORM_NET_SOCKET_ERROR when the connection is broken. It never waits for a peer that has stopped reading: a caller that needs every byte loops, and decides how long a stall it tolerates (zenoh-pico: Z_TRANSPORT_TX_WAIT_BEFORE_CLOSE). A socket opened with timeout_ms == 0 states no bound.
| int8_t nros_platform_tcp_set_rx_notify | ( | const void * | sock, |
| void(* | notify )(void *ctx), | ||
| void * | ctx ) |
Install (notify != NULL) or remove the receive notification on a connected TCP socket: the stack calls notify(ctx) each time data is queued on it, from the stack's own context (NetX's IP thread), so notify must only signal. Data already queued at install calls it once before this returns; once a removal returns, the previous notify is never called again. A zenoh session in CALLER mode over sock reports this as NROS_RMW_READINESS_NOTIFY.
Returns 0 when installed (or removed), -1 where the stack offers no such hook (every stack whose zenoh sessions read the link on their own thread needs none).
| void nros_platform_udp_close | ( | void * | sock | ) |
| int8_t nros_platform_udp_create_endpoint | ( | void * | ep, |
| const uint8_t * | address, | ||
| const uint8_t * | port ) |
| void nros_platform_udp_free_endpoint | ( | void * | ep | ) |
| int8_t nros_platform_udp_listen | ( | void * | sock, |
| const void * | endpoint, | ||
| uint32_t | timeout_ms ) |
Bind a UDP socket in listen / server mode. Optional — return -1 on platforms that don't expose a UDP-server primitive.
| void nros_platform_udp_mcast_close | ( | void * | sockrecv, |
| void * | socksend, | ||
| const void * | rep, | ||
| const void * | lep ) |
| int8_t nros_platform_udp_mcast_listen | ( | void * | sock, |
| const void * | endpoint, | ||
| uint32_t | timeout_ms, | ||
| const uint8_t * | iface, | ||
| const uint8_t * | join ) |
| int8_t nros_platform_udp_mcast_open | ( | void * | sock, |
| const void * | endpoint, | ||
| void * | lep, | ||
| uint32_t | timeout_ms, | ||
| const uint8_t * | iface ) |
| size_t nros_platform_udp_mcast_read | ( | const void * | sock, |
| uint8_t * | buf, | ||
| size_t | len, | ||
| const void * | lep, | ||
| void * | addr ) |
| size_t nros_platform_udp_mcast_read_exact | ( | const void * | sock, |
| uint8_t * | buf, | ||
| size_t | len, | ||
| const void * | lep, | ||
| void * | addr ) |
| size_t nros_platform_udp_mcast_send | ( | const void * | sock, |
| const uint8_t * | buf, | ||
| size_t | len, | ||
| const void * | endpoint ) |
| int8_t nros_platform_udp_open | ( | void * | sock, |
| const void * | endpoint, | ||
| uint32_t | timeout_ms ) |
| size_t nros_platform_udp_read | ( | const void * | sock, |
| uint8_t * | buf, | ||
| size_t | len ) |
| size_t nros_platform_udp_read_exact | ( | const void * | sock, |
| uint8_t * | buf, | ||
| size_t | len ) |
| int32_t nros_platform_udp_readiness_handle | ( | const void * | sock | ) |
The OS handle that becomes readable when a datagram arrives on sock: its file descriptor on POSIX and NuttX. An RMW session reports it as NROS_RMW_READINESS_WAITABLE, and the executor parks on it (nros_platform_wake_park_handles_us) instead of blocking in read. Returns -1 where the stack has no such handle (lwIP, NetX, a bare-metal stack); those report readiness as a Notify instead.
| size_t nros_platform_udp_send | ( | const void * | sock, |
| const uint8_t * | buf, | ||
| size_t | len, | ||
| const void * | endpoint ) |
Send len bytes to endpoint.
| void nros_platform_udp_set_recv_timeout | ( | const void * | sock, |
| uint32_t | timeout_ms ) |
Set the recv timeout in milliseconds; 0 means block indefinitely.
| int8_t nros_platform_udp_set_rx_notify | ( | const void * | sock, |
| void(* | notify )(void *ctx), | ||
| void * | ctx ) |
Install (notify != NULL) or remove the receive notification on sock: the stack calls notify(ctx) each time a datagram is queued on it, from the stack's own context (lwIP's tcpip thread, NetX's IP thread), so notify must only signal. Data already queued at install calls it once before this returns; once a removal returns, the previous notify is never called again. An RMW session over sock reports this as NROS_RMW_READINESS_NOTIFY.
Returns 0 when installed (or removed), -1 where the stack offers no such hook — POSIX/NuttX, which have nros_platform_udp_readiness_handle instead, and stacks not yet given one.