[][src]Struct fd_queue::UnixListener

pub struct UnixListener { /* fields omitted */ }

A structure representing a Unix domain socket server whose connected sockets have support for passing RawFd.

Implementations

impl UnixListener[src]

pub fn bind(path: impl AsRef<Path>) -> Result<UnixListener>[src]

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

pub fn accept(&self) -> Result<(UnixStream, SocketAddr)>[src]

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

pub fn try_clone(&self) -> Result<UnixListener>[src]

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

pub fn local_addr(&self) -> Result<SocketAddr>[src]

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

pub fn take_error(&self) -> Result<Option<Error>>[src]

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

pub fn incoming(&self) -> Incoming<'_>

Notable traits for Incoming<'_>

impl Iterator for Incoming<'_> type Item = Result<UnixStream>;
[src]

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

impl AsRawFd for UnixListener[src]

impl Debug for UnixListener[src]

impl From<UnixListener> for UnixListener[src]

impl FromRawFd for UnixListener[src]

impl<'a> IntoIterator for &'a UnixListener[src]

type Item = Result<UnixStream>

The type of the elements being iterated over.

type IntoIter = Incoming<'a>

Which kind of iterator are we turning this into?

impl IntoRawFd for UnixListener[src]

impl TryFrom<UnixListener> for UnixListener[src]

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.