Compare commits

..
2 Commits
16 .. 18
Author SHA1 Message Date
Arjan van de Ven 66bab25bcd implement multi-url setup 2015-03-23 14:45:00 -04:00
Arjan van de Ven 49ac392f01 move logging up 2015-03-23 14:37:26 -04:00
+14 -6
View File
@@ -43,6 +43,9 @@
GStaticMutex dupes_mutex = G_STATIC_MUTEX_INIT;
char *urls[2] = {"http://debuginfo.clearlinux.org/debuginfo/", "http://debuginfo.fenrus.org/debuginfo/" };
int urlcounter = 0;
static GHashTable *hash;
@@ -119,6 +122,9 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
fflush(file);
// printf("HTTP return code is %i\n", ret);
if (ret != 200 && ret != 404)
urlcounter++;
if (ret == 200) {
char *command = NULL;
// printf("Filename is %s\n", filename);
@@ -197,7 +203,7 @@ static void *server_thread(void *arg)
return NULL;
}
url = NULL;
if (asprintf(&url, "http://debuginfo.clearlinux.org/debuginfo/%s%s.tar", prefix, path) < 0) {
if (asprintf(&url, "%s%s%s.tar", urls[urlcounter % 2], prefix, path) < 0) {
close(fd);
return NULL;
}
@@ -205,17 +211,19 @@ static void *server_thread(void *arg)
// printf("Getting url %s %i:%06i\n", url, before.tv_sec, before.tv_usec);
ret = curl_get_file(url, prefix, timestamp);
/* tell the other side we're done with the download */
write(fd, "ok", 3);
close(fd);
if (ret != 200)
printf("Request for %s resulted in error %i\n", url, ret);
gettimeofday(&after, NULL);
if (timedelta(before, after) > 0.6)
printf("Request for %s took %5.2f seconds (%i - %i)\n", url,
after.tv_sec - before.tv_sec + (1.0*after.tv_usec - before.tv_usec) / 1000000.0, ret, (int)timestamp);
/* tell the other side we're done with the download */
write(fd, "ok", 3);
close(fd);
if (ret != 200)
printf("Request for %s resulted in error %i\n", url, ret);
free(url);
return NULL;
}