2019-06-29 08:08:12 +00:00
|
|
|
use failure::*;
|
|
|
|
use futures::*;
|
|
|
|
|
|
|
|
// Simple H2 server to test H2 speed with h2client.rs
|
|
|
|
|
|
|
|
use tokio::net::TcpListener;
|
2019-08-28 13:50:40 +00:00
|
|
|
use tokio::io::{AsyncRead, AsyncWrite};
|
2019-06-29 08:08:12 +00:00
|
|
|
|
2019-08-28 13:50:40 +00:00
|
|
|
use proxmox_backup::client::pipe_to_stream::PipeToSendStream;
|
2019-06-29 08:08:12 +00:00
|
|
|
|
2020-01-20 11:52:22 +00:00
|
|
|
fn main() -> Result<(), Error> {
|
|
|
|
proxmox_backup::tools::runtime::main(run())
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn run() -> Result<(), Error> {
|
2019-12-12 14:27:07 +00:00
|
|
|
let mut listener = TcpListener::bind(std::net::SocketAddr::from(([127,0,0,1], 8008))).await?;
|
2019-06-29 08:08:12 +00:00
|
|
|
|
|
|
|
println!("listening on {:?}", listener.local_addr());
|
|
|
|
|
2019-12-12 14:27:07 +00:00
|
|
|
loop {
|
|
|
|
let (socket, _addr) = listener.accept().await?;
|
2019-08-28 13:50:40 +00:00
|
|
|
tokio::spawn(handle_connection(socket)
|
|
|
|
.map(|res| {
|
|
|
|
if let Err(err) = res {
|
|
|
|
eprintln!("Error: {}", err);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
2019-06-29 08:08:12 +00:00
|
|
|
|
2019-08-28 13:50:40 +00:00
|
|
|
async fn handle_connection<T: AsyncRead + AsyncWrite + Unpin>(socket: T) -> Result<(), Error> {
|
|
|
|
let mut conn = h2::server::handshake(socket).await?;
|
2019-06-29 08:08:12 +00:00
|
|
|
|
2019-08-28 13:50:40 +00:00
|
|
|
println!("H2 connection bound");
|
2019-06-29 08:08:12 +00:00
|
|
|
|
2019-08-28 13:50:40 +00:00
|
|
|
while let Some((request, mut respond)) = conn.try_next().await? {
|
|
|
|
println!("GOT request: {:?}", request);
|
2019-06-29 08:08:12 +00:00
|
|
|
|
2019-08-28 13:50:40 +00:00
|
|
|
let response = http::Response::builder()
|
|
|
|
.status(http::StatusCode::OK)
|
|
|
|
.body(())
|
|
|
|
.unwrap();
|
2019-06-29 08:08:12 +00:00
|
|
|
|
2019-08-28 13:50:40 +00:00
|
|
|
let send = respond.send_response(response, false).unwrap();
|
|
|
|
let data = vec![65u8; 1024*1024];
|
|
|
|
PipeToSendStream::new(bytes::Bytes::from(data), send).await?;
|
|
|
|
println!("DATA SENT");
|
|
|
|
}
|
2019-06-29 08:08:12 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|