interprocess_docfix/local_socket/tokio/stream/
read_half.rs

1use {
2    futures_io::AsyncRead,
3    std::{
4        fmt::{self, Debug, Formatter},
5        io::{self, IoSliceMut},
6        pin::Pin,
7        task::{Context, Poll},
8    },
9};
10
11#[cfg(feature = "tokio_support")]
12impmod! {local_socket::tokio,
13    OwnedReadHalf as OwnedReadHalfImpl
14}
15#[cfg(not(feature = "tokio_support"))]
16struct OwnedReadHalfImpl;
17
18/// An owned read half of a Tokio-based local socket stream, obtained by splitting a [`LocalSocketStream`].
19///
20/// # Examples
21/// - [Basic client](https://github.com/kotauskas/interprocess/blob/main/examples/tokio_local_socket/client.rs)
22///
23/// [`LocalSocketStream`]: struct.LocalSocketStream.html " "
24pub struct OwnedReadHalf {
25    pub(super) inner: OwnedReadHalfImpl,
26}
27impl OwnedReadHalf {
28    /// Retrieves the identifier of the process on the opposite end of the local socket connection.
29    ///
30    /// # Platform-specific behavior
31    /// ## macOS and iOS
32    /// Not supported by the OS, will always generate an error at runtime.
33    pub fn peer_pid(&self) -> io::Result<u32> {
34        self.inner.peer_pid()
35    }
36    fn pinproj(&mut self) -> Pin<&mut OwnedReadHalfImpl> {
37        Pin::new(&mut self.inner)
38    }
39}
40
41impl AsyncRead for OwnedReadHalf {
42    fn poll_read(
43        mut self: Pin<&mut Self>,
44        cx: &mut Context<'_>,
45        buf: &mut [u8],
46    ) -> Poll<io::Result<usize>> {
47        self.pinproj().poll_read(cx, buf)
48    }
49    fn poll_read_vectored(
50        mut self: Pin<&mut Self>,
51        cx: &mut Context<'_>,
52        bufs: &mut [IoSliceMut<'_>],
53    ) -> Poll<io::Result<usize>> {
54        self.pinproj().poll_read_vectored(cx, bufs)
55    }
56}
57
58impl Debug for OwnedReadHalf {
59    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
60        Debug::fmt(&self.inner, f)
61    }
62}
63
64// TODO can't do this on Unix
65//impl_as_raw_handle!(OwnedReadHalf);