removed log code again

This commit is contained in:
2025-10-18 13:31:19 +02:00
parent f4496c7fda
commit 12121e8b3e

View File

@@ -4,37 +4,14 @@
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdatomic.h>
/* #include <stdatomic.h>
#include <time.h>
#include <pthread.h>
#include <pthread.h> */
#define PORT 6008
#define BACKLOG 16
#define RECV_BUF 256
atomic_ullong request_count = 0;
void *logger_thread(void *arg) {
(void)arg;
while (1) {
sleep(24 * 60 * 60); // 1 day
unsigned long long count = atomic_exchange(&request_count, 0);
FILE *f = fopen("requests.log", "a");
if (!f) continue;
time_t now = time(NULL);
struct tm *tm = localtime(&now);
char ts[64];
strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S", tm);
fprintf(f, "%s | %llu requests served\n", ts, count);
fclose(f);
}
return NULL;
}
int main() {
int server_fd = socket(AF_INET, SOCK_STREAM, 0);
int opt = 1;
@@ -50,11 +27,6 @@ int main() {
printf("listening port %d\nbacklog %d\nrecv buffer %d\n", PORT, BACKLOG, RECV_BUF);
//add logger thread
pthread_t logger;
pthread_create(&logger, NULL, logger_thread, NULL);
pthread_detach(logger);
char buf[RECV_BUF];
const char *hdr = "X-Forwarded-For:";
const size_t hdrlen = strlen(hdr);
@@ -65,7 +37,6 @@ int main() {
ssize_t r = recv(client, buf, sizeof(buf) -1, 0);
if (r <= 0) { close(client); continue; }
buf[r] = 0;
atomic_fetch_add(&request_count, 1);
//find header
char *ip = NULL;
for (ssize_t i = 0; i < r - (ssize_t)hdrlen; ++i) {
@@ -91,7 +62,6 @@ int main() {
send(client, head, strlen(head), 0);
send(client, lenbuf, len, 0);
if (iplen > 0) send(client, ip, iplen, 0);
close(client);
}