使用 s2n_quic 和 monoio 运行时 rust 启动错误(没有正在运行的反应器,必须从 Tokio 1.x 运行时的上下文中调用)
我正在尝试将 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论