Skip to main content

PlatformTcp

Trait PlatformTcp 

Source
pub trait PlatformTcp {
    // Required methods
    fn create_endpoint(
        ep: *mut c_void,
        address: *const u8,
        port: *const u8,
    ) -> i8;
    fn free_endpoint(ep: *mut c_void);
    fn open(sock: *mut c_void, endpoint: *const c_void, timeout_ms: u32) -> i8;
    fn open_within(
        sock: *mut c_void,
        endpoint: *const c_void,
        timeout_ms: u32,
        connect_timeout_ms: i32,
    ) -> i8;
    fn listen(sock: *mut c_void, endpoint: *const c_void) -> i8;
    fn close(sock: *mut c_void);
    fn read(sock: *const c_void, buf: *mut u8, len: usize) -> usize;
    fn read_exact(sock: *const c_void, buf: *mut u8, len: usize) -> usize;
    fn send(sock: *const c_void, buf: *const u8, len: usize) -> usize;

    // Provided method
    fn set_rx_notify(
        _sock: *const c_void,
        _notify: Option<unsafe extern "C" fn(*mut c_void)>,
        _ctx: *mut c_void,
    ) -> i8 { ... }
}
Expand description

TCP networking.

Socket and endpoint parameters are opaque *mut c_void pointers to platform-specific types (_z_sys_net_socket_t, _z_sys_net_endpoint_t). The shim provides correctly-sized #[repr(C)] wrappers whose sizes are auto-detected from C headers at build time.

Read functions return usize::MAX on error. Send returns usize::MAX on error.

Method names are unprefixed — the trait already namespaces them. Shims dispatch via <ConcretePlatform as PlatformTcp>::open(...) etc.

Required Methods§

Source

fn create_endpoint(ep: *mut c_void, address: *const u8, port: *const u8) -> i8

Resolve address + port strings into an endpoint handle.

Source

fn free_endpoint(ep: *mut c_void)

Free endpoint resources.

Source

fn open(sock: *mut c_void, endpoint: *const c_void, timeout_ms: u32) -> i8

Open a TCP client connection. endpoint is by-value (opaque bytes on stack).

Source

fn open_within( sock: *mut c_void, endpoint: *const c_void, timeout_ms: u32, connect_timeout_ms: i32, ) -> i8

Self::open whose connect gives up after connect_timeout_ms (nros_platform_tcp_open_within, issue 2438). Negative: no bound, the same as Self::open. Required, not defaulted: a stack that cannot bound its connect says so in its own implementation.

Source

fn listen(sock: *mut c_void, endpoint: *const c_void) -> i8

Open a TCP listening socket.

Source

fn close(sock: *mut c_void)

Close a TCP socket.

Source

fn read(sock: *const c_void, buf: *mut u8, len: usize) -> usize

Read up to len bytes. Returns bytes read (0: nothing yet), NET_SOCKET_EOF when the peer closed the stream, or NET_SOCKET_ERROR on error.

Source

fn read_exact(sock: *const c_void, buf: *mut u8, len: usize) -> usize

Read exactly len bytes. Returns len on success, NET_SOCKET_EOF when the peer closed the stream first, NET_SOCKET_ERROR on error.

Source

fn send(sock: *const c_void, buf: *const u8, len: usize) -> usize

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 — possibly fewer than len, and 0 when none were taken in that time — or usize::MAX when the connection is broken. Never waits for a peer that stopped reading (issue 2389); the caller loops and owns the stall bound (nros_platform_tcp_send).

Provided Methods§

Source

fn set_rx_notify( _sock: *const c_void, _notify: Option<unsafe extern "C" fn(*mut c_void)>, _ctx: *mut c_void, ) -> i8

phase-521 W6 (RFC-0113 D4) — install (Some) or remove (None) the connected socket’s receive notification, called from the stack’s own context each time data is queued, so it must only signal.

Default -1: this stack has no such hook.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl PlatformTcp for CffiPlatform

Source§

fn create_endpoint(ep: *mut c_void, address: *const u8, port: *const u8) -> i8

Source§

fn free_endpoint(ep: *mut c_void)

Source§

fn open(sock: *mut c_void, endpoint: *const c_void, timeout_ms: u32) -> i8

Source§

fn open_within( sock: *mut c_void, endpoint: *const c_void, timeout_ms: u32, connect_timeout_ms: i32, ) -> i8

Source§

fn listen(sock: *mut c_void, endpoint: *const c_void) -> i8

Source§

fn close(sock: *mut c_void)

Source§

fn read(sock: *const c_void, buf: *mut u8, len: usize) -> usize

Source§

fn read_exact(sock: *const c_void, buf: *mut u8, len: usize) -> usize

Source§

fn send(sock: *const c_void, buf: *const u8, len: usize) -> usize

Source§

fn set_rx_notify( sock: *const c_void, notify: Option<unsafe extern "C" fn(*mut c_void)>, ctx: *mut c_void, ) -> i8

Implementors§