net+x86_64 +linux

The net module provides some general-purpose interfaces and support code, but generally users are directed to the submodules, where implementations of various network protocols are provided, such as net::tcp:: or net::dns::.

A porcelain API for establishing an outgoing connection, able to automatically handle matters such as DNS resolution, is available at net::dial::.

Submodules

Index

Types

type shut = enum {
	RD, // Disables further receptions.
	WR, // Disables further transmissions.
	RDWR, // Disables further receptions and transmissions.
};
type socket = io::file;
type sockflag = enum {
	NOCLOEXEC = rt::SOCK_CLOEXEC,
	NONBLOCK = rt::SOCK_NONBLOCK,
};

// Undocumented types:
type msghdr = struct {
	native: rt::msghdr,
	vectors: []rt::iovec,
	control: []u8,
};

Errors

type error = !(unknownproto | ...errors::error);
type unknownproto = !void;

Functions

fn accept(sock: socket, flags: sockflag = 0) (socket | error);
fn addcontrol(msg: *msghdr, length: size, level: int, ctype: int) []u8;
fn addvector(msg: *msghdr, vec: []u8) void;
fn close(sock: socket) (void | error);
fn finish(msg: *msghdr) void;
fn getcontrol(msg: *msghdr, length: size, level: int, ctype: int) ([]u8 | void);
fn getflags(msg: *msghdr) int;
fn newmsg() msghdr;
fn recvmsg(sock: socket, msg: *msghdr) (size | error);
fn reset(msg: *msghdr) void;
fn sendmsg(sock: socket, msg: *msghdr) (size | error);
fn setflags(msg: *msghdr, flags: int) void;
fn setname(msg: *msghdr, name: *opaque, length: size) void;
fn shutdown(sock: socket, how: shut) (void | error);
fn strerror(err: error) const str;

Types

type shut[link]

type shut = enum {
	RD, // Disables further receptions.
	WR, // Disables further transmissions.
	RDWR, // Disables further receptions and transmissions.
};

The end of the full-duplex connection that should be shutdown.

type socket[link]

type socket = io::file;

A network socket.

type sockflag[link]

type sockflag = enum {
	NOCLOEXEC = rt::SOCK_CLOEXEC,
	NONBLOCK = rt::SOCK_NONBLOCK,
};

Optional flags to accept to be set on the returned socket. See the O_CLOEXEC and O_NONBLOCK sections of open(2) for details. Note that CLOEXEC is on by default, and NOCLOEXEC flag disables it.

type msghdr[link]

Show undocumented member
type msghdr = struct {
	native: rt::msghdr,
	vectors: []rt::iovec,
	control: []u8,
};

Errors

type error[link]

type error = !(unknownproto | ...errors::error);

All error types which can be returned from networking functions.

type unknownproto[link]

type unknownproto = !void;

An attempt was made to use an unsupported protocol.

Functions

fn accept[link]

fn accept(sock: socket, flags: sockflag = 0) (socket | error);

Accepts the next connection from a socket. Blocks until a new connection is available. Optionally accepts NOCLOEXEC and NONBLOCK flags. If flags are supplied, the io::file returned will have the supplied flags set.

fn addcontrol[link]

fn addcontrol(msg: *msghdr, length: size, level: int, ctype: int) []u8;

Adds a control message of the desired length to a msghdr, returning a buffer in which the ancillary data may be written in a domain-specific format.

This is a low-level interface, and is not generally used by users. More often, users will call functions like net::unix::addfiles or net::unix::allocfiles, which provide a high-level interface to this function for domain-specific use-cases.

fn addvector[link]

fn addvector(msg: *msghdr, vec: []u8) void;

Adds an I/O vector to the message.

fn close[link]

fn close(sock: socket) (void | error);

Closes a socket. No further operations against this socket are permitted after calling this function. Closing a socket can fail only under certain conditions (for example, closing a socket twice, or an interrupted syscall). However, the user should not attempt to close the file again on failure - at best the user should print a diagnostic message and move on. See close(2) for details.

On Linux, this function is an alias for io::close.

fn finish[link]

fn finish(msg: *msghdr) void;

Frees resources associated with a msghdr.

fn getcontrol[link]

fn getcontrol(msg: *msghdr, length: size, level: int, ctype: int) ([]u8 | void);

Retrieves a control header from a message, returning a slice of domain-specific data.

This is a low-level interface, and is not generally used by users. More often, users will call functions like net::unix::addfiles or net::unix::allocfiles, which provide a high-level interface to this function for domain-specific use-cases.

fn getflags[link]

fn getflags(msg: *msghdr) int;

Get flags for this message.

fn newmsg[link]

fn newmsg() msghdr;

Creates a new message header for advanced socket usage, with configurable I/O vectors, control messages, and other details, for use with sendmsg and recvmsg.

The user must call finish when they are done using this message for sending or receiving. The same message may be used for multiple operations before calling finish. reset may be used to "reset" a msghdr to an empty list of I/O vectors and control messages without freeing the underlying memory, which may be useful if future messages are expected to have similar characteristics.

fn recvmsg[link]

fn recvmsg(sock: socket, msg: *msghdr) (size | error);

Receives a message from a socket. See newmsg for details.

fn reset[link]

fn reset(msg: *msghdr) void;

Resets a message header, clearing out any I/O vectors or control messages, without freeing the underlying memory. This allows the user to configure new vectors or control messages without a re-allocation, which improves performance if the new configuration fits into the same amount of memory.

fn sendmsg[link]

fn sendmsg(sock: socket, msg: *msghdr) (size | error);

Sends a message to a socket. See newmsg for details.

fn setflags[link]

fn setflags(msg: *msghdr, flags: int) void;

Sets flags for this message.

fn setname[link]

fn setname(msg: *msghdr, name: *opaque, length: size) void;

Sets name for this message.

fn shutdown[link]

fn shutdown(sock: socket, how: shut) (void | error);

Shuts down part of a full-duplex connection.

fn strerror[link]

fn strerror(err: error) const str;

Converts an error into a human-readable string.