mirror of
https://github.com/rustdesk/hbb_common.git
synced 2025-07-01 23:47:24 +00:00
[enhance] remove cfg select.
This commit is contained in:
parent
58103659e7
commit
2d65c24e4b
@ -114,25 +114,41 @@ pub async fn connect_tcp_local<
|
|||||||
local: Option<SocketAddr>,
|
local: Option<SocketAddr>,
|
||||||
ms_timeout: u64,
|
ms_timeout: u64,
|
||||||
) -> ResultType<Stream> {
|
) -> ResultType<Stream> {
|
||||||
#[cfg(feature = "websocket")]
|
let target_str = target.to_string();
|
||||||
{
|
|
||||||
let url = format!("ws://{}", target);
|
// 根据目标地址协议决定连接方式
|
||||||
Ok(Stream::WebSocket(websocket::WsFramedStream::new(url, local, None, ms_timeout).await?))
|
if target_str.starts_with("ws://") || target_str.starts_with("wss://") {
|
||||||
}
|
// WebSocket 连接逻辑
|
||||||
#[cfg(not(feature = "websocket"))]
|
Ok(Stream::WebSocket(websocket::WsFramedStream::new(
|
||||||
{
|
target_str,
|
||||||
|
local,
|
||||||
|
None,
|
||||||
|
ms_timeout,
|
||||||
|
)
|
||||||
|
.await?))
|
||||||
|
} else {
|
||||||
|
// TCP 连接逻辑
|
||||||
if let Some(conf) = Config::get_socks() {
|
if let Some(conf) = Config::get_socks() {
|
||||||
return tcp::FramedStream::connect(target, local, &conf, ms_timeout).await;
|
return Ok(Stream::Tcp(
|
||||||
|
FramedStream::connect(target, local, &conf, ms_timeout).await?,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
if let Some(target) = target.resolve() {
|
|
||||||
if let Some(local) = local {
|
if let Some(target_addr) = target.resolve() {
|
||||||
if local.is_ipv6() && target.is_ipv4() {
|
if let Some(local_addr) = local {
|
||||||
let target = query_nip_io(target).await?;
|
if local_addr.is_ipv6() && target_addr.is_ipv4() {
|
||||||
return tcp::FramedStream::new(target, Some(local), ms_timeout).await;
|
let resolved_target = query_nip_io(target_addr).await?;
|
||||||
|
return Ok(Stream::Tcp(
|
||||||
|
FramedStream::new(resolved_target, Some(local_addr), ms_timeout)
|
||||||
|
.await?,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tcp::FramedStream::new(target, local, ms_timeout).await
|
|
||||||
|
Ok(Stream::Tcp(
|
||||||
|
FramedStream::new(target, local, ms_timeout).await?,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user