Compare commits

..
6 Commits
14 .. 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
Arjan van de Ven 71f4e789c4 better logging 2015-03-23 14:17:30 -04:00
Arjan van de Ven f776162882 few more checks 2015-03-23 14:15:42 -04:00
Arjan van de Ven a2abd8d2a9 put memory optimizations back 2015-03-23 14:12:31 -04:00
Arjan van de Ven 8844b0b0e1 Revert "Wait with curl init until the first connection comes in"
This reverts commit 6fb3c6f193.
2015-03-05 18:00:06 -05:00
+18 -5
View File
@@ -36,12 +36,16 @@
#include <string.h> #include <string.h>
#include <pthread.h> #include <pthread.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <malloc.h>
#include <curl/curl.h> #include <curl/curl.h>
#include <glib.h> #include <glib.h>
GStaticMutex dupes_mutex = G_STATIC_MUTEX_INIT; 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; static GHashTable *hash;
@@ -118,6 +122,9 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
fflush(file); fflush(file);
// printf("HTTP return code is %i\n", ret); // printf("HTTP return code is %i\n", ret);
if (ret != 200 && ret != 404)
urlcounter++;
if (ret == 200) { if (ret == 200) {
char *command = NULL; char *command = NULL;
// printf("Filename is %s\n", filename); // printf("Filename is %s\n", filename);
@@ -185,7 +192,7 @@ static void *server_thread(void *arg)
path++; path++;
if (strstr(path, "..") || strstr(prefix, "..")) { if (strstr(path, "..") || strstr(prefix, "..") || strstr(path, "'") || strstr(path, ";")) {
close(fd); close(fd);
return NULL; return NULL;
} }
@@ -196,7 +203,7 @@ static void *server_thread(void *arg)
return NULL; return NULL;
} }
url = 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); close(fd);
return NULL; return NULL;
} }
@@ -204,14 +211,19 @@ static void *server_thread(void *arg)
// printf("Getting url %s %i:%06i\n", url, before.tv_sec, before.tv_usec); // printf("Getting url %s %i:%06i\n", url, before.tv_sec, before.tv_usec);
ret = curl_get_file(url, prefix, timestamp); ret = curl_get_file(url, prefix, timestamp);
/* tell the other side we're done with the download */ if (ret != 200)
write(fd, "ok", 3); printf("Request for %s resulted in error %i\n", url, ret);
close(fd);
gettimeofday(&after, NULL); gettimeofday(&after, NULL);
if (timedelta(before, after) > 0.6) if (timedelta(before, after) > 0.6)
printf("Request for %s took %5.2f seconds (%i - %i)\n", url, 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); 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);
free(url); free(url);
return NULL; return NULL;
} }
@@ -259,6 +271,7 @@ int main(int argc, char **argv)
int clientsock; int clientsock;
pthread_t thread; pthread_t thread;
malloc_trim(0);
clientsock = accept(sockfd, NULL, NULL); clientsock = accept(sockfd, NULL, NULL);
if (!curl_done) { if (!curl_done) {