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 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;
}
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 (see Phase 80 design).

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 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, or usize::MAX on error.

Source

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

Read exactly len bytes. Returns len on success, usize::MAX on error.

Source

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

Send len bytes. Returns bytes sent, or usize::MAX on error.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§