pub struct UdStream(/* private fields */);
tokio_support
only.Expand description
A Unix domain socket byte stream, obtained either from UdStreamListener
or by connecting to an existing server.
§Examples
Implementations§
Source§impl UdStream
impl UdStream
Sourcepub async fn connect(path: impl ToUdSocketPath<'_>) -> Result<Self>
pub async fn connect(path: impl ToUdSocketPath<'_>) -> Result<Self>
Connects to a Unix domain socket server at the specified path.
See ToUdSocketPath
for an example of using various string types to specify socket paths.
Sourcepub fn split(&mut self) -> (BorrowedReadHalf<'_>, BorrowedWriteHalf<'_>)
pub fn split(&mut self) -> (BorrowedReadHalf<'_>, BorrowedWriteHalf<'_>)
Borrows a stream into a read half and a write half, which can be used to read and write the stream concurrently.
This method is more efficient than .into_split()
, but the halves cannot be moved into independently spawned tasks.
Sourcepub fn into_split(self) -> (OwnedReadHalf, OwnedWriteHalf)
pub fn into_split(self) -> (OwnedReadHalf, OwnedWriteHalf)
Splits a stream into a read half and a write half, which can be used to read and write the stream concurrently.
Unlike .split()
, the owned halves can be moved to separate tasks, which comes at the cost of a heap allocation.
Dropping either half will shut it down. This is equivalent to calling .shutdown()
on the stream with the corresponding argument.
Sourcepub fn reunite(
read: OwnedReadHalf,
write: OwnedWriteHalf,
) -> Result<Self, ReuniteError>
pub fn reunite( read: OwnedReadHalf, write: OwnedWriteHalf, ) -> Result<Self, ReuniteError>
Attempts to put two owned halves of a stream back together and recover the original stream. Succeeds only if the two halves originated from the same call to .into_split()
.
Sourcepub fn shutdown(&self, how: Shutdown) -> Result<()>
pub fn shutdown(&self, how: Shutdown) -> Result<()>
Shuts down the read, write, or both halves of the stream. See Shutdown
.
Attempting to call this method with the same how
argument multiple times may return Ok(())
every time or it may return an error the second time it is called, depending on the platform. You must either avoid using the same value twice or ignore the error entirely.
Sourcepub fn get_peer_credentials(&self) -> Result<ucred>
Available on Linux and (GNU or musl or target_env="musleabi"
or target_env="musleabihf"
), or Emscripten, or Redox, or Haiku only.
pub fn get_peer_credentials(&self) -> Result<ucred>
target_env="musleabi"
or target_env="musleabihf"
), or Emscripten, or Redox, or Haiku only.Fetches the credentials of the other end of the connection without using ancillary data. The returned structure contains the process identifier, user identifier and group identifier of the peer.
Sourcepub fn into_sync(self) -> Result<SyncUdStream>
pub fn into_sync(self) -> Result<SyncUdStream>
Detaches the async object from the Tokio runtime (therefore has to be called within the runtime) and converts it to a blocking one.
Sourcepub fn from_sync(sync: SyncUdStream) -> Result<Self>
pub fn from_sync(sync: SyncUdStream) -> Result<Self>
Creates a Tokio-based async object from a blocking one. This will also attach the object to the Tokio runtime this function is called in, so calling it outside a runtime will result in an error.
Sourcepub fn into_std(self) -> Result<StdUdStream>
pub fn into_std(self) -> Result<StdUdStream>
Detaches the async object from the Tokio runtime and converts it to a blocking one from the standard library. Returns an error if called outside a Tokio runtime context.
Sourcepub fn from_std(std: StdUdStream) -> Result<Self>
pub fn from_std(std: StdUdStream) -> Result<Self>
Creates a Tokio-based async object from a blocking one from the standard library. This will also attach the object to the Tokio runtime this function is called in, so calling it outside a runtime will result in an error.
Sourcepub fn into_tokio(self) -> TokioUdStream
pub fn into_tokio(self) -> TokioUdStream
Unwraps into Tokio’s corresponding type. This is a zero-cost operation.
Sourcepub fn from_tokio(tokio: TokioUdStream) -> Self
pub fn from_tokio(tokio: TokioUdStream) -> Self
Wraps Tokio’s corresponding type. This is a zero-cost operation.
Sourcepub unsafe fn from_raw_fd(fd: c_int) -> Result<Self>
pub unsafe fn from_raw_fd(fd: c_int) -> Result<Self>
Creates a Tokio-based async object from a given raw file descriptor. This will also attach the object to the Tokio runtime this function is called in, so calling it outside a runtime will result in an error (which is why the FromRawFd
trait can’t be implemented instead).
§Safety
The given file descriptor must be valid (i.e. refer to an existing kernel object) and must not be owned by any other file descriptor container. If this is not upheld, an arbitrary file descriptor will be closed when the returned object is dropped.
Sourcepub fn into_raw_fd(self) -> Result<c_int>
pub fn into_raw_fd(self) -> Result<c_int>
Releases ownership of the raw file descriptor, detaches the object from the Tokio runtime (therefore has to be called within the runtime) and returns the file descriptor as an integer.
Trait Implementations§
Source§impl AsyncRead for UdStream
impl AsyncRead for UdStream
Source§impl AsyncWrite for UdStream
impl AsyncWrite for UdStream
Source§fn poll_shutdown(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Error>>
fn poll_shutdown( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Error>>
Finishes immediately. See the .shutdown()
method.
Source§fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize, Error>>
fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize, Error>>
buf
into the object. Read moreSource§fn poll_flush(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Error>>
fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Error>>
Source§fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, Error>>
fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>
poll_write
, except that it writes from a slice of buffers. Read moreSource§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. Read moreSource§impl AsyncWrite for UdStream
impl AsyncWrite for UdStream
Source§fn poll_close(
self: Pin<&mut Self>,
_: &mut Context<'_>,
) -> Poll<Result<(), Error>>
fn poll_close( self: Pin<&mut Self>, _: &mut Context<'_>, ) -> Poll<Result<(), Error>>
Finishes immediately. See the .shutdown()
method.
Source§fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize, Error>>
fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize, Error>>
buf
into the object. Read moreSource§impl From<UdStream> for TokioUdStream
impl From<UdStream> for TokioUdStream
Source§impl From<UnixStream> for UdStream
impl From<UnixStream> for UdStream
Source§fn from(tokio: TokioUdStream) -> Self
fn from(tokio: TokioUdStream) -> Self
Source§impl TryFrom<UdStream> for StdUdStream
impl TryFrom<UdStream> for StdUdStream
Auto Trait Implementations§
impl !Freeze for UdStream
impl RefUnwindSafe for UdStream
impl Send for UdStream
impl Sync for UdStream
impl Unpin for UdStream
impl UnwindSafe for UdStream
Blanket Implementations§
Source§impl<R> AsyncReadExt for R
impl<R> AsyncReadExt for R
Source§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
Source§fn read_buf<'a, B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>
fn read_buf<'a, B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>
Source§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
buf
. Read moreSource§fn read_u8(&mut self) -> ReadU8<&mut Self>where
Self: Unpin,
fn read_u8(&mut self) -> ReadU8<&mut Self>where
Self: Unpin,
Source§fn read_i8(&mut self) -> ReadI8<&mut Self>where
Self: Unpin,
fn read_i8(&mut self) -> ReadI8<&mut Self>where
Self: Unpin,
Source§fn read_u16(&mut self) -> ReadU16<&mut Self>where
Self: Unpin,
fn read_u16(&mut self) -> ReadU16<&mut Self>where
Self: Unpin,
Source§fn read_i16(&mut self) -> ReadI16<&mut Self>where
Self: Unpin,
fn read_i16(&mut self) -> ReadI16<&mut Self>where
Self: Unpin,
Source§fn read_u32(&mut self) -> ReadU32<&mut Self>where
Self: Unpin,
fn read_u32(&mut self) -> ReadU32<&mut Self>where
Self: Unpin,
Source§fn read_i32(&mut self) -> ReadI32<&mut Self>where
Self: Unpin,
fn read_i32(&mut self) -> ReadI32<&mut Self>where
Self: Unpin,
Source§fn read_u64(&mut self) -> ReadU64<&mut Self>where
Self: Unpin,
fn read_u64(&mut self) -> ReadU64<&mut Self>where
Self: Unpin,
Source§fn read_i64(&mut self) -> ReadI64<&mut Self>where
Self: Unpin,
fn read_i64(&mut self) -> ReadI64<&mut Self>where
Self: Unpin,
Source§fn read_u128(&mut self) -> ReadU128<&mut Self>where
Self: Unpin,
fn read_u128(&mut self) -> ReadU128<&mut Self>where
Self: Unpin,
Source§fn read_i128(&mut self) -> ReadI128<&mut Self>where
Self: Unpin,
fn read_i128(&mut self) -> ReadI128<&mut Self>where
Self: Unpin,
Source§fn read_f32(&mut self) -> ReadF32<&mut Self>where
Self: Unpin,
fn read_f32(&mut self) -> ReadF32<&mut Self>where
Self: Unpin,
Source§fn read_f64(&mut self) -> ReadF64<&mut Self>where
Self: Unpin,
fn read_f64(&mut self) -> ReadF64<&mut Self>where
Self: Unpin,
Source§fn read_u16_le(&mut self) -> ReadU16Le<&mut Self>where
Self: Unpin,
fn read_u16_le(&mut self) -> ReadU16Le<&mut Self>where
Self: Unpin,
Source§fn read_i16_le(&mut self) -> ReadI16Le<&mut Self>where
Self: Unpin,
fn read_i16_le(&mut self) -> ReadI16Le<&mut Self>where
Self: Unpin,
Source§fn read_u32_le(&mut self) -> ReadU32Le<&mut Self>where
Self: Unpin,
fn read_u32_le(&mut self) -> ReadU32Le<&mut Self>where
Self: Unpin,
Source§fn read_i32_le(&mut self) -> ReadI32Le<&mut Self>where
Self: Unpin,
fn read_i32_le(&mut self) -> ReadI32Le<&mut Self>where
Self: Unpin,
Source§fn read_u64_le(&mut self) -> ReadU64Le<&mut Self>where
Self: Unpin,
fn read_u64_le(&mut self) -> ReadU64Le<&mut Self>where
Self: Unpin,
Source§fn read_i64_le(&mut self) -> ReadI64Le<&mut Self>where
Self: Unpin,
fn read_i64_le(&mut self) -> ReadI64Le<&mut Self>where
Self: Unpin,
Source§fn read_u128_le(&mut self) -> ReadU128Le<&mut Self>where
Self: Unpin,
fn read_u128_le(&mut self) -> ReadU128Le<&mut Self>where
Self: Unpin,
Source§fn read_i128_le(&mut self) -> ReadI128Le<&mut Self>where
Self: Unpin,
fn read_i128_le(&mut self) -> ReadI128Le<&mut Self>where
Self: Unpin,
Source§fn read_f32_le(&mut self) -> ReadF32Le<&mut Self>where
Self: Unpin,
fn read_f32_le(&mut self) -> ReadF32Le<&mut Self>where
Self: Unpin,
Source§fn read_f64_le(&mut self) -> ReadF64Le<&mut Self>where
Self: Unpin,
fn read_f64_le(&mut self) -> ReadF64Le<&mut Self>where
Self: Unpin,
Source§fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
buf
. Read more