Struct otter_nodejs_tests::uds::nonblocking::UnixSeqpacketConn
[−]#[repr(transparent)]pub struct UnixSeqpacketConn { /* private fields */ }
Expand description
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(1), Ready::all(), PollOpt::edge())
.expect("register unix seqpacket connection with mio");
b.send(b"this is it").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(1));
assert_eq!(a.recv(&mut [0; 8]).expect("receive packet"), (8, true/*truncated*/));
Implementations
impl NonblockingUnixSeqpacketConn
impl NonblockingUnixSeqpacketConn
pub fn connect<P>(path: P) -> Result<NonblockingUnixSeqpacketConn, Error> where
P: AsRef<Path>,
pub fn connect<P>(path: P) -> Result<NonblockingUnixSeqpacketConn, Error> where
P: AsRef<Path>,
Connects 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<NonblockingUnixSeqpacketConn, Error>
pub fn connect_unix_addr(
addr: &UnixSocketAddr
) -> Result<NonblockingUnixSeqpacketConn, Error>
Connects to an unix seqpacket server listening at addr
.
pub fn connect_from_to_unix_addr(
from: &UnixSocketAddr,
to: &UnixSocketAddr
) -> Result<NonblockingUnixSeqpacketConn, Error>
pub fn connect_from_to_unix_addr(
from: &UnixSocketAddr,
to: &UnixSocketAddr
) -> Result<NonblockingUnixSeqpacketConn, Error>
Binds to an address before connecting to a listening seqpacket socket.
pub fn pair(
) -> Result<(NonblockingUnixSeqpacketConn, NonblockingUnixSeqpacketConn), Error>
pub fn pair(
) -> Result<(NonblockingUnixSeqpacketConn, NonblockingUnixSeqpacketConn), Error>
Creates 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>
pub fn local_unix_addr(&self) -> Result<UnixSocketAddr, Error>
Returns the address of this side of the connection.
pub fn peer_unix_addr(&self) -> Result<UnixSocketAddr, Error>
pub fn peer_unix_addr(&self) -> Result<UnixSocketAddr, Error>
Returns the address of the other side of the connection.
pub fn initial_peer_credentials(&self) -> Result<ConnCredentials, Error>
pub fn initial_peer_credentials(&self) -> Result<ConnCredentials, Error>
Returns information about the process of the peer when the connection was established.
See documentation of the returned type for details.
pub fn initial_peer_selinux_context(
&self,
buf: &mut [u8]
) -> Result<usize, Error>
pub fn initial_peer_selinux_context(
&self,
buf: &mut [u8]
) -> Result<usize, Error>
Returns the SELinux security context of the process that created the other end of this connection.
Will return an error on other operating systems than Linux or Android,
and also if running inside kubernetes.
On success the number of bytes used is returned. (like Read
)
The default security context is unconfined
, without any trailing NUL.
A buffor of 50 bytes is probably always big enough.
pub fn recv(&self, buffer: &mut [u8]) -> Result<(usize, bool), Error>
pub fn recv(&self, buffer: &mut [u8]) -> Result<(usize, bool), Error>
Receives 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>
pub fn send_vectored(&self, slices: &[IoSlice<'_>]) -> Result<usize, Error>
Sends a packet assembled from multiple byte slices.
pub fn recv_vectored(
&self,
buffers: &mut [IoSliceMut<'_>]
) -> Result<(usize, bool), Error>
pub fn recv_vectored(
&self,
buffers: &mut [IoSliceMut<'_>]
) -> Result<(usize, bool), Error>
Reads 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: &[i32]) -> Result<usize, Error>
pub fn send_fds(&self, bytes: &[u8], fds: &[i32]) -> Result<usize, Error>
Sends a packet with associated file descriptors.
pub fn recv_fds(
&self,
byte_buffer: &mut [u8],
fd_buffer: &mut [i32]
) -> Result<(usize, bool, usize), Error>
pub fn recv_fds(
&self,
byte_buffer: &mut [u8],
fd_buffer: &mut [i32]
) -> Result<(usize, bool, usize), Error>
Receives a packet and associated file descriptors.
pub fn peek(&self, buffer: &mut [u8]) -> Result<(usize, bool), Error>
pub fn peek(&self, buffer: &mut [u8]) -> Result<(usize, bool), Error>
Receives a packet without removing it from the incoming queue.
The returned bool
indicates whether the packet was truncated due to
the buffer being too small.
Examples
let (a, b) = uds::nonblocking::UnixSeqpacketConn::pair().unwrap();
let mut buf = [0u8; 10];
assert_eq!(b.peek(&mut buf).unwrap_err().kind(), WouldBlock);
a.send(b"hello").unwrap();
assert_eq!(b.peek(&mut buf).unwrap(), (5, false));
assert_eq!(&buf[..5], b"hello");
assert_eq!(b.recv(&mut buf).unwrap(), (5, false));
assert_eq!(&buf[..5], b"hello");
assert_eq!(b.peek(&mut buf).unwrap_err().kind(), WouldBlock);
pub fn peek_vectored(
&self,
buffers: &mut [IoSliceMut<'_>]
) -> Result<(usize, bool), Error>
pub fn peek_vectored(
&self,
buffers: &mut [IoSliceMut<'_>]
) -> Result<(usize, bool), Error>
Receives a packet without removing it from the incoming queue.
The returned bool
indicates whether the packet was truncated due to
the combined buffers being too small.
pub fn take_error(&self) -> Result<Option<Error>, Error>
pub fn take_error(&self) -> Result<Option<Error>, Error>
Returns the value of the SO_ERROR
option.
This might only provide errors generated from nonblocking connect()
s,
which this library doesn’t support. It is therefore unlikely to be
useful, but is provided for parity with mio
s UnixStream
.
Examples
let (a, _b) = uds::nonblocking::UnixSeqpacketConn::pair().unwrap();
assert!(a.recv(&mut[0u8; 1024]).is_err());
assert!(a.take_error().unwrap().is_none());
pub fn try_clone(&self) -> Result<NonblockingUnixSeqpacketConn, Error>
pub fn try_clone(&self) -> Result<NonblockingUnixSeqpacketConn, Error>
Creates 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);
Trait Implementations
impl AsRawFd for NonblockingUnixSeqpacketConn
impl AsRawFd for NonblockingUnixSeqpacketConn
impl Debug for NonblockingUnixSeqpacketConn
impl Debug for NonblockingUnixSeqpacketConn
impl Drop for NonblockingUnixSeqpacketConn
impl Drop for NonblockingUnixSeqpacketConn
impl FromRawFd for NonblockingUnixSeqpacketConn
impl FromRawFd for NonblockingUnixSeqpacketConn
unsafe fn from_raw_fd(fd: i32) -> NonblockingUnixSeqpacketConn
unsafe fn from_raw_fd(fd: i32) -> NonblockingUnixSeqpacketConn
Constructs a new instance of Self
from the given raw file
descriptor. Read more
impl IntoRawFd for NonblockingUnixSeqpacketConn
impl IntoRawFd for NonblockingUnixSeqpacketConn
fn into_raw_fd(self) -> i32
fn into_raw_fd(self) -> i32
Consumes this object, returning the raw underlying file descriptor. Read more
Auto Trait Implementations
impl RefUnwindSafe for NonblockingUnixSeqpacketConn
impl Send for NonblockingUnixSeqpacketConn
impl Sync for NonblockingUnixSeqpacketConn
impl Unpin for NonblockingUnixSeqpacketConn
impl UnwindSafe for NonblockingUnixSeqpacketConn
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
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<W, Global>impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<W, Global>impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
impl<A> DynCastExt for A
impl<A> DynCastExt for A
fn dyn_cast<T>(
self
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source> where
A: DynCastExtHelper<T>,
T: ?Sized,
fn dyn_cast<T>(
self
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source> where
A: DynCastExtHelper<T>,
T: ?Sized,
Use this to cast from one trait object type to another. Read more
fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target where
A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>,
T: ?Sized,
fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target where
A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>,
T: ?Sized,
Use this to upcast a trait to one of its supertraits. Read more
fn dyn_cast_adv<F, T>(
self
) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source> where
A: DynCastExtAdvHelper<F, T>,
F: ?Sized,
T: ?Sized,
fn dyn_cast_adv<F, T>(
self
) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source> where
A: DynCastExtAdvHelper<F, T>,
F: ?Sized,
T: ?Sized,
fn dyn_cast_with_config<C>(
self
) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source> where
C: DynCastConfig,
A: DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>,
fn dyn_cast_with_config<C>(
self
) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source> where
C: DynCastConfig,
A: DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>,
Use this to cast from one trait object type to another. With this method the type parameter is a config type that uniquely specifies which cast should be preformed. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourcefn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
T: Future, type Output = <T as Future>::Output;
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more