summaryrefslogtreecommitdiffstats
path: root/pacredir.c
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2014-01-13 08:24:15 +0100
committerGravatar Christian Hesse <mail@eworm.de>2014-01-13 08:24:15 +0100
commitb99ca309bc5fce1749c33c1f6d647ae36ee881dc (patch)
tree4cc583257a14f43aed19364cb1a76513d94947e4 /pacredir.c
parentc9f687e0c16a7f6ea6471f69b6be8cb2f0a3268d (diff)
downloadpaccache-b99ca309bc5fce1749c33c1f6d647ae36ee881dc.tar.gz
paccache-b99ca309bc5fce1749c33c1f6d647ae36ee881dc.tar.zst
try to guess the fastest server for packages
Diffstat (limited to 'pacredir.c')
-rw-r--r--pacredir.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/pacredir.c b/pacredir.c
index 99b000e..a148257 100644
--- a/pacredir.c
+++ b/pacredir.c
@@ -264,6 +264,11 @@ static void * get_http_code(void * data) {
return NULL;
}
+ if ((res = curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &(request->time_total))) != CURLE_OK) {
+ write_log(stderr, "curl_easy_getinfo() failed: %s\n", curl_easy_strerror(res));
+ return NULL;
+ }
+
/* get last modified time */
if (request->http_code == MHD_HTTP_OK) {
if ((res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &(request->last_modified))) != CURLE_OK) {
@@ -301,6 +306,7 @@ static int ahc_echo(void * cls, struct MHD_Connection * connection, const char *
struct request ** requests = NULL;
struct request * request = NULL;
long http_code = 0, last_modified = 0;
+ double time_total = INFINITY;
/* we want the filename, not the path */
basename = uri;
@@ -390,14 +396,20 @@ static int ahc_echo(void * cls, struct MHD_Connection * connection, const char *
request = requests[i];
+ if (request->http_code == MHD_HTTP_OK)
+ printf("Found: %s (%f sec)\n", request->url, request->time_total);
+
if (request->http_code == MHD_HTTP_OK &&
- (dbfile == 0 || request->last_modified > last_modified)) {
- printf("Found: %s\n", request->url);
+ /* for db files choose the most recent server */
+ ((dbfile == 1 && request->last_modified > last_modified) ||
+ /* for packages try to guess the fastest server */
+ (dbfile == 0 && request->time_total < time_total))) {
if (url != NULL)
free(url);
url = request->url;
http_code = MHD_HTTP_OK;
last_modified = request->last_modified;
+ time_total = request->time_total;
} else
free(request->url);
free(request);