Struct 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§

Source§

impl UnixListener

Source

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(());
    }
};
Source

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(());
    }
};
Source

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(());
    }
};
Source

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(());
    }
};
Source

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(())
    }
};
Source

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

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Debug for UnixListener

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<UnixListener> for UnixListener

Source§

fn from(inner: StdUnixListner) -> Self

Converts to this type from the input type.
Source§

impl FromRawFd for UnixListener

Source§

unsafe fn from_raw_fd(fd: RawFd) -> Self

Constructs a new instance of Self from the given raw file descriptor. Read more
Source§

impl<'a> IntoIterator for &'a UnixListener

Source§

type Item = Result<UnixStream, Error>

The type of the elements being iterated over.
Source§

type IntoIter = Incoming<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoRawFd for UnixListener

Source§

fn into_raw_fd(self) -> RawFd

Consumes this object, returning the raw underlying file descriptor. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more