Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Itsusinn committed Dec 21, 2024
1 parent 3632d0d commit 37b7ed0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion tuic-server/src/connection/handle_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Connection {
let target_addr = conn.addr().to_string();

info!(
"[{id:#010x}] [{addr}] [{user}] [TCP] {target_addr}",
"[{id:#010x}] [{addr}] [{user}] [TCP] {target_addr} ",
id = self.id(),
addr = self.inner.remote_address(),
user = self.auth,
Expand Down Expand Up @@ -63,6 +63,7 @@ impl Connection {
// a <- b rx
let (tx, rx, err) =
exchange_tcp(&mut conn, &mut stream, self.ctx.cfg.stream_timeout).await;
// let (tx, rx) = tokio::io::copy_bidirectional(&mut conn, &mut stream).await?;
_ = conn.reset(ERROR_CODE);
_ = stream.shutdown().await;

Expand Down
2 changes: 1 addition & 1 deletion tuic-server/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod handle_stream;
mod handle_task;
mod udp_session;

pub const ERROR_CODE: VarInt = VarInt::from_u32(0);
pub const ERROR_CODE: VarInt = VarInt::from_u32(6000);
pub const INIT_CONCURRENT_STREAMS: u32 = 32;

#[derive(Clone)]
Expand Down
6 changes: 4 additions & 2 deletions tuic-server/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt};

const BUFFER_SIZE: usize = 8 * 1024;

#[allow(dead_code)]
pub async fn exchange_tcp(
a: &mut tuic_quinn::Connect,
b: &mut tokio::net::TcpStream,
Expand All @@ -18,6 +19,7 @@ pub async fn exchange_tcp(
let mut last_err = None;
let mut timeout = tokio::time::interval(timeout);
timeout.reset();

loop {
tokio::select! {
_ = timeout.tick() => {
Expand All @@ -28,7 +30,7 @@ pub async fn exchange_tcp(
a2b_res = a.recv.read(&mut a2b) => match a2b_res {
Ok(Some(num)) => {
a2b_num += num;
if let Err(err) = b.write(&a2b).await {
if let Err(err) = b.write_all(&a2b[..num]).await {
last_err = Some(err.into());
break;
}
Expand All @@ -50,7 +52,7 @@ pub async fn exchange_tcp(
break;
}
b2a_num += num;
if let Err(err) = a.send.write(&b2a).await {
if let Err(err) = a.send.write_all(&b2a[..num]).await {
last_err = Some(err.into());
break;
}
Expand Down

0 comments on commit 37b7ed0

Please sign in to comment.