Skip to main content

SharedSocket

Type Alias SharedSocket 

Source
pub type SharedSocket = Arc<dyn AsFd + Send + Sync>;
Available on Unix only.
Expand description

A socket as a Driver registers it: shared, so the driver keeps it open until Driver::deregister whatever the caller drops. Any Arc of a socket type converts (Arc<TcpStream>, Arc<TcpListener>, Arc<OwnedFd>); keep a clone to accept from a listener or to read the socket’s options.

The driver works on the descriptor as_fd returns at registration, so the value must keep returning the same one while registered, as every std socket type does.

use std::sync::Arc;
let listener = Arc::new(std::net::TcpListener::bind("127.0.0.1:0").unwrap());
let shared: net_io::SharedSocket = listener.clone();

Aliased Type§

pub struct SharedSocket { /* private fields */ }