Skip to content

Commit

Permalink
dict-client: Remove timeout when there are only background commands.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sirainen committed Sep 26, 2016
1 parent 666d85f commit 9fa33a0
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/lib-dict/dict-client.c
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down

0 comments on commit 9fa33a0

Please sign in to comment.