aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;
};