diff --git a/tentacle/Cargo.toml b/tentacle/Cargo.toml index 4a41769f..9b52b840 100644 --- a/tentacle/Cargo.toml +++ b/tentacle/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tentacle" -version = "0.6.0" +version = "0.6.1" license = "MIT" description = "Minimal implementation for a multiplexed p2p network framework." authors = ["piaoliu ", "Nervos Core Dev "] diff --git a/tentacle/src/service/config.rs b/tentacle/src/service/config.rs index ef482478..8897d8cb 100644 --- a/tentacle/src/service/config.rs +++ b/tentacle/src/service/config.rs @@ -4,10 +4,15 @@ use crate::{ yamux::config::Config as YamuxConfig, ProtocolId, SessionId, }; -#[cfg(unix)] -use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; #[cfg(windows)] -use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket}; +use std::os::windows::io::{ + AsRawSocket, AsSocket, BorrowedSocket, FromRawSocket, IntoRawSocket, RawSocket, +}; +#[cfg(unix)] +use std::os::{ + fd::AsFd, + unix::io::{AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}, +}; use std::{sync::Arc, time::Duration}; #[cfg(feature = "tls")] use tokio_rustls::rustls::{ClientConfig, ServerConfig}; @@ -144,6 +149,13 @@ impl IntoRawFd for TcpSocket { } } +#[cfg(unix)] +impl AsFd for TcpSocket { + fn as_fd(&self) -> BorrowedFd<'_> { + self.inner.as_fd() + } +} + #[cfg(windows)] impl IntoRawSocket for TcpSocket { fn into_raw_socket(self) -> RawSocket { @@ -167,6 +179,13 @@ impl FromRawSocket for TcpSocket { } } +#[cfg(windows)] +impl AsSocket for TcpSocket { + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + /// tls config wrap for server setup #[derive(Clone, Default)] #[cfg(feature = "tls")]