[geary/wip/conversation-polish: 8/26] Make ImapCommand throw a timeout error when a timeout has occurred



commit 98be2d117bd4ad276935db83f0d783aa084155f3
Author: Michael Gratton <mike vee net>
Date:   Thu Jan 24 18:55:39 2019 +1100

    Make ImapCommand throw a timeout error when a timeout has occurred
    
    This allows API clients to retry email store and folder operations if
    the network has disappeared.

 src/engine/imap/command/imap-command.vala | 11 +++++++++++
 1 file changed, 11 insertions(+)
---
diff --git a/src/engine/imap/command/imap-command.vala b/src/engine/imap/command/imap-command.vala
index a77bfa55..dd6eb18d 100644
--- a/src/engine/imap/command/imap-command.vala
+++ b/src/engine/imap/command/imap-command.vala
@@ -78,6 +78,8 @@ public class Geary.Imap.Command : BaseObject {
     private Geary.Nonblocking.Semaphore complete_lock =
         new Geary.Nonblocking.Semaphore();
 
+    private bool timed_out = false;
+
     private Geary.Nonblocking.Spinlock? literal_spinlock = null;
     private GLib.Cancellable? literal_cancellable = null;
 
@@ -224,6 +226,14 @@ public class Geary.Imap.Command : BaseObject {
     public async void wait_until_complete(GLib.Cancellable cancellable)
         throws GLib.Error {
         yield this.complete_lock.wait_async(cancellable);
+
+        if (this.timed_out) {
+            throw new ImapError.TIMED_OUT(
+                "%s: No command response was received",
+                to_brief_string()
+            );
+        }
+
         // Since this is part of the public API, perform a strict
         // check on the status code.
         check_status(true);
@@ -353,6 +363,7 @@ public class Geary.Imap.Command : BaseObject {
     }
 
     private void on_response_timeout() {
+        this.timed_out = true;
         cancel_command();
         response_timed_out();
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]