Skip to content

Commit

Permalink
feat: add client signal handle logic
Browse files Browse the repository at this point in the history
  • Loading branch information
oowl committed May 2, 2023
1 parent bac2aa8 commit 583c41a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use clap::Parser;
use quinn::{ClientConfig, Endpoint, VarInt};
use std::{error::Error, net::SocketAddr, sync::Arc, net::ToSocketAddrs};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::signal::unix::{signal, SignalKind};
use url::Url;

#[allow(unused_imports)]
Expand Down Expand Up @@ -176,9 +177,23 @@ pub async fn run(options: Opt) -> Result<(), Box<dyn Error>> {
}
};

let signal_thread = async move {
let mut stream = match signal(SignalKind::hangup()) {
Ok(s) => s,
Err(e) => {
error!("[client] create signal stream error: {}", e);
return;
}
};

stream.recv().await;
info!("[client] got signal HUP");
};

tokio::select! {
_ = recv_thread => (),
_ = write_thread => (),
_ = signal_thread => connection.close(0u32.into(), b"signal HUP"),
}

info!("[client] exit client");
Expand Down

0 comments on commit 583c41a

Please sign in to comment.