Struct quic_socket::QuicSocket [−][src]
pub struct QuicSocket {
pub inner: UdpSocket,
pub addr: SocketAddr,
}Expand description
A QUIC socket that has not yet been converted to a QuicListener.
QuicSocket wraps an underlying operating system UDP socket and enables the caller to
configure the socket before establishing a QUIC connection or accepting
inbound connections. The caller is able to set socket option and explicitly
bind the socket with a socket address.
The underlying socket is closed when the UdpSocket value is dropped.
UdpSocket should only be used directly if the default configuration used
by QuicListener::bind does not meet the required use case.
Fields
inner: UdpSocketaddr: SocketAddrImplementations
Create a new underlying UDP socket and attempts to bind it to the addr provided
Examples
use quic::QuicSocket;
#[tokio::main]
async fn main() -> io::Result<()> {
let addr = "127.0.0.1:8080".parse().unwrap();
let socket = QuickSocket::bind(addr);
Ok(())
}Creates new QuicSocket from a previously bound std::net::UdpSocket.
The conversion assumes nothing about the underlying socket; it is left up to the user to set it in non-blocking mode.
Example
use quic::QuicSocket;
let addr = "0.0.0.0:8080".parse::<SocketAddr>().unwrap();
let std_sock = std::net::UdpSocket::bind(addr)?;
std_sock.set_nonblocking(true)?;
let sock = QuicSocket::from_std(std_sock)?;
// use `sock`Accept a QUIC connection from a peer at the specified socket address.
The QuicSocket is consumed. Once the connection is established, a
connected QuicListener is returned. If the connection fails, the
encountered error is returned.
Examples
Connecting to a peer.
use quic::QuicSocket;
use std::io;
#[tokio::main]
async fn main() -> io::Result<()> {
let addr = "127.0.0.1:8080".parse().unwrap();
let socket = QuicSocket::bind(addr).await?;
let listener = socket.accept(addr)?;
Ok(())
}Establish a QUIC connection with a peer at the specified socket address.
The QuicSocket is consumed. Once the connection is established, a
connected QuicListener is returned. If the connection fails, the
encountered error is returned.
Examples
Connecting to a peer.
use quic::QuicSocket;
use std::io;
#[tokio::main]
async fn main() -> io::Result<()> {
let addr = "127.0.0.1:8080".parse().unwrap();
let socket = QuicSocket::bind(addr).await?;
let listener = socket.connect(addr)?;
Ok(())
}