Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use poll-io for h2 example #234

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions examples/h2_client.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
//! Example for using h2 directly.
//! Note: This is only meant for compatible usage.
//! Example code is modified from https://github.com/hyperium/h2/blob/master/examples/client.rs.

use monoio::net::TcpStream;
use monoio_compat::StreamWrapper;
use monoio::{io::IntoPollIo, net::TcpStream};

#[monoio::main]
async fn main() {
let tcp = TcpStream::connect("127.0.0.1:5928").await.unwrap();
let tcp_wrapper = StreamWrapper::new(tcp);
let (mut client, h2) = h2::client::handshake(tcp_wrapper).await.unwrap();
let io = TcpStream::connect("127.0.0.1:5928")
.await
.unwrap()
.into_poll_io()
.unwrap();
let (mut client, h2) = h2::client::handshake(io).await.unwrap();

println!("sending request");

Expand Down
13 changes: 7 additions & 6 deletions examples/h2_server.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//! Example for using h2 directly.
//! Note: This is only meant for compatible usage.
//! Example code is modified from https://github.com/hyperium/h2/blob/master/examples/server.rs.

use monoio::net::{TcpListener, TcpStream};
use monoio_compat::StreamWrapper;
use monoio::{
io::IntoPollIo,
net::{TcpListener, TcpStream},
};

async fn serve(socket: TcpStream) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let socket_wrapper = StreamWrapper::new(socket);
let mut connection = h2::server::handshake(socket_wrapper).await?;
async fn serve(io: TcpStream) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let io = io.into_poll_io()?;
let mut connection = h2::server::handshake(io).await?;
println!("H2 connection bound");

while let Some(result) = connection.accept().await {
Expand Down
Loading