Struct uds::nonblocking::UnixSeqpacketListener[][src]

#[repr(transparent)]pub struct UnixSeqpacketListener { /* fields omitted */ }

A non-blocking unix domain listener for sequential-packet connections.

Differs from UnixSeqpacketListener in that accept() returns non-blocking connection sockets and doesn’t block if no client connect()ions are pending.

This type can be used with mio if the mio feature is enabled:

uds = { version = "x.y", features=["mio"] }

Examples

use uds::nonblocking::{UnixSeqpacketListener, UnixSeqpacketConn};
use std::io::ErrorKind;

let listener = UnixSeqpacketListener::bind("nonblocking_seqpacket_listener.socket")
    .expect("Cannot create nonblocking seqpacket listener");

// doesn't block if no connections are waiting:
assert_eq!(listener.accept_unix_addr().unwrap_err().kind(), ErrorKind::WouldBlock);

// returned connections are nonblocking:
let _client = UnixSeqpacketConn::connect("nonblocking_seqpacket_listener.socket").unwrap();
let (conn, _addr) = listener.accept_unix_addr().unwrap();
assert_eq!(conn.recv(&mut[0u8; 20]).unwrap_err().kind(), ErrorKind::WouldBlock);

Registering with mio (v0.7):

use uds::nonblocking::{UnixSeqpacketListener, UnixSeqpacketConn};
use mio_07::{Poll, Events, Token, Interest};
use std::io::ErrorKind;

let listener = UnixSeqpacketListener::bind("seqpacket.sock")
    .expect("create nonblocking seqpacket listener");

let mut poll = Poll::new().expect("create mio poll");
let mut events = Events::with_capacity(10);
poll.registry()
    .register(&mut &listener, Token(0), Interest::READABLE)
    .expect("register unix seqpacket listener with mio");

let _conn = UnixSeqpacketConn::connect("seqpacket.sock")
    .expect("create nonblocking seqpacket socket and connect to listener");

poll.poll(&mut events, None).expect("receive mio notifications");
let current_events = events.iter().collect::<Vec<_>>();
assert!(current_events.len() > 0);
assert_eq!(current_events[0].token(), Token(0));
let (_, _addr) = listener.accept_unix_addr().expect("accept connection");

Implementations

impl NonblockingUnixSeqpacketListener[src]

pub fn bind<P: AsRef<Path>>(path: P) -> Result<Self, Error>[src]

Creates a socket that listens for seqpacket connections on the specified socket file.

pub fn bind_unix_addr(addr: &UnixSocketAddr) -> Result<Self, Error>[src]

Creates a socket that listens for seqpacket connections on the specified address.

pub fn local_unix_addr(&self) -> Result<UnixSocketAddr, Error>[src]

Returns the address this listener was bound to.

pub fn accept_unix_addr(
    &self
) -> Result<(NonblockingUnixSeqpacketConn, UnixSocketAddr), Error>
[src]

Accepts a non-blocking connection, non-blockingly.

Examples

Doesn’t block if no connections are waiting:

let _ = std::fs::remove_file("nonblocking_seqpacket_listener.socket");
let listener = UnixSeqpacketListener::bind("nonblocking_seqpacket_listener.socket")
    .expect("Cannot create nonblocking seqpacket listener");
assert_eq!(listener.accept_unix_addr().unwrap_err().kind(), ErrorKind::WouldBlock);
std::fs::remove_file("nonblocking_seqpacket_listener.socket").unwrap();

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

Returns the value of the SO_ERROR option.

This might never produce any errors for listeners. It is therefore unlikely to be useful, but is provided for parity with mios UnixListener.

Examples

let listener = uds::nonblocking::UnixSeqpacketListener::bind_unix_addr(
    &uds::UnixSocketAddr::new("@nonblocking_take_error").unwrap()
).unwrap();

assert!(listener.accept_unix_addr().is_err());
assert!(listener.take_error().unwrap().is_none());

pub fn try_clone(&self) -> Result<Self, Error>[src]

Creates a new file descriptor listening for the same connections.

Trait Implementations

impl AsRawFd for NonblockingUnixSeqpacketListener[src]

impl Debug for NonblockingUnixSeqpacketListener[src]

impl Drop for NonblockingUnixSeqpacketListener[src]

impl Evented for NonblockingUnixSeqpacketListener[src]

impl FromRawFd for NonblockingUnixSeqpacketListener[src]

impl IntoRawFd for NonblockingUnixSeqpacketListener[src]

impl Source for NonblockingUnixSeqpacketListener[src]

impl<'a> Source for &'a NonblockingUnixSeqpacketListener[src]

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, 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.