Skip to content

Commit

Permalink
Merge pull request #23 from ssrlive/main
Browse files Browse the repository at this point in the history
timeout and shutdown
  • Loading branch information
SajjadPourali committed Mar 4, 2024
2 parents 9d21ce7 + e4a3b6e commit 6147d5a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
5 changes: 3 additions & 2 deletions examples/tun2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
//!
//! This example must be run as root or administrator privileges.
//! ```
//! sudo target/debug/examples/tun --server-addr 127.0.0.1:8080 # Linux or macOS
//! sudo target/debug/examples/tun2 --server-addr 127.0.0.1:8080 # Linux or macOS
//! ```
//! Then please run the `echo` example server, which listens on TCP & UDP ports 127.0.0.1:8080.
//! ```
//! target/debug/examples/echo 127.0.0.1:8080
//! cargo install socks5-impl --example echo-server
//! echo-server --listen-addr 127.0.0.1:8080 --tcp-timeout 600
//! ```
//! To route traffic to the tun interface, run the following command with root or administrator privileges:
//! ```
Expand Down
5 changes: 1 addition & 4 deletions src/stream/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,7 @@ impl AsyncWrite for IpStackTcpStream {
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<(), std::io::Error>> {
let notified = self.shutdown.get_or_insert(Notify::new()).notified();
match Pin::new(&mut Box::pin(notified)).poll(cx) {
std::task::Poll::Ready(_) => std::task::Poll::Ready(Ok(())),
std::task::Poll::Pending => std::task::Poll::Pending,
}
Pin::new(&mut Box::pin(notified)).poll(cx).map(Ok)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/stream/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl AsyncRead for IpStackUdpStream {
return std::task::Poll::Ready(Ok(()));
}
if matches!(self.timeout.as_mut().poll(cx), std::task::Poll::Ready(_)) {
return std::task::Poll::Ready(Ok(())); // todo: return timeout error
return std::task::Poll::Ready(Err(std::io::Error::from(std::io::ErrorKind::TimedOut)));
}

self.reset_timeout();
Expand Down

0 comments on commit 6147d5a

Please sign in to comment.