feat: pending test

This commit is contained in:
2022-08-23 02:30:10 +08:00
parent 9e9301d4d7
commit 67e1d2f495
4 changed files with 40 additions and 26 deletions

View File

@@ -2,11 +2,14 @@ use std::io::{Error, ErrorKind};
use std::time::Duration;
use futures::future::try_join;
use rust_util::util_msg;
use rust_util::util_msg::MessageType;
use s2n_quic::stream::BidirectionalStream;
use tokio::{select, time};
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
use tokio::net::TcpStream;
#[derive(Debug)]
enum StreamDirection {
Up,
Down,
@@ -143,7 +146,7 @@ async fn inner_transfer<'a, R1, W1, R2, W2>(mut ri: &'a mut R1, mut wi: &'a mut
// }
async fn copy_data<'a, R, W>(
reader: &'a mut R, writer: &'a mut W, _direction: StreamDirection, _conn_count: &str) -> tokio::io::Result<u64>
reader: &'a mut R, writer: &'a mut W, direction: StreamDirection, conn_count: &str) -> tokio::io::Result<u64>
where R: AsyncRead + Unpin + ?Sized,
W: AsyncWrite + Unpin + ?Sized {
let mut total_copied_bytes = 0_u64;
@@ -151,11 +154,17 @@ async fn copy_data<'a, R, W>(
loop {
match reader.read(&mut buff).await {
Ok(0) => return Ok(total_copied_bytes),
Ok(n) => match writer.write_all(&buff[..n]).await {
Ok(_) => {
total_copied_bytes += n as u64;
Ok(n) => {
util_msg::when(MessageType::DEBUG, || {
debugging!("[conn {}] Direction: {:?}, {} bytes: {:02x?}", conn_count, direction, n, &buff[..n]);
debugging!("[conn {}] Direction: {:?}, {} string: {}", conn_count, direction, n, String::from_utf8_lossy(&buff[..n]).to_string());
});
match writer.write_all(&buff[..n]).await {
Ok(_) => {
total_copied_bytes += n as u64;
}
Err(e) => return Err(e),
}
Err(e) => return Err(e),
}
Err(e) => return Err(e),
}