net.nx
buildroot/runtime/net.nx
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
imports: syscalls.nxstdlib.nx
imported by: nobody (leaf or entry point)
structs
| 53 | struct SockAddrIn { |
consts
| 36 | const SYS_SOCKET: i64 = 198 |
| 37 | const SYS_BIND: i64 = 200 |
| 38 | const SYS_LISTEN: i64 = 201 |
| 39 | const SYS_ACCEPT: i64 = 202 |
| 40 | const SYS_CONNECT: i64 = 203 |
| 41 | const SYS_SENDTO: i64 = 206 |
| 42 | const SYS_RECVFROM: i64 = 207 |
| 43 | const SYS_SETSOCKOPT: i64 = 208 |
| 45 | const AF_INET: i64 = 2 |
| 46 | const SOCK_STREAM: i64 = 1 |
| 47 | const SOCK_DGRAM: i64 = 2 |
| 250 | const SOL_SOCKET: i64 = 1 |
| 251 | const SO_REUSEADDR: i64 = 2 |
| 252 | const SO_REUSEPORT: i64 = 15 |
functions
| 77 | func net_errno_to(e: i64) -> i64 { |
| 94 | func net_tcp_raw() -> i64 {
called by 1: net_tcp |
| 98 | func net_udp_raw() -> i64 {
called by 1: net_udp |
| 103 | func net_tcp() -> *Result<i64, NetError> { |
| 109 | func net_udp() -> *Result<i64, NetError> { |
| 117 | func net_close(fd: i64) -> *Result<i64, NetError> {
calls 1: net_errno_to |
| 127 | func net_addr_any(sa: *SockAddrIn, port: i64) -> i64 { |
| 144 | func net_addr(sa: *SockAddrIn, port: i64, ip: i64) -> i64 { |
| 157 | func net_bind_raw(fd: i64, sa: *SockAddrIn) -> i64 {
called by 1: net_bind |
| 161 | func net_bind(fd: i64, sa: *SockAddrIn) -> *Result<i64, NetError> { |
| 169 | func net_listen_raw(fd: i64, backlog: i64) -> i64 {
called by 1: net_listen |
| 173 | func net_listen(fd: i64, backlog: i64) -> *Result<i64, NetError> { |
| 183 | func net_accept_raw(fd: i64, peer: *SockAddrIn,
called by 1: net_accept |
| 189 | func net_accept(fd: i64, peer: *SockAddrIn, |
| 199 | func net_connect_raw(fd: i64, sa: *SockAddrIn) -> i64 {
called by 1: net_connect |
| 203 | func net_connect(fd: i64, sa: *SockAddrIn) -> *Result<i64, NetError> { |
| 219 | func net_send(fd: i64, buf: *u8, n: i64) -> i64 {
called by 1: net_send_all_raw |
| 225 | func net_recv(fd: i64, buf: *u8, n: i64) -> i64 { |
| 230 | func net_send_all_raw(fd: i64, buf: *u8, n: i64) -> i64 { |
| 242 | func net_send_all(fd: i64, buf: *u8, n: i64) -> *Result<i64, NetError> { |
| 256 | func net_set_reuseaddr(fd: i64) -> i64 { |