]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Fixed io_loop_move_timeout() to retain the next_run time, so that the timeout...
authorStephan Bosch <stephan@rename-it.nl>
Sat, 4 Oct 2014 14:31:38 +0000 (17:31 +0300)
committerStephan Bosch <stephan@rename-it.nl>
Sat, 4 Oct 2014 14:31:38 +0000 (17:31 +0300)
This problem became with timeout_add_absolute(), since resetting an
absolute timeout causes it to fire immediately (msecs == 0).

src/lib/ioloop.c

index a58ce0182ec760a5bd15d129eab81b5cf633b724..d5a014f4dd6b67b3192c88439823162e8d4851b5 100644 (file)
@@ -254,6 +254,21 @@ timeout_add_absolute(const struct timeval *time,
        return timeout;
 }
 
+static struct timeout *
+timeout_copy(const struct timeout *old_to)
+{
+       struct timeout *new_to;
+
+       new_to = timeout_add_common
+               (old_to->source_linenum, old_to->callback, old_to->context);
+       new_to->one_shot = old_to->one_shot;
+       new_to->msecs = old_to->msecs;
+       new_to->next_run = old_to->next_run;
+       priorityq_add(new_to->ioloop->timeouts, &new_to->item);
+
+       return new_to;
+}
+
 static void timeout_free(struct timeout *timeout)
 {
        if (timeout->ctx != NULL)
@@ -829,8 +844,7 @@ struct timeout *io_loop_move_timeout(struct timeout **_timeout)
        if (old_to->ioloop == current_ioloop)
                return old_to;
 
-       new_to = timeout_add(old_to->msecs, old_to->source_linenum,
-                            old_to->callback, old_to->context);
+       new_to = timeout_copy(old_to);
        timeout_remove(_timeout);
        return new_to;
 }