Expand description
Socket System Calls for Scarlet Native
This module implements socket system calls specifically for Scarlet Native. Unlike POSIX sockets, these are designed around Scarlet’s handle-based architecture.
§Design Principles
- Handle-based: Returns handle IDs instead of file descriptors
- Scarlet-native: Uses LocalSocket for IPC, not POSIX Unix domain sockets
- Path-based naming: Sockets are identified by filesystem-like paths
- Simple and direct: Minimal abstraction for kernel IPC
§System Call Interface
sys_socket_create()- Create a new socket (returns handle ID)sys_socket_bind()- Bind socket to a pathsys_socket_listen()- Start listening for connectionssys_socket_connect()- Connect to a named socketsys_socket_accept()- Accept an incoming connection (returns new handle)sys_socketpair()- Create a connected socket pair (for IPC)sys_socket_shutdown()- Shutdown socket (read, write, or both)
§Usage Example
ⓘ
// Server side
let server_handle = sys_socket_create();
sys_socket_bind(server_handle, "/tmp/server.sock");
sys_socket_listen(server_handle, 5);
let client_handle = sys_socket_accept(server_handle);
// Client side
let client_handle = sys_socket_create();
sys_socket_connect(client_handle, "/tmp/server.sock");
// IPC pair (simpler)
let [handle1, handle2] = sys_socketpair();Structs§
Functions§
- read_
user_ 🔒ipv4 - read_
user_ 🔒string - sys_
network_ list_ interfaces - sys_
network_ set_ dns - sys_
network_ set_ gateway - sys_
network_ set_ ipv4 - sys_
network_ set_ netmask - sys_
socket_ accept - System call: Accept an incoming connection
- sys_
socket_ bind - System call: Bind socket to a path
- sys_
socket_ connect - System call: Connect to a named socket
- sys_
socket_ create - System call: Create a new socket
- sys_
socket_ listen - System call: Listen for connections
- sys_
socket_ recvfrom - System call: Receive datagram with sender address
- sys_
socket_ sendto - System call: Send datagram to specified address
- sys_
socket_ shutdown - System call: Shutdown socket
- sys_
socketpair - System call: Create a connected socket pair