From d3046284b23ca81be438c94e8f83b7e13e929d81 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Sat, 28 Sep 2024 16:09:14 +0300 Subject: Make it multithreaded And also add `int n` to the CPTC_requestHandler so it threads will not conflict with each other with filenames --- requestHandler.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'requestHandler.c') diff --git a/requestHandler.c b/requestHandler.c index 68442f0..6e4a691 100644 --- a/requestHandler.c +++ b/requestHandler.c @@ -23,15 +23,15 @@ static bool isnumber(const char *s) return true; } -static char *generate_filename(char *buf, size_t size, const char *ext) +static char *generate_filename(char *buf, size_t size, const char *ext, int n) { struct timespec tp; clock_gettime(CLOCK_REALTIME, &tp); - snprintf(buf, size, "/tmp/%lld.%s", tp.tv_sec * 1000000000LL + tp.tv_nsec, ext); + snprintf(buf, size, "/tmp/%d-%lld.%s", n, tp.tv_sec * 1000000000LL + tp.tv_nsec, ext); return buf; } -void CPTC_requestHandler(int fd) +void CPTC_requestHandler(int fd, int n) { enum CPTC_Method method; int ch; @@ -83,7 +83,7 @@ void CPTC_requestHandler(int fd) char *length = malloc(sizeof(*length) * 32); *strchr(path, '.') = '\0'; - generate_filename(filenamebuf, sizeof(filenamebuf), "png"); + generate_filename(filenamebuf, sizeof(filenamebuf), "png", n); char *in = CPTC_downloadAvatar(atoll(path + 1), filenamebuf); if (!in) { @@ -92,7 +92,7 @@ void CPTC_requestHandler(int fd) send(fd, response, strlen(response), 0); return; } - generate_filename(filenamebuf, sizeof(filenamebuf), "gif"); + generate_filename(filenamebuf, sizeof(filenamebuf), "gif", n); CPetPet(in, filenamebuf, 2); printf("From %s to %s\n", in, filenamebuf); -- cgit 1.4.1