monoio/net/unix/
split.rs

1use std::io;
2
3use super::{SocketAddr, UnixStream};
4use crate::io::{
5    as_fd::{AsReadFd, AsWriteFd, SharedFdWrapper},
6    OwnedReadHalf, OwnedWriteHalf,
7};
8
9/// OwnedReadHalf.
10pub type UnixOwnedReadHalf = OwnedReadHalf<UnixStream>;
11
12/// OwnedWriteHalf.
13pub type UnixOwnedWriteHalf = OwnedWriteHalf<UnixStream>;
14
15impl UnixOwnedReadHalf {
16    /// Returns the remote address that this stream is connected to.
17    #[inline]
18    pub fn peer_addr(&self) -> io::Result<SocketAddr> {
19        let raw_stream = unsafe { &mut *self.0.get() };
20        raw_stream.peer_addr()
21    }
22
23    /// Returns the local address that this stream is bound to.
24    #[inline]
25    pub fn local_addr(&self) -> io::Result<SocketAddr> {
26        let raw_stream = unsafe { &mut *self.0.get() };
27        raw_stream.local_addr()
28    }
29}
30
31impl AsReadFd for UnixOwnedReadHalf {
32    #[inline]
33    fn as_reader_fd(&mut self) -> &SharedFdWrapper {
34        let raw_stream = unsafe { &mut *self.0.get() };
35        raw_stream.as_reader_fd()
36    }
37}
38
39impl AsWriteFd for UnixOwnedWriteHalf {
40    #[inline]
41    fn as_writer_fd(&mut self) -> &SharedFdWrapper {
42        let raw_stream = unsafe { &mut *self.0.get() };
43        raw_stream.as_writer_fd()
44    }
45}