[][src]Struct uds::nonblocking::UnixSeqpacketConn

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

A non-blocking unix domain sequential-packet connection.

Differs from uds::UnixSeqpacketConn in that all operations that send or receive data will return an Error of kind ErrorKind::WouldBlock instead of blocking. This is done by creating the socket as non-blocking, and not by passing MSG_DONTWAIT. If creating this type from a raw file descriptor, ensure the fd is set to nonblocking before using it through this type.

This type can be used with mio if one of the mio features are enabled:

For mio version 0.6:

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

For mio version 0.7:

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

Examples

Sending or receiving when it would block a normal socket:

use uds::nonblocking::UnixSeqpacketConn;
use std::io::ErrorKind;

let (a, b) = UnixSeqpacketConn::pair().expect("create nonblocking seqpacket pair");

// trying to receive when there are no packets waiting
assert_eq!(a.recv(&mut[0]).unwrap_err().kind(), ErrorKind::WouldBlock);

// trying to send when the OS buffer for the connection is full
loop {
    if let Err(error) = a.send(&[0u8; 1000]) {
        assert_eq!(error.kind(), ErrorKind::WouldBlock);
        break;
    }
}

Registering with mio (v0.6):

use uds::nonblocking::UnixSeqpacketConn;
use mio::{Poll, Token, Ready, PollOpt, Events};
use std::io::ErrorKind;

let (a, b) = UnixSeqpacketConn::pair()
    .expect("create nonblocking seqpacket pair");

let poll = Poll::new().expect("create mio poll");
let mut events = Events::with_capacity(10);
poll.register(&a, Token(0), Ready::all(),  PollOpt::edge())
    .expect("register unix seqpacket connection with mio");

b.send(&[]).expect("send seqpacket");

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

Implementations

impl NonblockingUnixSeqpacketConn[src]

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

Connect to an unix seqpacket server listening at path.

This is a wrapper around connect_unix_addr() for convenience and compatibility with std.

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

Connect to an unix seqpacket server listening at addr.

pub fn connect_from_to_unix_addr(
    from: &UnixSocketAddr,
    to: &UnixSocketAddr
) -> Result<Self, Error>
[src]

Bind to an address before connecting to a listening seqpacket socket.

pub fn pair() -> Result<(Self, Self), Error>[src]

Create a pair of nonblocking unix-domain seqpacket conneections connected to each other.

Examples

let (a, b) = uds::nonblocking::UnixSeqpacketConn::pair().unwrap();
assert!(a.local_unix_addr().unwrap().is_unnamed());
assert!(b.local_unix_addr().unwrap().is_unnamed());
assert_eq!(b.recv(&mut[0; 20]).unwrap_err().kind(), std::io::ErrorKind::WouldBlock);
a.send(b"hello").unwrap();
assert_eq!(b.recv(&mut[0; 20]).unwrap(), (5, false));

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

Get the address of this side of the connection.

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

Get the address of the other side of the connection.

pub fn initial_peer_credentials(&self) -> Result<ConnCredentials, Error>[src]

Get information about the process of the peer when the connection was established.

See documentation of the returned type for details.

pub fn send(&self, packet: &[u8]) -> Result<usize, Error>[src]

Send a packet to the peer.

pub fn recv(&self, buffer: &mut [u8]) -> Result<(usize, bool), Error>[src]

Receive a packet from the peer.

The returned bool indicates whether the packet was truncated due to too short buffer.

pub fn send_vectored(&self, slices: &[IoSlice<'_>]) -> Result<usize, Error>[src]

Send a packet assembled from multiple byte slices.

pub fn recv_vectored(
    &self,
    buffers: &mut [IoSliceMut<'_>]
) -> Result<(usize, bool), Error>
[src]

Read a packet into multiple buffers.

The returned bool indicates whether the packet was truncated due to too short buffers.

pub fn send_fds(&self, bytes: &[u8], fds: &[RawFd]) -> Result<usize, Error>[src]

Send a packet with associated file descriptors.

pub fn recv_fds(
    &self,
    byte_buffer: &mut [u8],
    fd_buffer: &mut [RawFd]
) -> Result<(usize, bool, usize), Error>
[src]

Receive a packet and associated file descriptors.

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

Create a new file descriptor also pointing to this side of this connection.

Examples

let (a1, b) = UnixSeqpacketConn::pair().unwrap();
b.send(b"first come first serve").unwrap();
let a2 = a1.try_clone().unwrap();
a2.recv(&mut[0u8; 10]).unwrap();
assert_eq!(a1.recv(&mut[0u8; 10]).unwrap_err().kind(), ErrorKind::WouldBlock);

b.send(b"more").unwrap();
a1.recv(&mut[0u8; 10]).unwrap();
assert_eq!(a2.recv(&mut[0u8; 10]).unwrap_err().kind(), ErrorKind::WouldBlock);

pub fn shutdown(&self, how: Shutdown) -> Result<()>[src]

Shuts down the read, write, or both halves of this connection.

Trait Implementations

impl AsRawFd for NonblockingUnixSeqpacketConn[src]

impl Debug for NonblockingUnixSeqpacketConn[src]

impl Drop for NonblockingUnixSeqpacketConn[src]

impl Evented for NonblockingUnixSeqpacketConn[src]

impl FromRawFd for NonblockingUnixSeqpacketConn[src]

impl IntoRawFd for NonblockingUnixSeqpacketConn[src]

impl Source for NonblockingUnixSeqpacketConn[src]

impl<'a> Source for &'a NonblockingUnixSeqpacketConn[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.