diff options
| author | Nakidai <nakidai@disroot.org> | 2024-09-28 16:09:14 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2024-09-28 16:09:14 +0300 |
| commit | d3046284b23ca81be438c94e8f83b7e13e929d81 (patch) | |
| tree | 541a2de8cf543eee4abd99e6916e3169672f8cea /requestHandler.c | |
| parent | ffa61b7b6930fe4a08bb53ace07c2ee40a9cef43 (diff) | |
| download | cptc-d3046284b23ca81be438c94e8f83b7e13e929d81.tar.gz cptc-d3046284b23ca81be438c94e8f83b7e13e929d81.zip | |
Make it multithreaded v1.0.0
And also add `int n` to the CPTC_requestHandler so it threads will not conflict with each other with filenames
Diffstat (limited to 'requestHandler.c')
| -rw-r--r-- | requestHandler.c | 10 |
1 files changed, 5 insertions, 5 deletions
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); |