Skip to content

Commit

Permalink
ctrlc2 usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Nov 20, 2023
1 parent 73fff50 commit 9f3571c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 24 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ base64 = "0.21"
bytes = "1.5"
chrono = "0.4"
clap = { version = "4.4", features = ["derive"] }
ctrlc2 = { version = "3.5", features = ["tokio", "termination"] }
dotenvy = "0.15"
env_logger = "0.10"
futures-util = { version = "0.3", default-features = false, features = [
"sink",
"std",
] }
http = "0.2"
http = "1.0"
httparse = "1.8"
lazy_static = "1.4"
log = "0.4"
Expand All @@ -34,7 +35,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
socks5-impl = "0.5"
thiserror = "1.0"
tokio = { version = "1.32", features = ["full"] }
tokio = { version = "1.34", features = ["full"] }
tokio-rustls = "0.24"
tokio-tungstenite = { version = "0.20", features = ["rustls-tls-webpki-roots"] }
trust-dns-proto = "0.23"
Expand All @@ -56,7 +57,7 @@ crossbeam = "0.8"
jni = { version = "0.21", default-features = false }

[target.'cfg(target_os="windows")'.dependencies]
windows = { version = "0.51", features = [
windows = { version = "0.52", features = [
"Win32_NetworkManagement_IpHelper",
"Win32_NetworkManagement_Ndis",
"Win32_Networking_WinSock",
Expand Down
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ pub(crate) async fn create_ws_stream<S: AsyncRead + AsyncWrite + Unpin>(

let accept_key = tungstenite::handshake::derive_accept_key(key.as_bytes());

if accept_key.as_str() != remote_key.to_str()? {
if accept_key.as_str() != remote_key.to_str().map_err(|e| e.to_string())? {
return Err(Error::from("accept key error"));
}

Expand Down
24 changes: 4 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,7 @@ async fn async_main(config: config::Config) -> Result<()> {

let local_addr = config.listen_addr()?;

tokio::spawn(async move {
#[cfg(unix)]
{
use tokio::signal::unix::{signal, SignalKind};
let mut kill_signal = signal(SignalKind::terminate())?;
tokio::select! {
_ = tokio::signal::ctrl_c() => log::info!("Ctrl-C received, shutting down..."),
_ = kill_signal.recv() => log::info!("Kill signal received, shutting down..."),
}
}

#[cfg(not(unix))]
{
tokio::signal::ctrl_c().await?;
log::info!("Ctrl-C received, shutting down...");
}

ctrlc2::set_async_handler(async move {
exiting_flag.store(true, std::sync::atomic::Ordering::Relaxed);

let addr = if local_addr.is_ipv6() {
Expand All @@ -94,9 +78,9 @@ async fn async_main(config: config::Config) -> Result<()> {
SocketAddr::from((Ipv4Addr::LOCALHOST, local_addr.port()))
};
let _ = std::net::TcpStream::connect(addr);

Ok::<(), Error>(())
});
log::info!("");
})
.await;

if let Err(e) = main_body.await {
log::error!("{}", e);
Expand Down

0 comments on commit 9f3571c

Please sign in to comment.