net::tcp
Index
Types
type backlog = u32;
type connect_option = (keepalive | net::sockflag);
type keepalive = void;
type listen_option = (keepalive | reuseport | reuseaddr | backlog | portassignment | net::sockflag);
type portassignment = *u16;
type reuseaddr = void;
type reuseport = void;
Functions
fn accept(sock: net::socket, flags: net::sockflag = 0) (net::socket | net::error);
fn connect(addr: ip::addr, port: u16, options: connect_option...) (net::socket | net::error);
fn listen(addr: ip::addr, port: u16, options: listen_option...) (net::socket | net::error);
fn peeraddr(peer: net::socket) ((ip::addr, u16) | void);
Types
type backlog
type backlog = u32;
Configures the backlog size for a listener. If not specified, a sensible default (10) is used.
type connect_option
type connect_option = (keepalive | net::sockflag);
Options for connect.
type keepalive
type keepalive = void;
Enables keep-alive for a socket.
type listen_option
type listen_option = (keepalive | reuseport | reuseaddr | backlog | portassignment | net::sockflag);
Options for listen.
type portassignment
type portassignment = *u16;
To have the system select an arbitrary unused port for listen, set port to zero. To retrieve the assigned port, provide this as one of the options and the addressed u16 will be filled in with the port.
type reuseaddr
type reuseaddr = void;
Enables address re-use for a TCP listener.
type reuseport
type reuseport = void;
Enables port re-use for a TCP listener.
Functions
fn accept
fn accept(sock: net::socket, flags: net::sockflag = 0) (net::socket | net::error);
Accepts the next connection from a socket. Blocks until a new connection is available. This is a convenience wrapper around net::accept.
fn connect
fn connect(addr: ip::addr, port: u16, options: connect_option...) (net::socket | net::error);
Opens a TCP connection to the given host and port. Blocks until the connection is established.
fn listen
fn listen(addr: ip::addr, port: u16, options: listen_option...) (net::socket | net::error);
Binds a TCP socket to the given address.
fn peeraddr
fn peeraddr(peer: net::socket) ((ip::addr, u16) | void);
Returns the remote address for a given connection, or void if none is available.