Skip to main content

socket

include "socket";

TCP network connections: connect to a server or listen for clients, then send and receive bytes.

Types​

socket​

Native object

accept​

fn accept() -> socket

Waits for and returns the next connection.

receive​

fn receive(buffer buffer, int offset, int count) -> int

Reads up to count bytes into buffer at offset; 0 at end of stream.

send​

fn send(buffer buffer, int offset, int count) -> int

Writes up to count bytes from buffer at offset and returns how many were sent.

set_read_deadline​

fn set_read_deadline(float seconds)

Makes later receives fail once seconds pass without data.

clear_read_deadline infallible​

infallible fn clear_read_deadline()

Removes the read deadline, so receives wait as long as it takes.

close infallible​

infallible fn close()

Closes the socket.

shutdown_read infallible​

infallible fn shutdown_read() -> int

Stops receiving; returns 0 or an error code.

shutdown_write infallible​

infallible fn shutdown_write() -> int

Stops sending; returns 0 or an error code.

shutdown infallible​

infallible fn shutdown() -> int

Stops both directions; returns 0 or an error code.

Functions​

socket_connect_tcp​

fn socket_connect_tcp(string host, string service, int family) -> socket

Connects to host:service over TCP. family selects the address family (0 for any).

socket_listen_tcp​

fn socket_listen_tcp(string host, string service, int family, int backlog) -> socket

Listens for TCP connections on host:service with the given backlog.