]> 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>
Mon, 26 Sep 2016 13:37:35 +0000 (16:37 +0300)
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 900e4465d482a528dd21edfb37e138e165eacf96..f99bac318d75e1d18fec0515cdf2a261c9cb2610 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)