Skip to content

Commit

Permalink
feat: fast check before relay
Browse files Browse the repository at this point in the history
  • Loading branch information
yinheli committed Aug 31, 2022
1 parent bb108da commit 5a4c0b1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/gateway/relay_tcp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
net::IpAddr,
sync::{Arc, Mutex},
time::Duration,
};

use log::warn;
Expand All @@ -14,6 +15,7 @@ use tokio::{
tcp::{ReadHalf, WriteHalf},
TcpListener,
},
time,
};

use crate::{
Expand Down Expand Up @@ -184,6 +186,8 @@ fn find_target(setting: ArcSetting, session: Session) -> Option<(String, String,
}

async fn copy<'a>(r: &mut ReadHalf<'a>, w: &mut WriteHalf<'a>) -> Result<u64, io::Error> {
time::timeout(Duration::from_secs(1), r.readable()).await??;
time::timeout(Duration::from_secs(1), w.writable()).await??;
let n = io::copy(r, w).await?;
w.shutdown().await?;
Ok(n)
Expand Down

0 comments on commit 5a4c0b1

Please sign in to comment.