Expand description
Sockets: TCP, UDP and Unix domain, as Handles.
Each type keeps std’s own socket inside; the handle adds the async
operations (accept, connect, send, recv, peek, send_to,
recv_from, peek_from) and, for the streams, AsyncRead and
AsyncWrite on the handle and on a shared reference to it, so two tasks
can read and write one stream at once. A stream’s read_owned and
write_owned take the caller’s buffer (any IoBuf
or IoBufMut) and give it back, so the driver
reads into it and writes from it with no copy, and read_vectored_owned
and write_vectored_owned do the same with several buffers in one call;
a TCP stream’s write_zero_copy asks the kernel not to copy it either,
and gives it back through a Released once the kernel let go of it.
send_file sends a range of a file to a stream.
A stream ends with shut, std’s shutdown made once
the bytes written behind reached the kernel, or for TCP with
abort, which resets the connection now.
TcpSocket and UdpSocketBuilder set a socket up before it listens,
connects or binds, and TcpKeepalive times a TCP connection’s
keepalive probes.
An address is anything ToSocketAddrs takes: numbers are used at
once; a name ("localhost:80") is looked up on the blocking pool, so no
shard waits on the resolver. lookup_host looks one up alone.
use nuclei::net::{TcpListener, TcpStream};
let listener = TcpListener::bind("127.0.0.1:0").await?;
let addr = listener.get_ref().local_addr()?;
let client = TcpStream::connect(addr).await?;
let (server, _) = listener.accept().await?;
client.send(b"hi").await?;
let mut buf = [0u8; 2];
assert_eq!(server.recv(&mut buf).await?, 2);Modules§
- unix
- Unix domain sockets: listeners, streams and datagrams, and
UCred, the credentials of a stream’s peer; and Unix pipes (pipe).
Structs§
- Device
Name - A network interface’s name, as
bind_devicetakes it: up to 16 bytes, held in place. - Owned
Read Half - The read half of a stream, owning it with the write half.
- Owned
Write Half - The write half of a stream, owning it with the read half.
- Read
Half - The read half of a stream, borrowed from it.
- Released
- The buffer of a
TcpStream::write_zero_copy, as a future that resolves to it once the kernel let go of every byte. For a send the kernel did not copy, that is once the peer acknowledged the bytes, which may be long after the write ended. - Reunite
Error - Two halves of different streams, given back by
OwnedReadHalf::reunite. - TcpKeepalive
- When an idle connection’s keepalive probes start, how far apart they go, and how many
unanswered ones drop the connection. A field left
Nonekeeps the system’s value. - TcpSocket
- A TCP socket to set up before it connects or listens.
- TcpStream
Generator - The connections of a listener, as
Handle::accept_multimakes them. - UdpSocket
Builder - A UDP socket to set up before it binds: what only a socket not bound yet takes
(
SO_REUSEPORTamong sockets that share a port,IPV6_V6ONLY, a device), and the rest before the first datagram. - Unix
Socket - A Unix domain socket, of streams or of datagrams, to bind before it connects, listens or sends.
- Write
Half - The write half of a stream, borrowed from it.
Traits§
- ToSocket
Addrs - What an operation that takes an address accepts: a
SocketAddr, an(IpAddr, u16)pair, a slice or array of addresses, or a string,"host:port"or("host", port). Numbers are used as they are; a name is looked up on the blocking pool (getaddrinfo), never on the calling thread.
Functions§
- lookup_
host - Every address
hostnames: numbers at once, a name looked up on the blocking pool. The iterator owns what it walks, so a slice given here is copied into it; the operations that take an address walk it in place.
Type Aliases§
- TcpListener
- A TCP listener: std’s, with an async
accept. - TcpStream
- A TCP stream: std’s, with async reads and writes. A few of std’s calls
reached through
Derefgo around the handle (shutdownamong them): seeHandle. - UdpSocket
- A UDP socket: std’s, with async sends and receives. Its
connectmakes a socket;socket.connect(addr)on one is std’s own (see there). - Unix
Datagram - A Unix datagram socket: std’s, with async sends and receives.
- Unix
Listener - A Unix stream listener: std’s, with an async
accept. - Unix
Stream - A Unix stream: std’s, with async reads and writes. A few of std’s calls
reached through
Derefgo around the handle (shutdownamong them): seeHandle.