[geary/mjog/imap-command-cancellation: 3/6] Geary.Imap.ClientConnection: Avoid sending cancelled commands




commit 0707500561c16edfa4e6a88725bf9444a84a38a1
Author: Michael Gratton <mike vee net>
Date:   Tue Sep 1 22:50:42 2020 +1000

    Geary.Imap.ClientConnection: Avoid sending cancelled commands
    
    Now that commands has a `should_send` cancellable property, check that
    before queuing and before sending, so that cancelled commands never
    actually get sent over the wire.

 src/engine/imap/transport/imap-client-connection.vala | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/src/engine/imap/transport/imap-client-connection.vala 
b/src/engine/imap/transport/imap-client-connection.vala
index 82822d311..debb843db 100644
--- a/src/engine/imap/transport/imap-client-connection.vala
+++ b/src/engine/imap/transport/imap-client-connection.vala
@@ -260,8 +260,16 @@ public class Geary.Imap.ClientConnection : BaseObject, Logging.Source {
         yield open_channels_async();
     }
 
-    public void send_command(Command new_command) throws ImapError {
+    public void send_command(Command new_command)
+        throws ImapError, GLib.IOError.CANCELLED {
         check_connection();
+        if (new_command.should_send != null &&
+            new_command.should_send.is_cancelled()) {
+            throw new GLib.IOError.CANCELLED(
+                "Not queuing command, sending is cancelled: %s",
+                new_command.to_brief_string()
+            );
+        }
 
         this.pending_queue.send(new_command);
 
@@ -427,6 +435,13 @@ public class Geary.Imap.ClientConnection : BaseObject, Logging.Source {
     // sending literals.
     private async void flush_command(Command command, Cancellable cancellable)
         throws GLib.Error {
+        if (command.should_send != null &&
+            command.should_send.is_cancelled()) {
+            throw new GLib.IOError.CANCELLED(
+                "Not sending command, sending is cancelled: %s",
+                command.to_brief_string()
+            );
+        }
         GLib.Error? ser_error = null;
         try {
             // Assign a new tag; Commands with pre-assigned Tags
@@ -576,8 +591,8 @@ public class Geary.Imap.ClientConnection : BaseObject, Logging.Source {
     private void on_idle_timeout() {
         debug("Initiating IDLE");
         try {
-        } catch (ImapError err) {
             this.send_command(new IdleCommand(this.open_cancellable));
+        } catch (GLib.Error err) {
             warning("Error sending IDLE: %s", err.message);
         }
     }


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