diff options
| author | ihc童鞋@提不起劲 <[email protected]> | 2023-02-24 15:59:10 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-24 15:59:10 +0800 |
| commit | 50fda3b07db1f3c3de8a1fc85bb5334cd6373114 (patch) | |
| tree | 3152f2f6b43ead4b706a579d0d70a6d16bdba2f8 | |
| parent | 1c1ecbafbbda3d97acf38c4ac2bc69d8c1b2e365 (diff) | |
fix: not close OwnedWriteHalf on reunite (#145)
| -rw-r--r-- | monoio/src/io/util/split.rs | 6 | ||||
| -rw-r--r-- | monoio/src/net/udp.rs | 2 | ||||
| -rw-r--r-- | monoio/src/net/unix/stream.rs | 2 |
3 files changed, 7 insertions, 3 deletions
diff --git a/monoio/src/io/util/split.rs b/monoio/src/io/util/split.rs index 4865dae..747bc64 100644 --- a/monoio/src/io/util/split.rs +++ b/monoio/src/io/util/split.rs @@ -17,6 +17,7 @@ use crate::{ pub struct OwnedReadHalf<T>(pub Rc<UnsafeCell<T>>); /// Owned Write Half Part #[derive(Debug)] +#[repr(transparent)] pub struct OwnedWriteHalf<T>(pub Rc<UnsafeCell<T>>) where T: AsyncWriteRent; @@ -269,7 +270,10 @@ pub(crate) fn reunite<T: AsyncWriteRent>( write: OwnedWriteHalf<T>, ) -> Result<T, ReuniteError<T>> { if Rc::ptr_eq(&read.0, &write.0) { - drop(write); + // we cannot execute drop for OwnedWriteHalf. + unsafe { + let _inner: Rc<UnsafeCell<T>> = std::mem::transmute(write); + } // This unwrap cannot fail as the api does not allow creating more than two // Arcs, and we just dropped the other half. Ok(Rc::try_unwrap(read.0) diff --git a/monoio/src/net/udp.rs b/monoio/src/net/udp.rs index ea94139..d30f5eb 100644 --- a/monoio/src/net/udp.rs +++ b/monoio/src/net/udp.rs @@ -26,7 +26,7 @@ pub struct UdpSocket { fd: SharedFd, } -/// TcpStream is safe to split to two parts +/// UdpSocket is safe to split to two parts unsafe impl Split for UdpSocket {} impl UdpSocket { diff --git a/monoio/src/net/unix/stream.rs b/monoio/src/net/unix/stream.rs index 5fc7e40..978578f 100644 --- a/monoio/src/net/unix/stream.rs +++ b/monoio/src/net/unix/stream.rs @@ -26,7 +26,7 @@ pub struct UnixStream { fd: SharedFd, } -/// TcpStream is safe to split to two parts +/// UnixStream is safe to split to two parts unsafe impl Split for UnixStream {} impl UnixStream { |
