]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add connection_client_connect_with_retries()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 5 Jan 2022 21:46:12 +0000 (23:46 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 8 Feb 2022 09:48:24 +0000 (10:48 +0100)
src/lib/connection.c
src/lib/connection.h

index 638c28ce2b1a94e3f9064e1fcaf3c467891abd6a..e540f6187120adc640e1328ae7c6e870906251f2 100644 (file)
@@ -695,7 +695,8 @@ static void connection_socket_connected(struct connection *conn)
        connection_client_connected(conn, errno == 0);
 }
 
-int connection_client_connect(struct connection *conn)
+int connection_client_connect_with_retries(struct connection *conn,
+                                          unsigned int msecs)
 {
        const struct connection_settings *set = &conn->list->set;
        int fd;
@@ -709,12 +710,10 @@ int connection_client_connect(struct connection *conn)
                fd = net_connect_ip(&conn->remote_ip, conn->remote_port,
                                    (conn->local_ip.family != 0 ?
                                     &conn->local_ip : NULL));
-       } else if (conn->list->set.unix_client_connect_msecs == 0) {
+       } else if (msecs == 0) {
                fd = net_connect_unix(conn->base_name);
        } else {
-               fd = net_connect_unix_with_retries(
-                       conn->base_name,
-                       conn->list->set.unix_client_connect_msecs);
+               fd = net_connect_unix_with_retries(conn->base_name, msecs);
        }
        if (fd == -1)
                return -1;
@@ -741,6 +740,12 @@ int connection_client_connect(struct connection *conn)
        return 0;
 }
 
+int connection_client_connect(struct connection *conn)
+{
+       return connection_client_connect_with_retries(conn,
+               conn->list->set.unix_client_connect_msecs);
+}
+
 static void connection_update_counters(struct connection *conn)
 {
        if (conn->input != NULL)
index efe82808e9712d0279fd3057916df538c7d7d0e0..398637cfdec9581e1f799508b5cca2f57f78695d 100644 (file)
@@ -201,6 +201,10 @@ void connection_init_from_streams(struct connection_list *list,
                                  struct ostream *output) ATTR_NULL(3);
 
 int connection_client_connect(struct connection *conn);
+/* Connect to UNIX socket. If it fails, try it up to msecs is reached.
+   Overrides connection_settings.unix_client_connect_msecs. */
+int connection_client_connect_with_retries(struct connection *conn,
+                                          unsigned int msecs);
 
 /* Disconnects a connection */
 void connection_disconnect(struct connection *conn);