Close sessions once the disconnect events shows up

This commit is contained in:
Rodolphe Breard 2019-01-05 16:28:51 +01:00
parent d05423edba
commit c127c5ca24

View file

@ -79,7 +79,9 @@ impl SmtpIn {
/// already exists, creates it. /// already exists, creates it.
fn dispatch(&mut self, input: &str) -> Result<(), Error> { fn dispatch(&mut self, input: &str) -> Result<(), Error> {
let entry = Entry::from_str(input)?; let entry = Entry::from_str(input)?;
let channel = match self.sessions.get(&entry.session_id) { let id = entry.session_id;
let disconnect = entry.event == Event::LinkDisconnect;
let channel = match self.sessions.get(&id) {
Some((r, _)) => r, Some((r, _)) => r,
None => { None => {
let (handlers_tx, handlers_rx) = mpsc::channel(); let (handlers_tx, handlers_rx) = mpsc::channel();
@ -97,6 +99,9 @@ impl SmtpIn {
} }
}; };
channel.send(entry)?; channel.send(entry)?;
if disconnect {
let _ = self.sessions.remove(&id);
}
Ok(()) Ok(())
} }