Module syscall

Module syscall 

Source
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

  1. Handle-based: Returns handle IDs instead of file descriptors
  2. Scarlet-native: Uses LocalSocket for IPC, not POSIX Unix domain sockets
  3. Path-based naming: Sockets are identified by filesystem-like paths
  4. 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 path
  • sys_socket_listen() - Start listening for connections
  • sys_socket_connect() - Connect to a named socket
  • sys_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§

NetworkSetIpv4Request 🔒

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