Half time

This commit is contained in:
Ano-sys
2025-02-02 18:43:19 +01:00
parent 02c31d009e
commit c370a35d98
29 changed files with 28782 additions and 145 deletions
+23 -1
View File
@@ -299,6 +299,22 @@ char *sanitize_input(char *input){
return ret;
}
void fucking_string_empty(void *context, char **worker_ports){
THREAD_ARGS *args = malloc(sizeof(THREAD_ARGS));
if(!args){
// perror("[MAIN - fucking_string_empty] Failed to allocate memory for args");
return;
}
args->context = context;
args->port = atol(*worker_ports);
args->type = MAP;
args->data = strdup("");
pthread_t thread;
pthread_create(&thread, NULL, receiverFunc, args);
pthread_join(thread, NULL);
}
void map(size_t worker_count, char **worker_ports, const char *filename, void *context) {
FILE *fp = fopen(filename, "rb");
char *raw = get_file_content(fp);
@@ -320,6 +336,12 @@ void map(size_t worker_count, char **worker_ports, const char *filename, void *c
exit(1);
}
if(strcmp(content, "") == 0){
fucking_string_empty(context, worker_ports);
free(content);
return;
}
size_t max_threads = worker_count * 2;
pthread_t *threads = malloc(sizeof(pthread_t) * max_threads);
if (!threads) {
@@ -335,7 +357,7 @@ void map(size_t worker_count, char **worker_ports, const char *filename, void *c
size_t total_len = strlen(content);
size_t offset = 0;
while (offset < total_len || (offset == 0 && total_len == 0)) {
while (offset < total_len) {
size_t chunk_size = (total_len - offset >= PAYLOAD_LENGTH) ? PAYLOAD_LENGTH : (total_len - offset);
if (offset + chunk_size < total_len) {