run and start methods
This commit is contained in:
parent
f65a496d51
commit
7f2e84256a
@ -1,5 +1,5 @@
|
||||
use std::{
|
||||
error::Error, str::FromStr, sync::Arc, net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}
|
||||
error::Error, net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}, str::FromStr, sync::Arc, time::Duration
|
||||
};
|
||||
|
||||
use ignore_result::Ignore;
|
||||
@ -7,7 +7,7 @@ use log::{debug, info};
|
||||
|
||||
use tokio::{
|
||||
io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader},
|
||||
net::{TcpListener, TcpStream}
|
||||
net::{TcpListener, TcpStream}, time::sleep
|
||||
};
|
||||
use tokio_io_timeout::TimeoutStream;
|
||||
use tokio_rustls::TlsAcceptor;
|
||||
@ -38,14 +38,32 @@ impl FlowgateServer {
|
||||
}
|
||||
|
||||
pub async fn run(self) {
|
||||
self.start().await;
|
||||
|
||||
loop {
|
||||
sleep(Duration::from_secs(60)).await;
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn start(self) {
|
||||
let local_self = Arc::new(self);
|
||||
|
||||
local_self.clone().start_http().await;
|
||||
local_self.clone().start_https().await;
|
||||
}
|
||||
|
||||
pub async fn start_http(self: Arc<Self>) {
|
||||
tokio::spawn({
|
||||
let local_self = local_self.clone();
|
||||
let local_self = self.clone();
|
||||
async move { local_self.run_http().await.ignore(); }
|
||||
});
|
||||
|
||||
local_self.run_https().await.ignore();
|
||||
}
|
||||
|
||||
pub async fn start_https(self: Arc<Self>) {
|
||||
tokio::spawn({
|
||||
let local_self = self.clone();
|
||||
async move { local_self.run_https().await.ignore(); }
|
||||
});
|
||||
}
|
||||
|
||||
pub async fn run_http(self: Arc<Self>) -> Result<(), Box<dyn Error>> {
|
||||
|
@ -14,6 +14,5 @@ async fn main() {
|
||||
let config = Arc::new(Config::parse("conf.yml").unwrap());
|
||||
let server = FlowgateServer::new(config.clone());
|
||||
|
||||
// server.start().await;
|
||||
server.run().await;
|
||||
}
|
Loading…
Reference in New Issue
Block a user