pub struct UnixListener { /* private fields */ }local only.Expand description
A Unix domain socket listener. Dropping it removes its socket file, but only while the path still names the file this listener created.
let listener = net_io::UnixListener::bind("/run/myapp/control.sock")?;
let (mut conn, info) = listener.accept()?;
println!("uid {:?}", info.peer_credentials.and_then(|c| c.uid));
conn.send_all(b"ready\n")?;Implementations§
Source§impl UnixListener
impl UnixListener
Sourcepub fn bind<P: AsRef<Path>>(path: P) -> Result<UnixListener, NetError>
pub fn bind<P: AsRef<Path>>(path: P) -> Result<UnixListener, NetError>
Binds path with LocalOptions::new: mode 0600, a stale socket file removed.
§Errors
PathTooLong, StaleSocketInUse, PermissionDenied, NotFound (no such
directory), InvalidConfig { field: "path" }, Os.
Sourcepub fn bind_with<P: AsRef<Path>>(
path: P,
options: LocalOptions,
) -> Result<UnixListener, NetError>
pub fn bind_with<P: AsRef<Path>>( path: P, options: LocalOptions, ) -> Result<UnixListener, NetError>
Binds path with options: the socket is bound, given its mode and owner,
and only then listens, so no connection is accepted under the umask’s
permissions.
§Errors
Sourcepub fn bind_atomic<P: AsRef<Path>>(
path: P,
options: LocalOptions,
) -> Result<UnixListener, NetError>
pub fn bind_atomic<P: AsRef<Path>>( path: P, options: LocalOptions, ) -> Result<UnixListener, NetError>
As UnixListener::bind_with, but bound under a temporary name in the
same directory and renamed into place once it listens with its final
mode: the path never names a socket that refuses or is not ready.
§Errors
Sourcepub fn accept(&self) -> Result<(UnixConnection, ConnectionInfo), NetError>
pub fn accept(&self) -> Result<(UnixConnection, ConnectionInfo), NetError>
Blocks until a connection arrives. Peer credentials are read once and
stored in ConnectionInfo; with require_uid, other users’ connections
are closed before any read and accepting continues.
§Errors
Limit { which: Descriptors } when exhaustion persists past one backoff step; Os.
Sourcepub fn accept_timeout(
&self,
timeout: Duration,
) -> Result<Option<(UnixConnection, ConnectionInfo)>, NetError>
pub fn accept_timeout( &self, timeout: Duration, ) -> Result<Option<(UnixConnection, ConnectionInfo)>, NetError>
As UnixListener::accept, but Ok(None) when nothing arrived within timeout.
§Errors
Sourcepub fn info(&self) -> &ListenerInfo
pub fn info(&self) -> &ListenerInfo
Facts about this listener.