Fixed double words (for first word the pointer was not moved) - Fixed last char overwritten (\0 was inserted one to early

This commit is contained in:
Ano-sys
2025-01-29 16:02:23 +01:00
parent 190011be88
commit 95bdf0867d
13 changed files with 33733 additions and 33749 deletions
+9 -7
View File
@@ -44,13 +44,13 @@ char *get_file_content(FILE *fp)
if (delimiter_pos < 0)
{
perror("No delimiting character was found -> taking whole buffer");
printf("No delimiting character was found -> taking whole buffer");
delimiter_pos = (int)bytes_read;
}
buffer[delimiter_pos] = '\0';
buffer[delimiter_pos + 1] = '\0';
if (fseek(fp, delimiter_pos - (int) bytes_read + 1, SEEK_CUR) != 0)
if (fseek(fp, delimiter_pos - (int) bytes_read + 2, SEEK_CUR) != 0)
{
perror("Failed to seek in file");
free(buffer);
@@ -88,6 +88,7 @@ void *receiverFunc(void *args)
zmq_ctx_destroy(context);
return NULL;
}
printf("[THREAD] Connected to worker: %s\n", addr);
size_t len = strlen(params->data) + 4;
char *request = (char*)malloc(sizeof(char) * len);
@@ -116,7 +117,7 @@ void *receiverFunc(void *args)
zmq_ctx_destroy(context);
return NULL;
}
printf("[THREAD] Sent request: %s\n", request);
if(zmq_send(requester, request, strlen(request), 0) == -1){
perror("[THREAD] Failed to send request");
free(params);
@@ -128,6 +129,7 @@ void *receiverFunc(void *args)
free(request);
printf("[THREAD]: Waiting for response\n");
char reply[MESSAGE_LENGTH];
int bytes_recv = zmq_recv(requester, reply, MESSAGE_LENGTH - 1, 0);
if (bytes_recv == -1){
@@ -197,13 +199,13 @@ int main(const int argc, char **argv) {
FILE *fp = fopen(argv[1], "r");
char *file_content_chunks;
int worker_index = 1;
int worker_count = argc - 1;
int worker_index = 2;
int worker_count = argc - 2;
int thread_count = 0;
pthread_t *threads = (pthread_t*)malloc(sizeof(pthread_t) * worker_count);
while ((file_content_chunks = get_file_content(fp)) != NULL && thread_count < worker_count)
while (thread_count < worker_count && (file_content_chunks = get_file_content(fp)) != NULL)
{
pthread_t receiver;