aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2022-06-13 11:58:33 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2022-06-13 11:58:33 +0200
commitbdae537fe7dbf9c7fc731af3f427400055ea03cf (patch)
tree958bb1f9a238a7a9126278d0e0ba6436b8924ff6
parent4914c453778db4198b7de667cd4e196b051079a1 (diff)
downloadaerogramme-bdae537fe7dbf9c7fc731af3f427400055ea03cf.tar.gz
aerogramme-bdae537fe7dbf9c7fc731af3f427400055ea03cf.zip
Add response
-rw-r--r--src/session.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/session.rs b/src/session.rs
index 7553caf..4e8b301 100644
--- a/src/session.rs
+++ b/src/session.rs
@@ -21,7 +21,7 @@ const MAX_PIPELINED_COMMANDS: usize = 10;
struct Message {
req: Request,
- tx: oneshot::Sender<Response>,
+ tx: oneshot::Sender<Result<Response, BalError>>,
}
pub struct Manager {
@@ -55,10 +55,13 @@ impl Manager {
// @FIXME add a timeout, handle a session that fails.
async {
- rx.await.or_else(|e| {
- tracing::warn!("Got error {:#?}", e);
- Response::bad("No response from the session handler")
- })
+ match rx.await {
+ Ok(r) => r,
+ Err(e) => {
+ tracing::warn!("Got error {:#?}", e);
+ Response::bad("No response from the session handler")
+ },
+ }
}.boxed()
}
}
@@ -85,7 +88,7 @@ impl Instance {
while let Some(msg) = self.rx.recv().await {
let mut cmd = command::Command::new(msg.req.tag, self);
- let _ = match msg.req.body {
+ let res = match msg.req.body {
CommandBody::Capability => cmd.capability().await,
CommandBody::Login { username, password } => cmd.login(username, password).await,
CommandBody::Lsub { reference, mailbox_wildcard } => cmd.lsub(reference, mailbox_wildcard).await,
@@ -94,6 +97,10 @@ impl Instance {
CommandBody::Fetch { sequence_set, attributes, uid } => cmd.fetch(sequence_set, attributes, uid).await,
_ => Response::bad("Error in IMAP command received by server."),
};
+
+ //@FIXME I think we should quit this thread on error and having our manager watch it,
+ // and then abort the session as it is corrupted.
+ msg.tx.send(res).unwrap_or_else(|e| tracing::warn!("failed to send imap response to manager: {:#?}", e));
}
//@FIXME add more info about the runner