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: UdpSocket
addr: SocketAddr
Implementations
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(())
}
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(())
}