Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

net

fuzion.sys.net

groups networking related features

internally this builds on:
- java: nio
- why not java.net.Socket etc.?: this is only suitable for blocking I/O
- why not nio2? : nio2 is basically the same as nio but asynchronous.

- c/posix: posix-sockets
- c/win: winsock2

sources of inspiration:
- https://github.com/tezc/sc/
- https://github.com/jart/cosmopolitan
- https://learn.microsoft.com/en-us/windows/win32/winsock/complete-server-code
- https://learn.microsoft.com/en-us/windows/win32/winsock/complete-client-code

NYI: use error codes coming from backend
§accept(sd i64, arr_result Any)
 => 
bool
:
Any 
accept a new connection for given socket descriptor.
may block until there is a connection to accept.
returns a new / different descriptor which
corresponds to the accepted connection only.

true => arr_result[0] is the socket descriptor
false => arr_result[0] is an error number
accept a new connection for given socket descriptor, wrapper for accept intrinsic.
returns an error or a new descriptor.
§bind(family i32, socket_type i32, protocol i32, host String, port u16)
 => 
outcome i64
:
Any 
bind a name to a newly created socket, wrapper for bind0 intrinsic
§bind0(family i32, socket_type i32, protocol i32, host Any, port Any, arr_result Any)
 => 
i32
:
Any 
bind a name to a newly created socket

0 => arr_result[0] is the socket descriptor
-1 => arr_result[0] is an error number
close socket descriptor
close socket

returns zero on success, anything else is an error.
§connect(family i32, socket_type i32, protocol i32, host String, port u16)
 => 
outcome i64
:
Any 
open and connect a client socket
§connect0(family i32, socket_type i32, protocol i32, host Any, port Any, arr_result Any)
 => 
i32
:
Any 
open and connect a client socket

0 => arr_result[0] is the socket descriptor
-1 => arr_result[0] is an error number
§listen(sd i64, backlog i32)
 => 
i32
:
Any 
activates a server socket, setting a backlog
of a maximum amount of connections which are kept
waiting for acceptance.

returns zero on success, anything else is an error.
§read(descriptor i64, max_bytes i32)
 => 
outcome (array u8)
:
Any 
read a maximum of max_bytes from descriptor, wrapper for read intrinsic
may block if descriptor is set to blocking.
§read(sd i64, arr_data Any, length i32, arr_result Any)
 => 
bool
:
Any 
read bytes into arr_data buffer

true => arr_result[0] is the number of bytes read
false => arr_result[0] is an error number
set descriptor to blocking / none blocking mode.
§set_blocking0(sd i64, blocking i32)
 => 
i32
:
Any 
0 = blocking, 1 = none_blocking

returns zero on success, anything else is an error.

NYI non blocking needs some kind of polling mechanism like epoll / kqueue
probably not good enough:
- select "can monitor only file descriptors numbers

- poll is in O(n)
difficult to implement on windows, read here: https://notgull.github.io/device-afd/
§write(descriptor i64, data array u8)
 => 
outcome unit
:
Any 
write data to descriptor, wrapper for write intrinsic
may block if descriptor is set to blocking.
§write(sd i64, arr_data Any, length i32)
 => 
i32
:
Any 
write buffer bytes on socket

returns zero on success, anything else is an error.