]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dict-client: Remove timeout when there are only background commands.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 26 Sep 2016 13:34:23 +0000 (16:34 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 13 Oct 2016 08:15:42 +0000 (10:15 +0200)
Normally the timeout wasn't added in the first place, but it was if a
non-background command was added first and it was followed by a background
command.

src/lib-dict/dict-client.c

index 8562b359fa6b6a05aa6276d95d4655ba6e3c11ef..3d6a7c7ee626887eab1230b9ca177537bf57f359 100644 (file)
@@ -342,6 +342,17 @@ static void client_dict_timeout(struct client_dict *dict)
                client_dict_disconnect(dict, "Idle disconnection");
 }
 
+static bool client_dict_have_nonbackground_cmds(struct client_dict *dict)
+{
+       struct client_dict_cmd *const *cmdp;
+
+       array_foreach(&dict->cmds, cmdp) {
+               if (!(*cmdp)->background)
+                       return TRUE;
+       }
+       return FALSE;
+}
+
 static void client_dict_add_timeout(struct client_dict *dict)
 {
        if (dict->to_idle != NULL) {
@@ -352,22 +363,25 @@ static void client_dict_add_timeout(struct client_dict *dict)
                                            client_dict_timeout, dict);
                if (dict->to_requests != NULL)
                        timeout_remove(&dict->to_requests);
+       } else if (dict->transactions == NULL &&
+                  !client_dict_have_nonbackground_cmds(dict)) {
+               /* we had non-background commands, but now we're back to
+                  having only background commands. remove timeouts. */
+               if (dict->to_requests != NULL)
+                       timeout_remove(&dict->to_requests);
        }
 }
 
 static void client_dict_cmd_backgrounded(struct client_dict *dict)
 {
-       struct client_dict_cmd *const *cmdp;
-
        if (dict->to_requests == NULL)
                return;
 
-       array_foreach(&dict->cmds, cmdp) {
-               if (!(*cmdp)->background)
-                       return;
+       if (!client_dict_have_nonbackground_cmds(dict)) {
+               /* we only have background-commands.
+                  remove the request timeout. */
+               timeout_remove(&dict->to_requests);
        }
-       /* we only have background-commands. remove the request timeout. */
-       timeout_remove(&dict->to_requests);
 }
 
 static int dict_conn_input_line(struct connection *_conn, const char *line)