Handle CTRL+C for IMAP
This commit is contained in:
parent
5599901b3b
commit
212573b4b1
2 changed files with 21 additions and 16 deletions
|
@ -11,11 +11,11 @@ use rusoto_signature::Region;
|
||||||
use tokio::sync::watch;
|
use tokio::sync::watch;
|
||||||
use tower::Service;
|
use tower::Service;
|
||||||
|
|
||||||
use crate::service;
|
|
||||||
use crate::lmtp::*;
|
|
||||||
use crate::config::*;
|
use crate::config::*;
|
||||||
|
use crate::lmtp::*;
|
||||||
use crate::login::{ldap_provider::*, static_provider::*, *};
|
use crate::login::{ldap_provider::*, static_provider::*, *};
|
||||||
use crate::mailbox::Mailbox;
|
use crate::mailbox::Mailbox;
|
||||||
|
use crate::service;
|
||||||
|
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
lmtp_server: Option<Arc<LmtpServer>>,
|
lmtp_server: Option<Arc<LmtpServer>>,
|
||||||
|
@ -38,7 +38,6 @@ impl Server {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn run(self) -> Result<()> {
|
pub async fn run(self) -> Result<()> {
|
||||||
//tracing::info!("Starting server on {:#}", self.imap.incoming.local_addr);
|
//tracing::info!("Starting server on {:#}", self.imap.incoming.local_addr);
|
||||||
tracing::info!("Starting Aerogramme...");
|
tracing::info!("Starting Aerogramme...");
|
||||||
|
@ -49,8 +48,8 @@ impl Server {
|
||||||
let _ = provoke_exit.send(true);
|
let _ = provoke_exit.send(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
try_join!(
|
||||||
try_join!(async {
|
async {
|
||||||
match self.lmtp_server.as_ref() {
|
match self.lmtp_server.as_ref() {
|
||||||
None => Ok(()),
|
None => Ok(()),
|
||||||
Some(s) => s.run(exit_signal.clone()).await,
|
Some(s) => s.run(exit_signal.clone()).await,
|
||||||
|
@ -58,12 +57,15 @@ impl Server {
|
||||||
},
|
},
|
||||||
//@FIXME handle ctrl + c
|
//@FIXME handle ctrl + c
|
||||||
async {
|
async {
|
||||||
self.imap_server.await?;
|
let mut must_exit = exit_signal.clone();
|
||||||
|
tokio::select! {
|
||||||
|
s = self.imap_server => s?,
|
||||||
|
_ = must_exit.changed() => tracing::info!("IMAP server received CTRL+C, exiting."),
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,10 @@ pub struct Instance {
|
||||||
pub user: Option<User>,
|
pub user: Option<User>,
|
||||||
}
|
}
|
||||||
impl Instance {
|
impl Instance {
|
||||||
fn new(login_provider: Arc<dyn LoginProvider + Send + Sync>, rx: mpsc::Receiver<Message>) -> Self {
|
fn new(
|
||||||
|
login_provider: Arc<dyn LoginProvider + Send + Sync>,
|
||||||
|
rx: mpsc::Receiver<Message>,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
login_provider,
|
login_provider,
|
||||||
rx,
|
rx,
|
||||||
|
|
Loading…
Reference in a new issue