Skip to content

Commit

Permalink
Add set_nodelay and set_keepalive (#123)
Browse files Browse the repository at this point in the history
These additions are similar to those in 271e24d, which were then
removed during the transition to futures and tokio in 5bf6560.
  • Loading branch information
lemonadesaltbagel authored and zonyitoo committed Sep 23, 2018
1 parent 35c6959 commit 38b2df6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/relay/tcprelay/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ fn handle_client(server_cfg: Arc<ServerConfig>,
config: Arc<Config>,
socket: TcpStream)
-> impl Future<Item = (), Error = ()> + Send {
if let Err(err) = socket.set_keepalive(*server_cfg.timeout()) {
error!("Failed to set keep alive: {:?}", err);
}

if let Err(err) = socket.set_nodelay(true) {
error!("Failed to set no delay: {:?}", err);
}

futures::lazy(move || match socket.peer_addr() {
Ok(addr) => Ok((socket, addr)),
Err(err) => {
Expand Down
8 changes: 8 additions & 0 deletions src/relay/tcprelay/socks5_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ fn handle_socks5_client(config: Arc<Config>,
conf: Arc<ServerConfig>,
udp_conf: UdpConfig)
-> io::Result<()> {
if let Err(err) = s.set_keepalive(*conf.timeout()) {
error!("Failed to set keep alive: {:?}", err);
}

if let Err(err) = s.set_nodelay(true) {
error!("Failed to set no delay: {:?}", err);
}

let client_addr = s.peer_addr()?;
let cloned_client_addr = client_addr;
let fut = futures::lazy(|| Ok(s.split()))
Expand Down

0 comments on commit 38b2df6

Please sign in to comment.