]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: client: Moved connection backoff timer management to separate functions.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Fri, 16 Dec 2016 21:00:47 +0000 (22:00 +0100)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Sat, 17 Dec 2016 18:42:59 +0000 (19:42 +0100)
src/lib-http/http-client-peer.c

index 9492289a2c93fbe5464581351b7a834045b1f644..3813bb5a1bd040de6c2c2820c8060f8367000aa7 100644 (file)
@@ -182,6 +182,28 @@ http_client_peer_start_backoff_timer(struct http_client_peer *peer)
        return FALSE;
 }
 
+static void
+http_client_peer_increase_backoff_timer(struct http_client_peer *peer)
+{
+       const struct http_client_settings *set = &peer->client->set;
+
+       if (peer->backoff_time_msecs == 0)
+               peer->backoff_time_msecs = set->connect_backoff_time_msecs;
+       else
+               peer->backoff_time_msecs *= 2;
+       if (peer->backoff_time_msecs > set->connect_backoff_max_time_msecs)
+               peer->backoff_time_msecs = set->connect_backoff_max_time_msecs;
+}
+
+static void
+http_client_peer_reset_backoff_timer(struct http_client_peer *peer)
+{
+       peer->backoff_time_msecs = 0;
+
+       if (peer->to_backoff != NULL)
+               timeout_remove(&peer->to_backoff);
+}
+
 static void
 http_client_peer_connect(struct http_client_peer *peer, unsigned int count)
 {
@@ -745,10 +767,7 @@ void http_client_peer_connection_success(struct http_client_peer *peer)
                array_count(&peer->conns));
 
        peer->last_failure.tv_sec = peer->last_failure.tv_usec = 0;
-       peer->backoff_time_msecs = 0;
-
-       if (peer->to_backoff != NULL)
-               timeout_remove(&peer->to_backoff);
+       http_client_peer_reset_backoff_timer(peer);
 
        array_foreach(&peer->queues, queue) {
                http_client_queue_connection_success(*queue, &peer->addr);
@@ -760,7 +779,6 @@ void http_client_peer_connection_success(struct http_client_peer *peer)
 void http_client_peer_connection_failure(struct http_client_peer *peer,
                                         const char *reason)
 {
-       const struct http_client_settings *set = &peer->client->set;
        struct http_client_queue *const *queue;
        unsigned int pending;
 
@@ -776,14 +794,8 @@ void http_client_peer_connection_failure(struct http_client_peer *peer,
                array_count(&peer->conns), pending);
 
        /* manage backoff timer only when this was the only attempt */
-       if (pending == 1) {
-               if (peer->backoff_time_msecs == 0)
-                       peer->backoff_time_msecs = set->connect_backoff_time_msecs;
-               else
-                       peer->backoff_time_msecs *= 2;
-               if (peer->backoff_time_msecs > set->connect_backoff_max_time_msecs)
-                       peer->backoff_time_msecs = set->connect_backoff_max_time_msecs;
-       }
+       if (pending == 1)
+               http_client_peer_increase_backoff_timer(peer);
 
        if (pending > 1) {
                /* if there are other connections attempting to connect, wait