mirror of
https://github.com/mii443/rs-easy-p2p.git
synced 2025-08-22 16:15:38 +00:00
add close
This commit is contained in:
10
src/bin.rs
10
src/bin.rs
@ -62,7 +62,8 @@ async fn chat(mut p2p: P2P) -> Result<()> {
|
|||||||
println!("P2P Closed!");
|
println!("P2P Closed!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let peer_connection = p2p.peer_connection.clone();
|
||||||
let send_thread = tokio::spawn(async move {
|
let send_thread = tokio::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
let line = tokio::task::spawn_blocking(|| read_line()).await.unwrap();
|
let line = tokio::task::spawn_blocking(|| read_line()).await.unwrap();
|
||||||
@ -72,8 +73,11 @@ async fn chat(mut p2p: P2P) -> Result<()> {
|
|||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = receive_thread => {},
|
_ = receive_thread => {},
|
||||||
_ = send_thread => {}
|
_ = send_thread => {},
|
||||||
|
_ = tokio::signal::ctrl_c() => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
peer_connection.lock().await.close().await.unwrap();
|
||||||
|
|
||||||
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ pub struct ConnectionCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct P2P {
|
pub struct P2P {
|
||||||
peer_connection: Arc<Mutex<RTCPeerConnection>>,
|
pub peer_connection: Arc<Mutex<RTCPeerConnection>>,
|
||||||
send_data_tx: Arc<Mutex<Sender<SendData>>>,
|
send_data_tx: Arc<Mutex<Sender<SendData>>>,
|
||||||
send_data_rx: Arc<Mutex<Receiver<SendData>>>,
|
send_data_rx: Arc<Mutex<Receiver<SendData>>>,
|
||||||
pub receive_data_rx: Arc<Mutex<Receiver<Receive>>>,
|
pub receive_data_rx: Arc<Mutex<Receiver<Receive>>>,
|
||||||
|
Reference in New Issue
Block a user