diff --git a/crates/shadowsocks/src/relay/udprelay/proxy_socket.rs b/crates/shadowsocks/src/relay/udprelay/proxy_socket.rs index 2e69b647ba28..5c1563ed7df7 100644 --- a/crates/shadowsocks/src/relay/udprelay/proxy_socket.rs +++ b/crates/shadowsocks/src/relay/udprelay/proxy_socket.rs @@ -1,5 +1,9 @@ //! UDP socket for communicating with shadowsocks' proxy server +#[cfg(unix)] +use std::os::fd::{AsFd, AsRawFd, BorrowedFd, IntoRawFd, RawFd}; +#[cfg(windows)] +use std::os::windows::io::{AsRawSocket, AsSocket, BorrowedSocket, IntoRawSocket, RawSocket}; use std::{ io::{self, ErrorKind}, net::SocketAddr, @@ -30,9 +34,6 @@ use super::{ }, }; -#[cfg(unix)] -use std::os::fd::{AsRawFd, RawFd}; - static DEFAULT_CONNECT_OPTS: Lazy = Lazy::new(Default::default); static DEFAULT_SOCKET_CONTROL: Lazy = Lazy::new(UdpSocketControlData::default); @@ -626,3 +627,53 @@ where self.io.as_raw_fd() } } + +#[cfg(unix)] +impl AsFd for ProxySocket +where + S: AsFd, +{ + fn as_fd(&self) -> BorrowedFd<'_> { + self.io.as_fd() + } +} + +#[cfg(unix)] +impl IntoRawFd for ProxySocket +where + S: IntoRawFd, +{ + fn into_raw_fd(self) -> RawFd { + self.io.into_raw_fd() + } +} + +#[cfg(windows)] +impl AsRawSocket for ProxySocket +where + S: AsRawSocket, +{ + fn as_raw_socket(&self) -> RawSocket { + self.io.as_raw_socket() + } +} + +#[cfg(windows)] +impl AsSocket for ProxySocket +where + S: AsSocket, +{ + fn as_socket(&self) -> BorrowedSocket<'_> { + self.io.as_socket() + } +} + +#[cfg(windows)] +impl IntoRawSocket for ProxySocket +where + S: IntoRawSocket, +{ + fn into_raw_socket(self) -> RawSocket { + self.io.into_raw_socket() + } +}