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:
Binary file not shown.
@@ -1,57 +1,41 @@
|
|||||||
# ninja log v6
|
# ninja log v6
|
||||||
1 39 1738105708158215431 distributor 52b9e5589e6de4bc
|
|
||||||
0 30 1738105442283119334 CMakeFiles/distributor.dir/zmq_worker.c.o d5e5fcc0aafed156
|
|
||||||
0 16 1738107753006229164 build.ninja e4e5b46deb631549
|
|
||||||
0 40 1738105101300577756 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
|
||||||
1 29 1738105101301577749 CMakeFiles/distributor.dir/key_value_pair.c.o 3e4f10264f7b6f9
|
|
||||||
0 24 1738107753006229164 build.ninja e4e5b46deb631549
|
|
||||||
0 36 1738107753016229087 distributor 94c57781821b8eee
|
|
||||||
1 22 1738107830333638561 CMakeFiles/worker.dir/key_value_pair.c.o c815e7263f0d0a22
|
|
||||||
1 31 1738107830333638561 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
|
||||||
31 69 1738107830363638332 worker 8cb044e4b1d208e8
|
|
||||||
0 32 1738107952547710219 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
|
||||||
33 74 1738107952580709969 worker 8cb044e4b1d208e8
|
|
||||||
0 31 1738108015014237740 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
|
||||||
31 69 1738108015045237506 worker 8cb044e4b1d208e8
|
|
||||||
1 31 1738108032559105252 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
|
||||||
31 66 1738108032589105026 worker 8cb044e4b1d208e8
|
|
||||||
0 31 1738108046835997508 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
|
||||||
31 68 1738108046866997274 distributor 94c57781821b8eee
|
|
||||||
1 30 1738108289587173099 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
|
||||||
30 66 1738108289616172882 distributor 94c57781821b8eee
|
|
||||||
1 40 1738108439213054072 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
|
||||||
40 78 1738108439252053781 distributor 94c57781821b8eee
|
|
||||||
1 32 1738108534691341593 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
|
||||||
32 72 1738108534723341355 distributor 94c57781821b8eee
|
|
||||||
0 30 1738108557080174671 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
|
||||||
30 71 1738108557110174447 distributor 94c57781821b8eee
|
|
||||||
0 37 1738109015729940868 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
|
||||||
37 81 1738109015766940606 worker 8cb044e4b1d208e8
|
|
||||||
0 30 1738109205723589399 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
|
||||||
30 66 1738109205753589185 worker 8cb044e4b1d208e8
|
|
||||||
1 32 1738109381098330224 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
|
||||||
32 71 1738109381129330002 worker 8cb044e4b1d208e8
|
|
||||||
0 22 1738109438872913564 CMakeFiles/distributor.dir/key_value_pair.c.o 3e4f10264f7b6f9
|
|
||||||
22 60 1738109438894913406 distributor 94c57781821b8eee
|
|
||||||
0 22 1738109440578901248 CMakeFiles/worker.dir/key_value_pair.c.o c815e7263f0d0a22
|
|
||||||
22 60 1738109440600901090 worker 8cb044e4b1d208e8
|
|
||||||
0 31 1738109574428933106 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
|
||||||
31 66 1738109574459932881 worker 8cb044e4b1d208e8
|
|
||||||
1 32 1738109773469487886 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
|
||||||
32 68 1738109773500487661 worker 8cb044e4b1d208e8
|
|
||||||
0 32 1738109827431095194 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
|
||||||
32 68 1738109827463094961 worker 8cb044e4b1d208e8
|
|
||||||
0 31 1738109883817684518 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
|
||||||
31 69 1738109883848684292 worker 8cb044e4b1d208e8
|
|
||||||
1 31 1738110050147471462 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
|
||||||
31 69 1738110050177471243 worker 8cb044e4b1d208e8
|
|
||||||
1 35 1738110109599037390 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
|
||||||
35 71 1738110109633037141 worker 8cb044e4b1d208e8
|
|
||||||
0 32 1738110314667538601 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
|
||||||
32 69 1738110314699538367 worker 8cb044e4b1d208e8
|
|
||||||
1 31 1738110475673360618 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
|
||||||
31 68 1738110475703360398 worker 8cb044e4b1d208e8
|
|
||||||
0 32 1738110729201525050 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
|
||||||
32 69 1738110729233524838 worker 8cb044e4b1d208e8
|
|
||||||
1 32 1738110893874419033 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
|
||||||
32 69 1738110893905418822 distributor 94c57781821b8eee
|
32 69 1738110893905418822 distributor 94c57781821b8eee
|
||||||
|
0 30 1738105442283119334 CMakeFiles/distributor.dir/zmq_worker.c.o d5e5fcc0aafed156
|
||||||
|
0 24 1738158788025158273 build.ninja e4e5b46deb631549
|
||||||
|
1 32 1738110893874419033 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
||||||
|
0 22 1738109440578901248 CMakeFiles/worker.dir/key_value_pair.c.o c815e7263f0d0a22
|
||||||
|
32 69 1738110729233524838 worker 8cb044e4b1d208e8
|
||||||
|
0 22 1738109438872913564 CMakeFiles/distributor.dir/key_value_pair.c.o 3e4f10264f7b6f9
|
||||||
|
0 32 1738110729201525050 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
||||||
|
0 47 1738159115534281752 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
||||||
|
47 88 1738159115581282030 worker 8cb044e4b1d208e8
|
||||||
|
0 31 1738160036073886257 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
||||||
|
31 69 1738160036104886135 worker 8cb044e4b1d208e8
|
||||||
|
0 33 1738160039499872677 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
||||||
|
33 74 1738160039532872546 distributor 94c57781821b8eee
|
||||||
|
0 36 1738160280110822932 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
||||||
|
36 72 1738160280146822763 worker 8cb044e4b1d208e8
|
||||||
|
1 32 1738160366603408106 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
||||||
|
32 67 1738160366634407955 worker 8cb044e4b1d208e8
|
||||||
|
1 36 1738160545081507330 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
||||||
|
36 78 1738160545116507148 worker 8cb044e4b1d208e8
|
||||||
|
1 30 1738161121542863524 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
||||||
|
30 69 1738161121571863155 distributor 94c57781821b8eee
|
||||||
|
0 29 1738161228788554820 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
||||||
|
29 65 1738161228817554481 distributor 94c57781821b8eee
|
||||||
|
0 29 1738161354145148561 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
||||||
|
29 65 1738161354174148249 distributor 94c57781821b8eee
|
||||||
|
0 31 1738161531871329808 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
||||||
|
31 69 1738161531902329505 worker 8cb044e4b1d208e8
|
||||||
|
0 33 1738161877544183345 CMakeFiles/worker.dir/zmq_worker.c.o 8c7caa5d8888f06b
|
||||||
|
33 70 1738161877577183062 worker 8cb044e4b1d208e8
|
||||||
|
0 30 1738162098218341663 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
||||||
|
30 66 1738162098248341418 distributor 94c57781821b8eee
|
||||||
|
1 30 1738162114935205702 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
||||||
|
30 65 1738162114964205467 distributor 94c57781821b8eee
|
||||||
|
0 29 1738162161079832549 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
||||||
|
29 67 1738162161108832315 distributor 94c57781821b8eee
|
||||||
|
1 33 1738162779063038217 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
||||||
|
33 72 1738162779095037975 distributor 94c57781821b8eee
|
||||||
|
0 30 1738162800215878405 CMakeFiles/distributor.dir/zmq_distributor.c.o 8386b22addd5fe65
|
||||||
|
30 69 1738162800245878178 distributor 94c57781821b8eee
|
||||||
|
|||||||
@@ -1,16 +1,4 @@
|
|||||||
/home/timo/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/home/timo/.local/share/JetBrains/Toolbox/apps/clion/bin/ninja/linux/x64/ninja -G Ninja -S /home/timo/gitl/RN-Praxis3/praxis3 -B /home/timo/gitl/RN-Praxis3/praxis3/cmake-build-debug
|
/home/timo/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/home/timo/.local/share/JetBrains/Toolbox/apps/clion/bin/ninja/linux/x64/ninja -G Ninja -S /home/timo/gitl/RN-Praxis3/praxis3 -B /home/timo/gitl/RN-Praxis3/praxis3/cmake-build-debug
|
||||||
-- The C compiler identification is GNU 14.2.1
|
-- Configuring done (0.0s)
|
||||||
-- The CXX compiler identification is GNU 14.2.1
|
|
||||||
-- Detecting C compiler ABI info
|
|
||||||
-- Detecting C compiler ABI info - done
|
|
||||||
-- Check for working C compiler: /bin/cc - skipped
|
|
||||||
-- Detecting C compile features
|
|
||||||
-- Detecting C compile features - done
|
|
||||||
-- Detecting CXX compiler ABI info
|
|
||||||
-- Detecting CXX compiler ABI info - done
|
|
||||||
-- Check for working CXX compiler: /bin/c++ - skipped
|
|
||||||
-- Detecting CXX compile features
|
|
||||||
-- Detecting CXX compile features - done
|
|
||||||
-- Configuring done (0.3s)
|
|
||||||
-- Generating done (0.0s)
|
-- Generating done (0.0s)
|
||||||
-- Build files have been written to: /home/timo/gitl/RN-Praxis3/praxis3/cmake-build-debug
|
-- Build files have been written to: /home/timo/gitl/RN-Praxis3/praxis3/cmake-build-debug
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -1,3 +1,3 @@
|
|||||||
Start testing: Jan 29 01:35 CET
|
Start testing: Jan 29 16:00 CET
|
||||||
----------------------------------------------------------
|
----------------------------------------------------------
|
||||||
End testing: Jan 29 01:35 CET
|
End testing: Jan 29 16:00 CET
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@@ -44,13 +44,13 @@ char *get_file_content(FILE *fp)
|
|||||||
|
|
||||||
if (delimiter_pos < 0)
|
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;
|
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");
|
perror("Failed to seek in file");
|
||||||
free(buffer);
|
free(buffer);
|
||||||
@@ -88,6 +88,7 @@ void *receiverFunc(void *args)
|
|||||||
zmq_ctx_destroy(context);
|
zmq_ctx_destroy(context);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
printf("[THREAD] Connected to worker: %s\n", addr);
|
||||||
|
|
||||||
size_t len = strlen(params->data) + 4;
|
size_t len = strlen(params->data) + 4;
|
||||||
char *request = (char*)malloc(sizeof(char) * len);
|
char *request = (char*)malloc(sizeof(char) * len);
|
||||||
@@ -116,7 +117,7 @@ void *receiverFunc(void *args)
|
|||||||
zmq_ctx_destroy(context);
|
zmq_ctx_destroy(context);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
printf("[THREAD] Sent request: %s\n", request);
|
||||||
if(zmq_send(requester, request, strlen(request), 0) == -1){
|
if(zmq_send(requester, request, strlen(request), 0) == -1){
|
||||||
perror("[THREAD] Failed to send request");
|
perror("[THREAD] Failed to send request");
|
||||||
free(params);
|
free(params);
|
||||||
@@ -128,6 +129,7 @@ void *receiverFunc(void *args)
|
|||||||
|
|
||||||
free(request);
|
free(request);
|
||||||
|
|
||||||
|
printf("[THREAD]: Waiting for response\n");
|
||||||
char reply[MESSAGE_LENGTH];
|
char reply[MESSAGE_LENGTH];
|
||||||
int bytes_recv = zmq_recv(requester, reply, MESSAGE_LENGTH - 1, 0);
|
int bytes_recv = zmq_recv(requester, reply, MESSAGE_LENGTH - 1, 0);
|
||||||
if (bytes_recv == -1){
|
if (bytes_recv == -1){
|
||||||
@@ -197,13 +199,13 @@ int main(const int argc, char **argv) {
|
|||||||
|
|
||||||
FILE *fp = fopen(argv[1], "r");
|
FILE *fp = fopen(argv[1], "r");
|
||||||
char *file_content_chunks;
|
char *file_content_chunks;
|
||||||
int worker_index = 1;
|
int worker_index = 2;
|
||||||
int worker_count = argc - 1;
|
int worker_count = argc - 2;
|
||||||
int thread_count = 0;
|
int thread_count = 0;
|
||||||
|
|
||||||
pthread_t *threads = (pthread_t*)malloc(sizeof(pthread_t) * worker_count);
|
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;
|
pthread_t receiver;
|
||||||
|
|||||||
+25
-18
@@ -40,7 +40,7 @@ int main(int argc, char **argv){
|
|||||||
printf("Initialized Thread: %d\n", thread_count);
|
printf("Initialized Thread: %d\n", thread_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Done initialization");
|
printf("Init DONE\n");
|
||||||
|
|
||||||
// wait for workers to finish
|
// wait for workers to finish
|
||||||
for(int i = 0; i < thread_count; i++){
|
for(int i = 0; i < thread_count; i++){
|
||||||
@@ -96,6 +96,16 @@ void* workerFunc(void *args){
|
|||||||
|
|
||||||
char request[MESSAGE_LENGTH + 1]; // CHECK: off by one error
|
char request[MESSAGE_LENGTH + 1]; // CHECK: off by one error
|
||||||
int bytes_recv = zmq_recv(responder, request, MESSAGE_LENGTH, 0);
|
int bytes_recv = zmq_recv(responder, request, MESSAGE_LENGTH, 0);
|
||||||
|
if(bytes_recv <= 0){
|
||||||
|
perror("Failed to receive request");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
char endpoint[256];
|
||||||
|
size_t endpoint_size = sizeof(endpoint);
|
||||||
|
if (zmq_getsockopt(responder, ZMQ_LAST_ENDPOINT, endpoint, &endpoint_size) == 0) {
|
||||||
|
printf("Got request from: %s\n", endpoint);
|
||||||
|
}
|
||||||
|
|
||||||
const TYPE type = get_request_type(request);
|
const TYPE type = get_request_type(request);
|
||||||
char *content = request + TYPE_LENGTH;
|
char *content = request + TYPE_LENGTH;
|
||||||
@@ -104,15 +114,15 @@ void* workerFunc(void *args){
|
|||||||
|
|
||||||
switch(type){
|
switch(type){
|
||||||
case MAP:
|
case MAP:
|
||||||
perror("Handling MAP\n");
|
printf("Handling MAP\n");
|
||||||
ret = map(content, &head, &tail);
|
ret = map(content, &head, &tail);
|
||||||
break;
|
break;
|
||||||
case RED:
|
case RED:
|
||||||
perror("Handling RED\n");
|
printf("Handling RED\n");
|
||||||
ret = reduce(content);
|
ret = reduce(content);
|
||||||
break;
|
break;
|
||||||
case RIP:
|
case RIP:
|
||||||
perror("Handling RIP\n");
|
printf("Handling RIP\n");
|
||||||
// send errors are redundant to handle because exit
|
// send errors are redundant to handle because exit
|
||||||
zmq_send(responder, "rip", TYPE_LENGTH, 0);
|
zmq_send(responder, "rip", TYPE_LENGTH, 0);
|
||||||
zmq_close(responder);
|
zmq_close(responder);
|
||||||
@@ -125,8 +135,8 @@ void* workerFunc(void *args){
|
|||||||
exit(1);
|
exit(1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
printf("Sending content: %s\n", ret);
|
||||||
if(zmq_send(responder, ret, MESSAGE_LENGTH, 0) != 0){
|
if(zmq_send(responder, ret, strlen(ret), 0) != 0){
|
||||||
perror("Failed to send response");
|
perror("Failed to send response");
|
||||||
zmq_close(responder);
|
zmq_close(responder);
|
||||||
zmq_ctx_destroy(context);
|
zmq_ctx_destroy(context);
|
||||||
@@ -158,22 +168,18 @@ char* get_word(const char *request){
|
|||||||
if(request == NULL || *request == '\0')
|
if(request == NULL || *request == '\0')
|
||||||
return strdup("");
|
return strdup("");
|
||||||
|
|
||||||
int capacity = 16;
|
|
||||||
int length = 0;
|
int length = 0;
|
||||||
char *word = (char*)malloc(capacity);
|
char *word = (char*)malloc(sizeof(char));
|
||||||
if(!word)
|
if(!word)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
while(*request && isalpha(*request)){
|
while(*request && isalpha(*request)){
|
||||||
if(length + 1 >= capacity){
|
char *new_word = (char*)realloc(word, strlen(word) + 2); // realloc word size + \0 and extra char space
|
||||||
capacity *= 2;
|
if(!new_word){
|
||||||
char *new_word = (char*)realloc(word, capacity);
|
free(word);
|
||||||
if(!new_word){
|
return NULL;
|
||||||
free(word);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
word = new_word;
|
|
||||||
}
|
}
|
||||||
|
word = new_word;
|
||||||
word[length++] = *request;
|
word[length++] = *request;
|
||||||
request++;
|
request++;
|
||||||
}
|
}
|
||||||
@@ -193,7 +199,7 @@ char* map(const char *content, key_value_pair **head, key_value_pair **tail){
|
|||||||
if(strcmp(word, "") != 0){
|
if(strcmp(word, "") != 0){
|
||||||
add_word(word, head, tail);
|
add_word(word, head, tail);
|
||||||
}
|
}
|
||||||
content_iterator += strlen(word) + 1;
|
content_iterator += strlen(word) + 1; // skip current read word + one delimiter char
|
||||||
free(word);
|
free(word);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,12 +216,13 @@ char* map(const char *content, key_value_pair **head, key_value_pair **tail){
|
|||||||
}
|
}
|
||||||
if(!ret){
|
if(!ret){
|
||||||
ret = strdup(kvp2str);
|
ret = strdup(kvp2str);
|
||||||
|
kvp_it = kvp_it->next;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
char *tmp = realloc(ret, strlen(ret) + strlen(kvp2str) + 1);
|
char *tmp = realloc(ret, strlen(ret) + strlen(kvp2str) + 1);
|
||||||
if(!tmp){
|
if(!tmp){
|
||||||
free(ret);
|
free(ret);
|
||||||
perror("Failed to realloc memory for ret");
|
perror("Failed to reallocate memory for ret");
|
||||||
free(kvp2str);
|
free(kvp2str);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user