fix: fixed build with duplicated io::Error use (#1934)

This commit is contained in:
zonyitoo
2025-04-09 21:50:48 +08:00
parent d8f91b806c
commit fe71d5f2dc
4 changed files with 14 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
use std::{
io, mem, io:ErrorKind,
io::{self, ErrorKind},
mem,
net::{Ipv4Addr, Ipv6Addr, SocketAddr},
os::unix::io::{AsRawFd, RawFd},
pin::Pin,
@@ -19,7 +20,7 @@ use tokio_tfo::TfoStream;
use crate::net::{
AcceptOpts, AddrFamily, ConnectOpts,
sys::{set_common_sockopt_after_connect, set_common_sockopt_for_connect, socket_bind_dual_stack, io::Error},
sys::{set_common_sockopt_after_connect, set_common_sockopt_for_connect, socket_bind_dual_stack},
udp::{BatchRecvMessage, BatchSendMessage},
};
@@ -232,14 +233,14 @@ pub async fn create_outbound_udp_socket(af: AddrFamily, config: &ConnectOpts) ->
// Map IPv6 bind_local_addr to IPv4 if AF is IPv4
match addr.ip().to_ipv4_mapped() {
Some(addr) => SocketAddr::new(addr.into(), 0),
None => return Err(Error::new(ErrorKind::InvalidInput, "Invalid IPv6 address")),
None => return Err(io::Error::new(ErrorKind::InvalidInput, "Invalid IPv6 address")),
}
},
}
(AddrFamily::Ipv6, Some(SocketAddr::V6(addr))) => addr.into(),
(AddrFamily::Ipv6, Some(SocketAddr::V4(addr))) => {
// Map IPv4 bind_local_addr to IPv6 if AF is IPv6
SocketAddr::new(addr.ip().to_ipv6_mapped().into(), 0)
},
}
(AddrFamily::Ipv4, ..) => SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), 0),
(AddrFamily::Ipv6, ..) => SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), 0),
};

View File

@@ -23,7 +23,7 @@ use tokio_tfo::TfoStream;
use crate::net::{
AcceptOpts, AddrFamily, ConnectOpts,
sys::{io::Error, set_common_sockopt_after_connect, set_common_sockopt_for_connect, socket_bind_dual_stack},
sys::{set_common_sockopt_after_connect, set_common_sockopt_for_connect, socket_bind_dual_stack},
udp::{BatchRecvMessage, BatchSendMessage},
};
@@ -360,7 +360,7 @@ pub async fn create_outbound_udp_socket(af: AddrFamily, config: &ConnectOpts) ->
// Map IPv6 bind_local_addr to IPv4 if AF is IPv4
match addr.ip().to_ipv4_mapped() {
Some(addr) => SocketAddr::new(addr.into(), 0),
None => return Err(Error::new(ErrorKind::InvalidInput, "Invalid IPv6 address")),
None => return Err(io::Error::new(ErrorKind::InvalidInput, "Invalid IPv6 address")),
}
}
(AddrFamily::Ipv6, Some(SocketAddr::V6(addr))) => addr.into(),

View File

@@ -1,6 +1,5 @@
use std::{
io,
io::ErrorKind,
io::{self, ErrorKind},
mem,
net::{Ipv4Addr, Ipv6Addr, SocketAddr},
os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd},
@@ -22,7 +21,7 @@ use tokio_tfo::TfoStream;
use crate::net::{
AcceptOpts, AddrFamily, ConnectOpts,
sys::{io::Error, set_common_sockopt_after_connect, set_common_sockopt_for_connect, socket_bind_dual_stack},
sys::{set_common_sockopt_after_connect, set_common_sockopt_for_connect, socket_bind_dual_stack},
udp::{BatchRecvMessage, BatchSendMessage},
};
@@ -293,7 +292,7 @@ pub async fn create_outbound_udp_socket(af: AddrFamily, config: &ConnectOpts) ->
// Map IPv6 bind_local_addr to IPv4 if AF is IPv4
match addr.ip().to_ipv4_mapped() {
Some(addr) => SocketAddr::new(addr.into(), 0),
None => return Err(Error::new(ErrorKind::InvalidInput, "Invalid IPv6 address")),
None => return Err(io::Error::new(ErrorKind::InvalidInput, "Invalid IPv6 address")),
}
}
(AddrFamily::Ipv6, Some(SocketAddr::V6(addr))) => addr.into(),

View File

@@ -1,6 +1,5 @@
use std::{
io,
io::ErrorKind,
io::{self, ErrorKind},
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
ops::{Deref, DerefMut},
os::fd::AsRawFd,
@@ -16,7 +15,7 @@ use tokio::{
use crate::net::{
AcceptOpts, AddrFamily, ConnectOpts,
sys::{ErrorKind, io::Error, set_common_sockopt_after_connect, set_common_sockopt_for_connect},
sys::{set_common_sockopt_after_connect, set_common_sockopt_for_connect},
};
/// A wrapper of `TcpStream`
@@ -87,7 +86,7 @@ pub async fn create_outbound_udp_socket(af: AddrFamily, config: &ConnectOpts) ->
// Map IPv6 bind_local_addr to IPv4 if AF is IPv4
match addr.ip().to_ipv4_mapped() {
Some(addr) => SocketAddr::new(IpAddr::from(addr), 0),
None => return Err(Error::new(ErrorKind::InvalidInput, "Invalid IPv6 address")),
None => return Err(io::Error::new(ErrorKind::InvalidInput, "Invalid IPv6 address")),
}
}
(AddrFamily::Ipv6, Some(SocketAddr::V6(addr))) => addr.into(),