使用 s2n_quic 和 monoio 运行时 rust 启动错误(没有正在运行的反应器,必须从 Tokio 1.x 运行时的上下文中调用)

发布于 2025-01-12 14:21:04 字数 1652 浏览 3 评论 0原文

我正在尝试将 monoio 与 s2n_quic 结合使用来实现快速运行时的 quic。运行时,它会打印出

StartError:
there is no reactor running, must be called from the context of a Tokio 1.x runtime

Here is my code

use monoio;
use s2n_quic::{provider::connection_id, Server};
use std::error::Error;


fn main() -> Result<(), Box<dyn Error>> {
    
    let mut rt = monoio::RuntimeBuilder::new()
        .with_entries(1024)
        .enable_timer()
        .build()
        .unwrap();
    rt.block_on(async {
        println!("it works2!");
        let server = Server::builder();

        match server
            .with_connection_id(connection_id::Default::default()).unwrap()
            .with_io("127.0.0.1:8080").unwrap()
            .start()
        {
            Ok(mut serv) => {
                while let Some(mut connection) = serv.accept().await {
                    monoio::spawn(async move {
                        while let Ok(Some(mut stream)) =
                            connection.accept_bidirectional_stream().await
                        {
                            monoio::spawn(async move {
                                while let Ok(Some(data)) = stream.receive().await {
                                    stream.send(data).await.expect("stream should be open");
                                }
                            });
                        }
                    });
                }
            }
            Err(e) => {
                println!("{}", e);
            }
        }
    });

    Ok(())
}

要运行它,您将需要 5.6 linux 内核。

I am trying to use monoio with s2n_quic to implement quic for this fast runtime. When run, it prints out

StartError:
there is no reactor running, must be called from the context of a Tokio 1.x runtime

Here is my code

use monoio;
use s2n_quic::{provider::connection_id, Server};
use std::error::Error;


fn main() -> Result<(), Box<dyn Error>> {
    
    let mut rt = monoio::RuntimeBuilder::new()
        .with_entries(1024)
        .enable_timer()
        .build()
        .unwrap();
    rt.block_on(async {
        println!("it works2!");
        let server = Server::builder();

        match server
            .with_connection_id(connection_id::Default::default()).unwrap()
            .with_io("127.0.0.1:8080").unwrap()
            .start()
        {
            Ok(mut serv) => {
                while let Some(mut connection) = serv.accept().await {
                    monoio::spawn(async move {
                        while let Ok(Some(mut stream)) =
                            connection.accept_bidirectional_stream().await
                        {
                            monoio::spawn(async move {
                                while let Ok(Some(data)) = stream.receive().await {
                                    stream.send(data).await.expect("stream should be open");
                                }
                            });
                        }
                    });
                }
            }
            Err(e) => {
                println!("{}", e);
            }
        }
    });

    Ok(())
}

To run it you will need 5.6 linux kernel.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文