[geary] Make public I/O methods in Imap.Client require cancellables



commit a08cecad7bb722b96f6aa28a433ea0e1b88cd759
Author: Michael Gratton <mike vee net>
Date:   Wed Jan 16 11:26:12 2019 +1100

    Make public I/O methods in Imap.Client require cancellables
    
    Explicit is better than implcit. Fix a few places where it wasn't being
    passed in, resulting in some criticals when accounts have gone away.

 src/engine/imap/api/imap-client-service.vala       |  6 +-
 src/engine/imap/transport/imap-client-session.vala | 85 +++++++++++++---------
 2 files changed, 53 insertions(+), 38 deletions(-)
---
diff --git a/src/engine/imap/api/imap-client-service.vala b/src/engine/imap/api/imap-client-service.vala
index ff854815..aa153cbc 100644
--- a/src/engine/imap/api/imap-client-service.vala
+++ b/src/engine/imap/api/imap-client-service.vala
@@ -397,7 +397,7 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
             // honor Cancellable here, it's important to disconnect
             // the client before dropping the ref
             try {
-                yield new_session.disconnect_async();
+                yield new_session.disconnect_async(null);
             } catch (Error disconnect_err) {
                 debug("[%s] Error disconnecting due to session initiation failure, ignored: %s",
                     new_session.to_string(), disconnect_err.message);
@@ -436,7 +436,7 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
         // waiting for any since we don't want to delay closing the
         // others.
         foreach (ClientSession session in to_close) {
-            session.disconnect_async.begin();
+            session.disconnect_async.begin(null);
         }
     }
 
@@ -452,7 +452,7 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
 
         // Don't wait for this to finish because we don't want to
         // block claiming a new session, shutdown, etc.
-        session.disconnect_async.begin();
+        session.disconnect_async.begin(null);
     }
 
     private async bool remove_session_async(ClientSession session) throws Error {
diff --git a/src/engine/imap/transport/imap-client-session.vala 
b/src/engine/imap/transport/imap-client-session.vala
index 8ef5755b..76801cf2 100644
--- a/src/engine/imap/transport/imap-client-session.vala
+++ b/src/engine/imap/transport/imap-client-session.vala
@@ -674,7 +674,8 @@ public class Geary.Imap.ClientSession : BaseObject {
      * even if the error was from the server (that is, not a network problem).  The
      * {@link ClientSession} should be discarded.
      */
-    public async void connect_async(Cancellable? cancellable = null) throws Error {
+    public async void connect_async(GLib.Cancellable? cancellable)
+        throws GLib.Error {
         MachineParams params = new MachineParams(null);
         fsm.issue(Event.CONNECT, null, params);
         
@@ -837,8 +838,8 @@ public class Geary.Imap.ClientSession : BaseObject {
      * @see initiate_session_async
      */
     public async StatusResponse login_async(Geary.Credentials credentials,
-                                            Cancellable? cancellable = null)
-        throws Error {
+                                            GLib.Cancellable? cancellable)
+        throws GLib.Error {
         Command? cmd = null;
         switch (credentials.supported_method) {
         case Geary.Credentials.Method.PASSWORD:
@@ -914,11 +915,12 @@ public class Geary.Imap.ClientSession : BaseObject {
      * {@link Capabilities} are also retrieved automatically at the right time to ensure the best
      * results are available with {@link capabilities}.
      */
-    public async void initiate_session_async(Geary.Credentials credentials, Cancellable? cancellable = null)
-        throws Error {
+    public async void initiate_session_async(Geary.Credentials credentials,
+                                             GLib.Cancellable? cancellable)
+        throws GLib.Error {
         // If no capabilities available, get them now
         if (capabilities.is_empty())
-            yield send_command_async(new CapabilityCommand());
+            yield send_command_async(new CapabilityCommand(), cancellable);
 
         // store them for comparison later
         Imap.Capabilities caps = capabilities;
@@ -932,7 +934,9 @@ public class Geary.Imap.ClientSession : BaseObject {
             debug("[%s] Attempting STARTTLS...", to_string());
             StatusResponse resp;
             try {
-                resp = yield send_command_async(new StarttlsCommand());
+                resp = yield send_command_async(
+                    new StarttlsCommand(), cancellable
+                );
             } catch (Error err) {
                 debug(
                     "Error attempting STARTTLS command on %s: %s",
@@ -962,9 +966,10 @@ public class Geary.Imap.ClientSession : BaseObject {
         yield login_async(credentials, cancellable);
 
         // if new capabilities not offered after login, get them now
-        if (caps.revision == capabilities.revision)
-            yield send_command_async(new CapabilityCommand());
-        
+        if (caps.revision == capabilities.revision) {
+            yield send_command_async(new CapabilityCommand(), cancellable);
+        }
+
         // either way, new capabilities should be available
         caps = capabilities;
 
@@ -1216,11 +1221,12 @@ public class Geary.Imap.ClientSession : BaseObject {
     //
     // send commands
     //
-    
-    public async StatusResponse send_command_async(Command cmd, Cancellable? cancellable = null) 
-        throws Error {
+
+    public async StatusResponse send_command_async(Command cmd,
+                                                   GLib.Cancellable? cancellable)
+        throws GLib.Error {
         check_unsupported_send_command(cmd);
-        
+
         MachineParams params = new MachineParams(cmd);
         fsm.issue(Event.SEND_CMD, null, params);
         
@@ -1231,12 +1237,14 @@ public class Geary.Imap.ClientSession : BaseObject {
         
         return yield command_transaction_async(cmd, cancellable);
     }
-    
-    public async Gee.Map<Command, StatusResponse> send_multiple_commands_async(
-        Gee.Collection<Command> cmds, Cancellable? cancellable = null) throws Error {
+
+    public async Gee.Map<Command, StatusResponse>
+        send_multiple_commands_async(Gee.Collection<Command> cmds,
+                                     GLib.Cancellable? cancellable)
+        throws GLib.Error {
         if (cmds.size == 0)
             throw new ImapError.INVALID("Must supply at least one command");
-        
+
         foreach (Command cmd in cmds)
             check_unsupported_send_command(cmd);
         
@@ -1335,19 +1343,23 @@ public class Geary.Imap.ClientSession : BaseObject {
     //
     // select/examine
     //
-    
-    public async StatusResponse select_async(MailboxSpecifier mailbox, Cancellable? cancellable = null) 
-        throws Error {
+
+    public async StatusResponse select_async(MailboxSpecifier mailbox,
+                                             GLib.Cancellable? cancellable)
+        throws GLib.Error {
         return yield select_examine_async(mailbox, true, cancellable);
     }
-    
-    public async StatusResponse examine_async(MailboxSpecifier mailbox, Cancellable? cancellable = null)
-        throws Error {
+
+    public async StatusResponse examine_async(MailboxSpecifier mailbox,
+                                              GLib.Cancellable? cancellable)
+        throws GLib.Error {
         return yield select_examine_async(mailbox, false, cancellable);
     }
-    
-    public async StatusResponse select_examine_async(MailboxSpecifier mailbox, bool is_select,
-        Cancellable? cancellable) throws Error {
+
+    public async StatusResponse select_examine_async(MailboxSpecifier mailbox,
+                                                     bool is_select,
+                                                     GLib.Cancellable? cancellable)
+        throws GLib.Error {
         // Ternary troubles
         Command cmd;
         if (is_select)
@@ -1431,10 +1443,11 @@ public class Geary.Imap.ClientSession : BaseObject {
     //
     // close mailbox
     //
-    
-    public async StatusResponse close_mailbox_async(Cancellable? cancellable = null) throws Error {
+
+    public async StatusResponse close_mailbox_async(GLib.Cancellable? cancellable)
+        throws GLib.Error {
         CloseCommand cmd = new CloseCommand();
-        
+
         MachineParams params = new MachineParams(cmd);
         fsm.issue(Event.CLOSE_MAILBOX, null, params);
         
@@ -1487,10 +1500,11 @@ public class Geary.Imap.ClientSession : BaseObject {
     //
     // logout
     //
-    
-    public async void logout_async(Cancellable? cancellable = null) throws Error {
+
+    public async void logout_async(GLib.Cancellable? cancellable)
+        throws GLib.Error {
         LogoutCommand cmd = new LogoutCommand();
-        
+
         MachineParams params = new MachineParams(cmd);
         fsm.issue(Event.LOGOUT, null, params);
         
@@ -1528,8 +1542,9 @@ public class Geary.Imap.ClientSession : BaseObject {
     //
     // disconnect
     //
-    
-    public async void disconnect_async(Cancellable? cancellable = null) throws Error {
+
+    public async void disconnect_async(GLib.Cancellable? cancellable)
+        throws GLib.Error {
         MachineParams params = new MachineParams(null);
         fsm.issue(Event.DISCONNECT, null, params);
         


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