diff --git a/ylong_http/Cargo.toml b/ylong_http/Cargo.toml index d6cb5dffb3fbd2ef9e51ea5e5ab9716179742a55..4b69f981795c8a975363bb53c075b13eeb466519 100644 --- a/ylong_http/Cargo.toml +++ b/ylong_http/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["ylong", "http"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = ["http1_1", "tokio_base"] +default = [] full = [ "http1_1", "http2", @@ -23,11 +23,11 @@ http3 = [] # Uses HTTP/3. huffman = [] # Uses Huffman encoding in `Hpack` and `Qpack`. tokio_base = ["tokio"] # Uses asynchronous components of `tokio` -ylong_base = [] # Uses asynchronous components of `ylong` +ylong_base = ["ylong_runtime"] # Uses asynchronous components of `ylong` [dependencies] tokio = { version = "1.20.1", features = ["io-util"], optional = true } -# ylong_runtime = { path = "../runtime/ylong_runtime", optional = true } +ylong_runtime = { git = "https://gitee.com/openharmony-sig/commonlibrary_rust_ylong_runtime.git", optional = true } [dev-dependencies] tokio = { version = "1.20.1", features = ["io-util", "rt-multi-thread", "macros"] } diff --git a/ylong_http_client/Cargo.toml b/ylong_http_client/Cargo.toml index e70bd740d510207b5df4c2acc0557964b21b4d61..e507b3d9725de0657a73364dcbb1288070824a05 100644 --- a/ylong_http_client/Cargo.toml +++ b/ylong_http_client/Cargo.toml @@ -13,7 +13,7 @@ keywords = ["ylong", "http", "client"] ylong_http = { path = "../ylong_http", features = ["full"] } libc = { version = "0.2.134", optional = true } tokio = { version = "1.20.1", features = ["io-util", "net", "rt", "rt-multi-thread", "macros", "sync", "time"], optional = true } -# ylong_runtime = { path = "../runtime/ylong_runtime", features = ["net", "sync", "fs", "macros", "time"], optional = true } +ylong_runtime = { git = "https://gitee.com/openharmony-sig/commonlibrary_rust_ylong_runtime.git", features = ["net", "sync", "fs", "macros", "time"], optional = true } [dev-dependencies] hyper = { version = "0.14.23", features = ["http1", "tcp", "server"] } @@ -36,8 +36,8 @@ http1_1 = ["ylong_http/http1_1"] # Uses HTTP/1.1. http2 = ["ylong_http/http2"] # Uses HTTP/2. http3 = [] # Uses HTTP/3. -tokio_base = ["tokio"] # Uses tokio runtime. -ylong_base = [] # Uses ylong runtime. +tokio_base = ["tokio", "ylong_http/tokio_base"] # Uses tokio runtime. +ylong_base = ["ylong_runtime", "ylong_http/ylong_base"] # Uses ylong runtime. tls_default = ["c_openssl_3_0"] __tls = [] # Not open to user, only mark to use tls for developer. @@ -118,7 +118,7 @@ required-features = ["sync", "http1_1", "__tls", "tokio_base"] [[test]] name = "sdv_async_http_on_tcp" path = "./tests/sdv_async_http_on_tcp.rs" -required-features = ["async", "http1_1", "tokio_base"] +required-features = ["async", "http1_1", "ylong_base"] [[test]] name = "sdv_sync_http_on_tcp" diff --git a/ylong_http_client/src/lib.rs b/ylong_http_client/src/lib.rs index 7a215779716dc841e7388c7bd4217f3ba52f543b..1cad613724b87eef9aa0b5498bd3076577bcb57c 100644 --- a/ylong_http_client/src/lib.rs +++ b/ylong_http_client/src/lib.rs @@ -76,7 +76,7 @@ pub(crate) use ylong_runtime::sync::{ mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender}, Mutex as AsyncMutex, MutexGuard, RecvError as TryRecvError, }; -#[cfg(feature = "ylong_base")] +#[cfg(all(feature = "ylong_base", feature = "async"))] pub(crate) use ylong_runtime::{ io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf}, net::TcpStream, diff --git a/ylong_http_client/tests/sdv_async_http_on_tcp.rs b/ylong_http_client/tests/sdv_async_http_on_tcp.rs index 50cfde0567412d2015904bc40dcfde7f6982f3c8..96ba103a5b8cb7999feb53662b65ea364782d8e4 100644 --- a/ylong_http_client/tests/sdv_async_http_on_tcp.rs +++ b/ylong_http_client/tests/sdv_async_http_on_tcp.rs @@ -16,19 +16,10 @@ #[macro_use] pub mod tcp_server; -use tokio::runtime::Runtime; use ylong_http::body::async_impl::Body; use crate::tcp_server::{format_header_str, TcpHandle}; -fn init_test_work_runtime(thread_num: usize) -> Runtime { - tokio::runtime::Builder::new_multi_thread() - .worker_threads(thread_num) - .enable_all() - .build() - .expect("Build runtime failed.") -} - /// SDV test cases for `async::Client`. /// /// # Brief @@ -45,7 +36,6 @@ fn sdv_async_client_send_request() { // `GET` request async_client_test_on_tcp!( HTTP; - RuntimeThreads: 2, Request: { Method: "GET", Path: "/data", @@ -63,7 +53,6 @@ fn sdv_async_client_send_request() { // `HEAD` request. async_client_test_on_tcp!( HTTP; - RuntimeThreads: 2, Request: { Method: "HEAD", Path: "/data", @@ -80,7 +69,6 @@ fn sdv_async_client_send_request() { // `Post` Request. async_client_test_on_tcp!( HTTP; - RuntimeThreads: 2, Request: { Method: "POST", Path: "/data", @@ -98,7 +86,6 @@ fn sdv_async_client_send_request() { // `HEAD` request without body. async_client_test_on_tcp!( HTTP; - RuntimeThreads: 2, Request: { Method: "HEAD", Path: "/data", @@ -114,7 +101,6 @@ fn sdv_async_client_send_request() { // `PUT` request. async_client_test_on_tcp!( HTTP; - RuntimeThreads: 2, Request: { Method: "PUT", Path: "/data", @@ -142,7 +128,6 @@ fn sdv_async_client_send_request() { fn sdv_client_send_request_repeatedly() { async_client_test_on_tcp!( HTTP; - RuntimeThreads: 2, Request: { Method: "GET", Path: "/data", @@ -182,7 +167,6 @@ fn sdv_client_send_request_repeatedly() { fn sdv_client_making_multiple_connections() { async_client_test_on_tcp!( HTTP; - RuntimeThreads: 10, ClientNum: 5, Request: { Method: "GET", diff --git a/ylong_http_client/tests/tcp_server/async_utils.rs b/ylong_http_client/tests/tcp_server/async_utils.rs index 8734ddaf431248f4fd5e159546af1a5165075846..19cc540daebfdaf4a7e77b9d661189747fc8af92 100644 --- a/ylong_http_client/tests/tcp_server/async_utils.rs +++ b/ylong_http_client/tests/tcp_server/async_utils.rs @@ -15,7 +15,6 @@ macro_rules! async_client_test_on_tcp { ( HTTP; - RuntimeThreads: $thread_num: expr, $(ClientNum: $client_num: expr,)? $(Request: { Method: $method: expr, @@ -35,7 +34,6 @@ macro_rules! async_client_test_on_tcp { },)* ) => {{ - let runtime = init_test_work_runtime($thread_num); // The number of servers may be variable based on the number of servers set by the user. // However, cliipy checks that the variable does not need to be variable. #[allow(unused_mut, unused_assignments)] @@ -46,7 +44,6 @@ macro_rules! async_client_test_on_tcp { start_tcp_server!( ASYNC; ServerNum: server_num, - Runtime: runtime, Handles: handles_vec, $(Request: { Method: $method, @@ -69,7 +66,6 @@ macro_rules! async_client_test_on_tcp { let mut shut_downs = vec![]; async_client_assert_on_tcp!( HTTP; - Runtime: runtime, ServerNum: server_num, Handles: handles_vec, ShutDownHandles: shut_downs, @@ -92,7 +88,7 @@ macro_rules! async_client_test_on_tcp { ); for shutdown_handle in shut_downs { - runtime.block_on(shutdown_handle).expect("Runtime wait for server shutdown failed"); + ylong_runtime::block_on(shutdown_handle).expect("Runtime wait for server shutdown failed"); } }}; @@ -102,7 +98,6 @@ macro_rules! async_client_test_on_tcp { macro_rules! async_client_assert_on_tcp { ( HTTP; - Runtime: $runtime: expr, ServerNum: $server_num: expr, Handles: $handle_vec: expr, ShutDownHandles: $shut_downs: expr, @@ -128,7 +123,7 @@ macro_rules! async_client_assert_on_tcp { for _i in 0..$server_num { let handle = $handle_vec.pop().expect("No more handles !"); let client = std::sync::Arc::clone(&client); - let shutdown_handle = $runtime.spawn(async move { + let shutdown_handle = ylong_runtime::spawn(async move { async_client_assertions_on_tcp!( ServerHandle: handle, ClientRef: client, diff --git a/ylong_http_client/tests/tcp_server/mod.rs b/ylong_http_client/tests/tcp_server/mod.rs index 931ced330011d77d52e44ed88d73c7327eb8dc6a..3546dd746b3a9ec46b4039f3886b9fdc3e7d64f0 100644 --- a/ylong_http_client/tests/tcp_server/mod.rs +++ b/ylong_http_client/tests/tcp_server/mod.rs @@ -35,7 +35,6 @@ macro_rules! start_tcp_server { ( ASYNC; ServerNum: $server_num: expr, - Runtime: $runtime: expr, Handles: $handle_vec: expr, $(Request: { Method: $method: expr, @@ -56,14 +55,14 @@ macro_rules! start_tcp_server { ) => {{ use std::sync::mpsc::channel; - use tokio::net::TcpListener; - use tokio::io::{AsyncReadExt, AsyncWriteExt}; + use ylong_runtime::net::TcpListener; + use ylong_runtime::io::{AsyncReadExt, AsyncWriteExt}; for _i in 0..$server_num { let (rx, tx) = channel(); let (rx2, tx2) = channel(); - $runtime.spawn(async move { + ylong_runtime::spawn(async move { let server = TcpListener::bind("127.0.0.1:0").await.expect("server is failed to bind a address !"); let addr = server.local_addr().expect("failed to get server address !");