pub struct UnixListener { /* private fields */ }
Expand description
A structure representing a Unix domain socket server whose connected sockets
have support for passing RawFd
.
Implementations§
Source§impl UnixListener
impl UnixListener
Sourcepub fn bind(path: impl AsRef<Path>) -> Result<UnixListener>
pub fn bind(path: impl AsRef<Path>) -> Result<UnixListener>
Create a new UnixListener
bound to the specified socket.
§Examples
use fd_queue::UnixListener;
// let path = ...
let listener = match UnixListener::bind(&path) {
Ok(listener) => listener,
Err(e) => {
println!("Can't bind the unix socket libtest: {}", e);
return Ok(());
}
};
Sourcepub fn accept(&self) -> Result<(UnixStream, SocketAddr)>
pub fn accept(&self) -> Result<(UnixStream, SocketAddr)>
Accepts a new incoming connection to this server.
This function will block the calling thread until a new Unix connection is
established. When established the corresponding UnixStream
and the remote
peer’s address will be returned.
§Examples
use fd_queue::UnixListener;
// let path = ...
let listener = UnixListener::bind(&path)?;
let (sock, addr) = match listener.accept() {
Ok((sock, addr)) => (sock, addr),
Err(e) => {
println!("Can't accept unix stream: {}", e);
return Ok(());
}
};
Sourcepub fn try_clone(&self) -> Result<UnixListener>
pub fn try_clone(&self) -> Result<UnixListener>
Create a new independently owned handle to the underlying socket.
The returned UnixListener
is a reference to the same socket that this
object references. Both handles can be used to accept incoming connections
and options set on one will affect the other.
§Examples
use fd_queue::UnixListener;
// let path = ...
let listener1 = UnixListener::bind(&path)?;
let listener2 = match listener1.try_clone() {
Ok(listener) => listener,
Err(e) => {
println!("Can't clone listener: {}", e);
return Ok(());
}
};
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Returns the local address of of this listener.
§Examples
use fd_queue::UnixListener;
// let path = ...
let listener = UnixListener::bind(&path)?;
let addr = match listener.local_addr() {
Ok(addr) => addr,
Err(e) => {
println!("Couldn't get local address: {}", e);
return Ok(());
}
};
Sourcepub fn take_error(&self) -> Result<Option<Error>>
pub fn take_error(&self) -> Result<Option<Error>>
Return the value of the SO_ERROR
option.
§Examples
use fd_queue::UnixListener;
// let path = ...
let listener = UnixListener::bind(&path)?;
let err = match listener.take_error() {
Ok(Some(err)) => err,
Ok(None) => {
println!("There was no SO_ERROR option pending.");
return Ok(());
}
Err(e) => {
println!("Couldn't get the SO_ERROR option: {}", e);
return Ok(())
}
};
Sourcepub fn incoming(&self) -> Incoming<'_> ⓘ
pub fn incoming(&self) -> Incoming<'_> ⓘ
Returns an iterator over incoming connections.
The iterator will never return None
and also will not yield the peer’s
SocketAddr
structure.
§Examples
use fd_queue::UnixListener;
// let path = ...
let listener = UnixListener::bind(&path)?;
let mut incoming = listener.incoming();
let sock = match incoming.next() {
Some(Ok(sock)) => sock,
Some(Err(e)) => {
println!("Can't get the next incoming socket: {}", e);
return Ok(());
}
None => unreachable!(),
};
Trait Implementations§
Source§impl AsRawFd for UnixListener
impl AsRawFd for UnixListener
Source§impl Debug for UnixListener
impl Debug for UnixListener
Source§impl From<UnixListener> for UnixListener
impl From<UnixListener> for UnixListener
Source§fn from(inner: StdUnixListner) -> Self
fn from(inner: StdUnixListner) -> Self
Source§impl FromRawFd for UnixListener
impl FromRawFd for UnixListener
Source§unsafe fn from_raw_fd(fd: RawFd) -> Self
unsafe fn from_raw_fd(fd: RawFd) -> Self
Self
from the given raw file
descriptor. Read more