net
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 sockflags;
type msghdr;
Errors
type error;
type unknownproto;
Functions
fn accept(io::file, sockflags...) (io::file | error);
fn addcontrol(*msghdr, size, int, int) []u8;
fn addvector(*msghdr, []u8) void;
fn finish(*msghdr) void;
fn getcontrol(*msghdr, size, int, int) ([]u8 | void);
fn newmsg() msghdr;
fn recvmsg(io::file, *msghdr) (size | error);
fn reset(*msghdr) void;
fn sendmsg(io::file, *msghdr) (size | error);
fn setflags(*msghdr, int) void;
fn shutdown(io::file) void;
fn strerror(error) const str;
Types
type sockflags
type sockflags = enum {
CLOEXEC = rt::SOCK_CLOEXEC,
NONBLOCK = rt::SOCK_NONBLOCK,
};
Optional flags to accept to be set on the returned io::file.
See the O_CLOEXEC and O_NONBLOCK sections of open(2) for details.
type msghdr
Show undocumented member
type msghdr = struct {
native: rt::msghdr,
vectors: []rt::iovec,
control: []u8,
};
Errors
type error
type error = !(unknownproto | ...errors::error);
All error types which can be returned from networking functions.
type unknownproto
type unknownproto = !void;
An attempt was made to use an unsupported protocol.
Functions
fn accept
fn accept(sock: io::file, flags: sockflags...) (io::file | error);
Accepts the next connection from a socket. Blocks until a new connection is
available. Optionally accepts CLOEXEC and NONBLOCK flags. If flags are
supplied, the io::file returned will have the supplied flags set.
If no flags are supplied, CLOEXEC is used by default.
fn addcontrol
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::prepfiles, which provide a high-level interface to this
function for domain-specific use-cases.
fn addvector
fn addvector(msg: *msghdr, vec: []u8) void;
Adds an I/O vector to the message.
fn finish
fn finish(msg: *msghdr) void;
Frees resources associated with a msghdr.
fn getcontrol
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::prepfiles, which provide a high-level interface to this
function for domain-specific use-cases.
fn newmsg
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
fn recvmsg(sock: io::file, msg: *msghdr) (size | error);
Receives a message from a socket. See newmsg for details.
fn reset
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
fn sendmsg(sock: io::file, msg: *msghdr) (size | error);
Sends a message to a socket. See newmsg for details.
fn setflags
fn setflags(msg: *msghdr, flags: int) void;
Sets flags for this message.
fn shutdown
fn shutdown(sock: io::file) void;
Shuts down a listening socket.
fn strerror
fn strerror(err: error) const str;
Converts an error into a human-readable string.