mirror of
https://github.com/rustdesk/rustdesk-server.git
synced 2025-01-19 07:43:32 +08:00
Feat: listen for unix signal
This commit is contained in:
parent
848b5aedb7
commit
ca2bc99a38
BIN
db_v2.sqlite3
BIN
db_v2.sqlite3
Binary file not shown.
@ -5,10 +5,7 @@ fn main() {
|
||||
.out_dir("src/protos")
|
||||
.inputs(&["protos/rendezvous.proto", "protos/message.proto"])
|
||||
.include("protos")
|
||||
.customize(
|
||||
protobuf_codegen::Customize::default()
|
||||
.tokio_bytes(true)
|
||||
)
|
||||
.customize(protobuf_codegen::Customize::default().tokio_bytes(true))
|
||||
.run()
|
||||
.expect("Codegen failed.");
|
||||
}
|
||||
|
@ -565,4 +565,3 @@ pub fn transform_windows_path(entries: &mut Vec<FileEntry>) {
|
||||
entry.name = entry.name.replace("\\", "/");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
use clap::App;
|
||||
use hbb_common::{anyhow::Context, log, ResultType};
|
||||
use hbb_common::{
|
||||
anyhow::{Context, Result},
|
||||
log, ResultType,
|
||||
};
|
||||
use ini::Ini;
|
||||
use sodiumoxide::crypto::sign;
|
||||
use std::{
|
||||
@ -138,3 +141,43 @@ pub fn gen_sk(wait: u64) -> (String, Option<sign::SecretKey>) {
|
||||
}
|
||||
("".to_owned(), None)
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub async fn listen_signal() -> Result<()> {
|
||||
use hbb_common::tokio;
|
||||
use hbb_common::tokio::signal::unix::{signal, SignalKind};
|
||||
|
||||
tokio::spawn(async {
|
||||
let mut s = signal(SignalKind::hangup())?;
|
||||
let hangup = s.recv();
|
||||
let mut s = signal(SignalKind::terminate())?;
|
||||
let terminate = s.recv();
|
||||
let mut s = signal(SignalKind::interrupt())?;
|
||||
let interrupt = s.recv();
|
||||
let mut s = signal(SignalKind::quit())?;
|
||||
let quit = s.recv();
|
||||
|
||||
tokio::select! {
|
||||
_ = hangup => {
|
||||
log::info!("signal hangup");
|
||||
}
|
||||
_ = terminate => {
|
||||
log::info!("signal terminate");
|
||||
}
|
||||
_ = interrupt => {
|
||||
log::info!("signal interrupt");
|
||||
}
|
||||
_ = quit => {
|
||||
log::info!("signal quit");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.await?
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
pub async fn listen_signal() -> Result<()> {
|
||||
let () = std::future::pending().await;
|
||||
unreachable!();
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
use crate::common::*;
|
||||
use crate::database;
|
||||
use hbb_common::{
|
||||
bytes::Bytes,
|
||||
log,
|
||||
rendezvous_proto::*,
|
||||
tokio::sync::{Mutex, RwLock},
|
||||
bytes::Bytes,
|
||||
ResultType,
|
||||
};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
@ -81,15 +81,22 @@ pub async fn start(port: &str, key: &str) -> ResultType<()> {
|
||||
log::info!("Listening on tcp {}", addr);
|
||||
let addr2 = format!("0.0.0.0:{}", port.parse::<u16>().unwrap() + 2);
|
||||
log::info!("Listening on websocket {}", addr2);
|
||||
loop {
|
||||
log::info!("Start");
|
||||
io_loop(
|
||||
new_listener(&addr, false).await?,
|
||||
new_listener(&addr2, false).await?,
|
||||
&key,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
let main_task = async move {
|
||||
loop {
|
||||
log::info!("Start");
|
||||
io_loop(
|
||||
new_listener(&addr, false).await?,
|
||||
new_listener(&addr2, false).await?,
|
||||
&key,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
};
|
||||
let listen_signal = crate::common::listen_signal();
|
||||
tokio::select!(
|
||||
res = main_task => res,
|
||||
res = listen_signal => res,
|
||||
)
|
||||
}
|
||||
|
||||
fn check_params() {
|
||||
|
@ -170,37 +170,44 @@ impl RendezvousServer {
|
||||
allow_err!(test_hbbs(test_addr).await);
|
||||
});
|
||||
};
|
||||
loop {
|
||||
log::info!("Start");
|
||||
match rs
|
||||
.io_loop(
|
||||
&mut rx,
|
||||
&mut listener,
|
||||
&mut listener2,
|
||||
&mut listener3,
|
||||
&mut socket,
|
||||
&key,
|
||||
)
|
||||
.await
|
||||
{
|
||||
LoopFailure::UdpSocket => {
|
||||
drop(socket);
|
||||
socket = FramedSocket::new_with_buf_size(&addr, rmem).await?;
|
||||
}
|
||||
LoopFailure::Listener => {
|
||||
drop(listener);
|
||||
listener = new_listener(&addr, false).await?;
|
||||
}
|
||||
LoopFailure::Listener2 => {
|
||||
drop(listener2);
|
||||
listener2 = new_listener(&addr2, false).await?;
|
||||
}
|
||||
LoopFailure::Listener3 => {
|
||||
drop(listener3);
|
||||
listener3 = new_listener(&addr3, false).await?;
|
||||
let main_task = async move {
|
||||
loop {
|
||||
log::info!("Start");
|
||||
match rs
|
||||
.io_loop(
|
||||
&mut rx,
|
||||
&mut listener,
|
||||
&mut listener2,
|
||||
&mut listener3,
|
||||
&mut socket,
|
||||
&key,
|
||||
)
|
||||
.await
|
||||
{
|
||||
LoopFailure::UdpSocket => {
|
||||
drop(socket);
|
||||
socket = FramedSocket::new_with_buf_size(&addr, rmem).await?;
|
||||
}
|
||||
LoopFailure::Listener => {
|
||||
drop(listener);
|
||||
listener = new_listener(&addr, false).await?;
|
||||
}
|
||||
LoopFailure::Listener2 => {
|
||||
drop(listener2);
|
||||
listener2 = new_listener(&addr2, false).await?;
|
||||
}
|
||||
LoopFailure::Listener3 => {
|
||||
drop(listener3);
|
||||
listener3 = new_listener(&addr3, false).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
let listen_signal = listen_signal();
|
||||
tokio::select!(
|
||||
res = main_task => res,
|
||||
res = listen_signal => res,
|
||||
)
|
||||
}
|
||||
|
||||
async fn io_loop(
|
||||
|
@ -1 +1 @@
|
||||
pub const VERSION: &str = "1.1.6";
|
||||
pub const VERSION: &str = "1.1.6";
|
||||
|
Loading…
Reference in New Issue
Block a user