From a978eee08c89131e93e066731db449a401d8c87e Mon Sep 17 00:00:00 2001 From: kostasgr100 <97601678+kostasgr100@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:09:54 +0200 Subject: [PATCH] Update http.rs --- examples/http.rs | 95 ++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/examples/http.rs b/examples/http.rs index 109b7de..eb2afb7 100644 --- a/examples/http.rs +++ b/examples/http.rs @@ -13,56 +13,57 @@ struct SharedData { pub data: String, } -#[tokio::main] -async fn main() { - let opts = UsSocketContextOptions { - key_file_name: None, - cert_file_name: None, - passphrase: None, - dh_params_file_name: None, - ca_file_name: None, - ssl_ciphers: None, - ssl_prefer_low_memory_usage: None, - }; +fn main() { + tokio_uring::start(async { + let opts = UsSocketContextOptions { + key_file_name: None, + cert_file_name: None, + passphrase: None, + dh_params_file_name: None, + ca_file_name: None, + ssl_ciphers: None, + ssl_prefer_low_memory_usage: None, + }; + + let shared_data = SharedData { + data: "String containing data".to_string(), + }; - let shared_data = SharedData { - data: "String containing data".to_string(), - }; + let (sink, stream) = oneshot::channel::<()>(); + let (b_sink, mut b_stream) = broadcast::channel::<()>(1); + tokio_uring::spawn(async move { + let _ = b_stream.recv().await; + sink.send(()).unwrap(); + }); + let mut app = App::new(opts, Some(stream)); + app.data(shared_data); + app.data(b_sink); - let (sink, stream) = oneshot::channel::<()>(); - let (b_sink, mut b_stream) = broadcast::channel::<()>(1); - tokio::spawn(async move { - let _ = b_stream.recv().await; - sink.send(()).unwrap(); + app.get("/get", get_handler) + .post("/post", post_handler) + .post("/post/stream", body_stream) + .get( + "/closure", + move |res: HttpConnection, _req: HttpRequest| async { + println!("Closure Handler started"); + sleep(Duration::from_secs(1)).await; + println!("Closure Ready to respond"); + res.end( + Some("Closure it's the response".to_string().into_bytes()), + true, + ) + .await; + }, + ) + .listen( + 3001, + Some(|listen_socket| { + println!("{listen_socket:#?}"); + }), + ) + .run(); + println!("Server exiting"); }); - let mut app = App::new(opts, Some(stream)); - app.data(shared_data); - app.data(b_sink); - - app.get("/get", get_handler) - .post("/post", post_handler) - .post("/post/stream", body_stream) - .get( - "/closure", - move |res: HttpConnection, _req: HttpRequest| async { - println!("Closure Handler started"); - sleep(Duration::from_secs(1)).await; - println!("Closure Ready to respond"); - res.end( - Some("Closure it's the response".to_string().into_bytes()), - true, - ) - .await; - }, - ) - .listen( - 3001, - Some(|listen_socket| { - println!("{listen_socket:#?}"); - }), - ) - .run(); - println!("Server exiting"); } async fn post_handler(mut res: HttpConnection, _: HttpRequest) {