diff --git a/src/protocols/socks5/tcp_server.rs b/src/protocols/socks5/tcp_server.rs index 6722a2d..5a45729 100644 --- a/src/protocols/socks5/tcp_server.rs +++ b/src/protocols/socks5/tcp_server.rs @@ -229,8 +229,8 @@ impl AsyncRead for Socks5ReadHalf { buf: &mut ReadBuf<'_>, ) -> Poll> { match self.get_mut() { - Self::Tcp(s) => unsafe { Pin::new_unchecked(s) }.poll_read(cx, buf), - Self::Udp(s) => unsafe { Pin::new_unchecked(s) }.poll_read(cx, buf), + Self::Tcp(s) => Pin::new(s).poll_read(cx, buf), + Self::Udp(s) => Pin::new(s).poll_read(cx, buf), } } } @@ -238,22 +238,22 @@ impl AsyncRead for Socks5ReadHalf { impl AsyncWrite for Socks5WriteHalf { fn poll_write(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>, buf: &[u8]) -> Poll> { match self.get_mut() { - Self::Tcp(s) => unsafe { Pin::new_unchecked(s) }.poll_write(cx, buf), - Self::Udp(s) => unsafe { Pin::new_unchecked(s) }.poll_write(cx, buf), + Self::Tcp(s) => Pin::new(s).poll_write(cx, buf), + Self::Udp(s) => Pin::new(s).poll_write(cx, buf), } } fn poll_flush(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll> { match self.get_mut() { - Self::Tcp(s) => unsafe { Pin::new_unchecked(s) }.poll_flush(cx), - Self::Udp(s) => unsafe { Pin::new_unchecked(s) }.poll_flush(cx), + Self::Tcp(s) => Pin::new(s).poll_flush(cx), + Self::Udp(s) => Pin::new(s).poll_flush(cx), } } fn poll_shutdown(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll> { match self.get_mut() { - Self::Tcp(s) => unsafe { Pin::new_unchecked(s) }.poll_shutdown(cx), - Self::Udp(s) => unsafe { Pin::new_unchecked(s) }.poll_shutdown(cx), + Self::Tcp(s) => Pin::new(s).poll_shutdown(cx), + Self::Udp(s) => Pin::new(s).poll_shutdown(cx), } } @@ -263,8 +263,8 @@ impl AsyncWrite for Socks5WriteHalf { bufs: &[IoSlice<'_>], ) -> Poll> { match self.get_mut() { - Self::Tcp(s) => unsafe { Pin::new_unchecked(s) }.poll_write_vectored(cx, bufs), - Self::Udp(s) => unsafe { Pin::new_unchecked(s) }.poll_write_vectored(cx, bufs), + Self::Tcp(s) => Pin::new(s).poll_write_vectored(cx, bufs), + Self::Udp(s) => Pin::new(s).poll_write_vectored(cx, bufs), } } @@ -275,22 +275,3 @@ impl AsyncWrite for Socks5WriteHalf { } } } - -//#[cfg(test)] -//mod test { -// use super::*; -// use futures_util::StreamExt; -// use std::str::FromStr; -// -// #[tokio::test] -// async fn socks5_server() { -// let mut x = run_server(SocketAddr::from_str("[::]:4343").unwrap()) -// .await -// .unwrap(); -// -// loop { -// let cnx = x.next().await.unwrap().unwrap(); -// eprintln!("{:?}", cnx); -// } -// } -//} diff --git a/src/tunnel/listeners/socks5.rs b/src/tunnel/listeners/socks5.rs index 57ca1a2..f279241 100644 --- a/src/tunnel/listeners/socks5.rs +++ b/src/tunnel/listeners/socks5.rs @@ -32,7 +32,6 @@ impl Stream for Socks5TunnelListener { fn poll_next(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll> { let this = self.get_mut(); let ret = ready!(Pin::new(&mut this.listener).poll_next(cx)); - // TODO: Check if tokio::io::split can be avoided let ret = match ret { Some(Ok((stream, (host, port)))) => { let protocol = stream.local_protocol();