New ConnectionTimeout variable sets the amount of time trying to connect
to a repository, before timing out and trying the next one.

Signed-off-by: Nathan Aclander <[email protected]>
---
 doc/pacman.conf.5.asciidoc | 3 +++
 etc/pacman.conf.in         | 1 +
 lib/libalpm/alpm.h         | 3 +++
 lib/libalpm/dload.c        | 2 +-
 lib/libalpm/handle.c       | 7 +++++++
 lib/libalpm/handle.h       | 1 +
 src/pacman/conf.c          | 7 +++++++
 src/pacman/conf.h          | 1 +
 8 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/doc/pacman.conf.5.asciidoc b/doc/pacman.conf.5.asciidoc
index b297e332..dee5139e 100644
--- a/doc/pacman.conf.5.asciidoc
+++ b/doc/pacman.conf.5.asciidoc
@@ -205,6 +205,9 @@ Options
        Disable defaults for low speed limit and timeout on downloads. Use this
        if you have issues downloading files with proxy and/or security gateway.
 
+*ConnectionTimeout*::
+       Set the amount of time trying to connect to a repository, before timnig
+       out and trying the next one.
 
 Repository Sections
 -------------------
diff --git a/etc/pacman.conf.in b/etc/pacman.conf.in
index 7446944f..899ad18f 100644
--- a/etc/pacman.conf.in
+++ b/etc/pacman.conf.in
@@ -34,6 +34,7 @@ Architecture = auto
 #TotalDownload
 CheckSpace
 #VerbosePkgLists
+#ConnectionTimeout = 10
 
 # PGP signature checking
 #SigLevel = Optional
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index ffb2ad96..e0bf12ca 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -890,6 +890,9 @@ int alpm_option_set_remote_file_siglevel(alpm_handle_t 
*handle, int level);
 
 int alpm_option_set_disable_dl_timeout(alpm_handle_t *handle, unsigned short 
disable_dl_timeout);
 
+/** Sets the timeout for the curl connect phase. */
+int alpm_option_set_connecttimeout(alpm_handle_t *handle, unsigned int 
timeout);
+
 /** @} */
 
 /** @addtogroup alpm_api_databases Database Functions
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 05813c40..4e0703b4 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -258,7 +258,7 @@ static void curl_set_handle_opts(struct dload_payload 
*payload,
        curl_easy_reset(curl);
        curl_easy_setopt(curl, CURLOPT_URL, payload->fileurl);
        curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer);
-       curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
+       curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, handle->connecttimeout);
        curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 10L);
        curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
        curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index 476779c4..92bc9038 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -556,6 +556,13 @@ int SYMEXPORT alpm_option_set_usesyslog(alpm_handle_t 
*handle, int usesyslog)
        return 0;
 }
 
+int SYMEXPORT alpm_option_set_connecttimeout(alpm_handle_t *handle, unsigned 
int timeout)
+{
+       CHECK_HANDLE(handle, return -1);
+       handle->connecttimeout = timeout;
+       return 0;
+}
+
 static int _alpm_option_strlist_add(alpm_handle_t *handle, alpm_list_t **list, 
const char *str)
 {
        char *dup;
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index 14d20bbe..9defbc1b 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -103,6 +103,7 @@ struct __alpm_handle_t {
                                               upgrade operations */
        int remotefilesiglevel;  /* Signature verification level for remote file
                                               upgrade operations */
+       unsigned int connecttimeout; /* timeout for the connect phase  */
 
        /* error code */
        alpm_errno_t pm_errno;
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 3b79fbc7..2cdc157e 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -513,6 +513,8 @@ static int _parse_options(const char *key, char *value,
                        setrepeatingoption(value, "IgnoreGroup", 
&(config->ignoregrp));
                } else if(strcmp(key, "HoldPkg") == 0) {
                        setrepeatingoption(value, "HoldPkg", 
&(config->holdpkg));
+               } else if(strcmp(key, "ConnectionTimeout") == 0) {
+                       config->connecttimeout = atoi(value);
                } else if(strcmp(key, "CacheDir") == 0) {
                        setrepeatingoption(value, "CacheDir", 
&(config->cachedirs));
                } else if(strcmp(key, "HookDir") == 0) {
@@ -739,6 +741,10 @@ static int setup_libalpm(void)
                alpm_option_set_totaldlcb(handle, cb_dl_total);
        }
 
+       if(!config->connecttimeout) {
+               alpm_option_set_connecttimeout(handle, 10L);
+       }
+
        alpm_option_set_arch(handle, config->arch);
        alpm_option_set_checkspace(handle, config->checkspace);
        alpm_option_set_usesyslog(handle, config->usesyslog);
@@ -749,6 +755,7 @@ static int setup_libalpm(void)
        alpm_option_set_noextracts(handle, config->noextract);
 
        alpm_option_set_disable_dl_timeout(handle, config->disable_dl_timeout);
+       alpm_option_set_connecttimeout(handle, config->connecttimeout);
 
        for(i = config->assumeinstalled; i; i = i->next) {
                char *entry = i->data;
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index f45ed436..e1f9934e 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -118,6 +118,7 @@ typedef struct __config_t {
        /* select -Sc behavior */
        unsigned short cleanmethod;
        alpm_list_t *holdpkg;
+       unsigned int connecttimeout;
        alpm_list_t *ignorepkg;
        alpm_list_t *ignoregrp;
        alpm_list_t *assumeinstalled;
-- 
2.21.0

Reply via email to