code wiki / (root) / net.nx

net.nx

buildroot/runtime/net.nx

9400 B262 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind orphan librarytopic net
docsdependenciesstructsconstsfunctions

about

net.nx -- BSD-style socket primitives (Phase G2). Typed wrappers around Linux/NishiOS socket syscalls. Fallible public calls return `*Result<i64, NetError>` -- the Ok payload is an fd (for socket / accept) or a byte count (for send / recv) or 0 (for bind / listen / connect). Raw `_raw` variants keep the bare syscall return for callers that want the i64 directly (e.g. tight send loops). Syscall numbers (Linux RV64, NishiOS matches): 198 socket 200 bind 201 listen 202 accept 203 connect 206 sendto (we use as send) 207 recvfrom (we use as recv) 208 setsockopt 209 getsockopt Address families (SOL): AF_INET = 2 (IPv4) AF_INET6 = 10 (IPv6) Socket types: SOCK_STREAM = 1 (TCP) SOCK_DGRAM = 2 (UDP) The typed variant struct SockAddrIn matches Linux's `struct sockaddr_in` exactly (16 bytes): sin_family + sin_port (big- endian) + sin_addr + 8 bytes of padding.

dependencies 2 imports · 0 importers

syscalls.nx stdlib.nx net.nx

imports: syscalls.nxstdlib.nx

imported by: nobody (leaf or entry point)

structs

53struct SockAddrIn {

consts

36const SYS_SOCKET: i64 = 198
37const SYS_BIND: i64 = 200
38const SYS_LISTEN: i64 = 201
39const SYS_ACCEPT: i64 = 202
40const SYS_CONNECT: i64 = 203
41const SYS_SENDTO: i64 = 206
42const SYS_RECVFROM: i64 = 207
43const SYS_SETSOCKOPT: i64 = 208
45const AF_INET: i64 = 2
46const SOCK_STREAM: i64 = 1
47const SOCK_DGRAM: i64 = 2
250const SOL_SOCKET: i64 = 1
251const SO_REUSEADDR: i64 = 2
252const SO_REUSEPORT: i64 = 15

functions

77func net_errno_to(e: i64) -> i64 {
94func net_tcp_raw() -> i64 {
called by 1: net_tcp
98func net_udp_raw() -> i64 {
called by 1: net_udp
103func net_tcp() -> *Result<i64, NetError> {
109func net_udp() -> *Result<i64, NetError> {
117func net_close(fd: i64) -> *Result<i64, NetError> {
calls 1: net_errno_to
127func net_addr_any(sa: *SockAddrIn, port: i64) -> i64 {
144func net_addr(sa: *SockAddrIn, port: i64, ip: i64) -> i64 {
157func net_bind_raw(fd: i64, sa: *SockAddrIn) -> i64 {
called by 1: net_bind
161func net_bind(fd: i64, sa: *SockAddrIn) -> *Result<i64, NetError> {
169func net_listen_raw(fd: i64, backlog: i64) -> i64 {
called by 1: net_listen
173func net_listen(fd: i64, backlog: i64) -> *Result<i64, NetError> {
183func net_accept_raw(fd: i64, peer: *SockAddrIn,
called by 1: net_accept
189func net_accept(fd: i64, peer: *SockAddrIn,
199func net_connect_raw(fd: i64, sa: *SockAddrIn) -> i64 {
called by 1: net_connect
203func net_connect(fd: i64, sa: *SockAddrIn) -> *Result<i64, NetError> {
219func net_send(fd: i64, buf: *u8, n: i64) -> i64 {
called by 1: net_send_all_raw
225func net_recv(fd: i64, buf: *u8, n: i64) -> i64 {
230func net_send_all_raw(fd: i64, buf: *u8, n: i64) -> i64 {
called by 1: net_send_all calls 1: net_send
242func net_send_all(fd: i64, buf: *u8, n: i64) -> *Result<i64, NetError> {
256func net_set_reuseaddr(fd: i64) -> i64 {