Struct fd_queue::UnixListener
source · [−]pub struct UnixListener { /* private fields */ }Expand description
A structure representing a Unix domain socket server whose connected sockets
have support for passing RawFd.
Implementations
sourceimpl 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<'_>ⓘNotable traits for Incoming<'_>impl Iterator for Incoming<'_> type Item = Result<UnixStream>;
pub fn incoming(&self) -> Incoming<'_>ⓘNotable traits for Incoming<'_>impl Iterator for Incoming<'_> type Item = Result<UnixStream>;
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
sourceimpl AsRawFd for UnixListener
impl AsRawFd for UnixListener
sourceimpl Debug for UnixListener
impl Debug for UnixListener
sourceimpl From<UnixListener> for UnixListener
impl From<UnixListener> for UnixListener
sourcefn from(inner: StdUnixListner) -> Self
fn from(inner: StdUnixListner) -> Self
Converts to this type from the input type.
sourceimpl FromRawFd for UnixListener
impl FromRawFd for UnixListener
sourceunsafe fn from_raw_fd(fd: RawFd) -> Self
unsafe fn from_raw_fd(fd: RawFd) -> Self
Constructs a new instance of Self from the given raw file
descriptor. Read more
sourceimpl<'a> IntoIterator for &'a UnixListener
impl<'a> IntoIterator for &'a UnixListener
sourceimpl IntoRawFd for UnixListener
impl IntoRawFd for UnixListener
sourcefn into_raw_fd(self) -> RawFd
fn into_raw_fd(self) -> RawFd
Consumes this object, returning the raw underlying file descriptor. Read more
sourceimpl TryFrom<UnixListener> for UnixListener
impl TryFrom<UnixListener> for UnixListener
sourcefn try_from(inner: UnixListener) -> Result<UnixListener>
fn try_from(inner: UnixListener) -> Result<UnixListener>
Performs the conversion.
Auto Trait Implementations
impl RefUnwindSafe for UnixListener
impl Send for UnixListener
impl Sync for UnixListener
impl Unpin for UnixListener
impl UnwindSafe for UnixListener
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more