From 801785cbab4c9dcbf6af36469f7ed5581ef4c2b3 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 24 Jan 2010 15:48:29 +0100 Subject: [PATCH] Add xbps_fetch_set_cache_connection() to set libfetch's cache connection limits. Use it in xbps_fetch_file(), by default set with 8 and 16. --HG-- extra : convert_revision : xtraeme%40gmail.com-20100124144829-hqsr2bl6uflf0nhu --- include/xbps_api.h | 8 ++++++++ lib/download.c | 26 ++++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/include/xbps_api.h b/include/xbps_api.h index aa814799..391cb4e6 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -234,6 +234,14 @@ int xbps_fetch_file(const char *uri, bool refetch, const char *flags); +/** + * Sets the libfetch's cache connection limits. + * + * @param[in] global Number of global cached connections, by default 8. + * @param[in] per_host Number of per host cached connections, by default 16. + */ +void xbps_fetch_set_cache_connection(int global, int per_host); + /** * Returns last error string reported by xbps_fetch_file(). * diff --git a/lib/download.c b/lib/download.c index e8ee9205..b34c5570 100644 --- a/lib/download.c +++ b/lib/download.c @@ -58,6 +58,9 @@ struct xferstat { const char *name; }; +static int cache_connections = 8; +static int cache_connections_host = 16; + /* * Compute and display ETA */ @@ -171,12 +174,6 @@ stat_end(struct xferstat *xsp) fprintf(stderr, "\033[K\n"); } -const char * -xbps_fetch_error_string(void) -{ - return fetchLastErrString; -} - #ifdef DEBUG static const char * print_time(time_t *t) @@ -190,6 +187,23 @@ print_time(time_t *t) } #endif +const char * +xbps_fetch_error_string(void) +{ + return fetchLastErrString; +} + +void +xbps_fetch_set_cache_connection(int global, int per_host) +{ + if (global == 0) + global = cache_connections; + if (per_host == 0) + per_host = cache_connections_host; + + fetchConnectionCacheInit(global, per_host); +} + int xbps_fetch_file(const char *uri, const char *outputdir, bool refetch, const char *flags)