From ad074796d3c92125125ee64b6aaef0e5cc4ad978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=9C=AA=E6=9D=A5?= Date: Fri, 18 Apr 2025 11:33:40 +0800 Subject: [PATCH] =?UTF-8?q?rom=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 徐未来 --- ylong_http_client/src/lib.rs | 12 ++++++++++++ ylong_http_client/src/util/dispatcher.rs | 10 +++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ylong_http_client/src/lib.rs b/ylong_http_client/src/lib.rs index f1431e4..a4e2952 100644 --- a/ylong_http_client/src/lib.rs +++ b/ylong_http_client/src/lib.rs @@ -115,4 +115,16 @@ pub(crate) mod runtime { #[cfg(all(feature = "ylong_base", feature = "http2"))] pub(crate) use crate::{split, Reader as ReadHalf, Writer as WriteHalf}; + + #[cfg(any(feature = "http2", feature = "http3"))] + use std::future::Future; + + #[cfg(any(feature = "http2", feature = "http3"))] + pub(crate) fn runtime_spawn(fut: T) -> JoinHandle<()> + where + T: Future, + T: Send + Sync + 'static, + { + crate::runtime::spawn(Box::into_pin(Box::new(fut) as Box + Send + Sync>)) + } } diff --git a/ylong_http_client/src/util/dispatcher.rs b/ylong_http_client/src/util/dispatcher.rs index 4e8f5dc..611b526 100644 --- a/ylong_http_client/src/util/dispatcher.rs +++ b/ylong_http_client/src/util/dispatcher.rs @@ -503,7 +503,7 @@ pub(crate) mod http2 { let (read, write) = crate::runtime::split(io); let settings_sync = Arc::new(Mutex::new(SettingsSync::default())); let send_settings_sync = settings_sync.clone(); - let send = crate::runtime::spawn(async move { + let send = crate::runtime::runtime_spawn(async move { let mut writer = write; if async_send_preface(&mut writer).await.is_ok() { let encoder = FrameEncoder::new(DEFAULT_MAX_FRAME_SIZE, use_huffman); @@ -515,14 +515,14 @@ pub(crate) mod http2 { handles.push(send); let recv_settings_sync = settings_sync.clone(); - let recv = crate::runtime::spawn(async move { + let recv = crate::runtime::runtime_spawn(async move { let decoder = FrameDecoder::new(); let mut recv = RecvData::new(decoder, recv_settings_sync, read, resp_tx); let _ = Pin::new(&mut recv).await; }); handles.push(recv); - let manager = crate::runtime::spawn(async move { + let manager = crate::runtime::runtime_spawn(async move { let mut conn_manager = ConnManager::new(settings_sync, input_channel.0, resp_rx, req_rx, controller); let _ = Pin::new(&mut conn_manager).await; @@ -938,7 +938,7 @@ pub(crate) mod http3 { io_shutdown.clone(), io_goaway.clone(), ); - let stream_handle = crate::runtime::spawn(async move { + let stream_handle = crate::runtime::runtime_spawn(async move { if stream_manager.init(config).is_err() { return; } @@ -946,7 +946,7 @@ pub(crate) mod http3 { }); handles.push(stream_handle); - let io_handle = crate::runtime::spawn(async move { + let io_handle = crate::runtime::runtime_spawn(async move { let mut io_manager = IOManager::new(io, conn, io_manager_rx, stream_manager_tx); let _ = Pin::new(&mut io_manager).await; }); -- Gitee