aboutsummaryrefslogtreecommitdiffstats
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
parentc9f687e0c16a7f6ea6471f69b6be8cb2f0a3268d (diff)
downloadpacredir-b99ca309bc5fce1749c33c1f6d647ae36ee881dc.tar.gz
pacredir-b99ca309bc5fce1749c33c1f6d647ae36ee881dc.tar.zst
try to guess the fastest server for packages
-rw-r--r--pacredir.c16
-rw-r--r--pacredir.h2
2 files changed, 16 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);
diff --git a/pacredir.h b/pacredir.h
index 2b1a1c1..da64464 100644
--- a/pacredir.h
+++ b/pacredir.h
@@ -49,6 +49,8 @@ struct request {
char * url;
/* HTTP status code */
long http_code;
+ /* total connection time */
+ double time_total;
/* last modified timestamp */
long last_modified;
};