8-9/10... inconsistent book tests persist
This commit is contained in:
+13
-62
@@ -21,8 +21,6 @@ pthread_mutex_t context_mutex;
|
||||
|
||||
char *words_list;
|
||||
|
||||
char *sanitize_input(char *input);
|
||||
|
||||
char *get_file_content(FILE *fp)
|
||||
{
|
||||
if (!fp) {
|
||||
@@ -118,9 +116,9 @@ void *receiverFunc(void *args)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int timeout = SEND_RECV_TIMEOUT;
|
||||
zmq_setsockopt(requester, ZMQ_RCVTIMEO, &timeout, sizeof(timeout));
|
||||
zmq_setsockopt(requester, ZMQ_SNDTIMEO, &timeout, sizeof(timeout));
|
||||
// int timeout = SEND_RECV_TIMEOUT;
|
||||
// zmq_setsockopt(requester, ZMQ_RCVTIMEO, &timeout, sizeof(timeout));
|
||||
// zmq_setsockopt(requester, ZMQ_SNDTIMEO, &timeout, sizeof(timeout));
|
||||
|
||||
char addr[22];
|
||||
snprintf(addr, 21, "tcp://localhost:%d", params->port); // BUG: FIX PORT 0
|
||||
@@ -136,8 +134,9 @@ void *receiverFunc(void *args)
|
||||
// fprintf(stderr, "[THREAD] Connected to worker: %s\n", addr);
|
||||
|
||||
char *data = NULL;
|
||||
if(params->type == MAP) data = sanitize_input(params->data);
|
||||
else data = strdup(params->data);
|
||||
// if(params->type == MAP) data = sanitize_input(params->data);
|
||||
// else
|
||||
data = strdup(params->data);
|
||||
free(params->data);
|
||||
|
||||
if(!data){
|
||||
@@ -233,50 +232,6 @@ void *receiverFunc(void *args)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *sanitize_input(char *input){
|
||||
if(!input) return NULL;
|
||||
|
||||
int i = 0;
|
||||
|
||||
char *ret = malloc(sizeof(char));
|
||||
if(!ret){
|
||||
// perror("[MAIN - sanitize_input] Failed to allocate memory for ret");
|
||||
return NULL;
|
||||
}
|
||||
*ret = '\0';
|
||||
|
||||
char *it = input;
|
||||
while(*it && !isalpha(*it)) it++;
|
||||
|
||||
bool writeSpace = false;
|
||||
while(*it){
|
||||
if(isalpha(*it)){
|
||||
char *tmp = NULL;
|
||||
if(writeSpace){
|
||||
tmp = realloc(ret, i + 3);
|
||||
}
|
||||
else{
|
||||
tmp = realloc(ret, i + 2);
|
||||
}
|
||||
if(!tmp){
|
||||
// perror("[MAIN - sanitize_input] Failed to realloc memory for ret");
|
||||
free(ret);
|
||||
return NULL;
|
||||
}
|
||||
ret = tmp;
|
||||
if(writeSpace) ret[i++] = ' ';
|
||||
ret[i++] = tolower(*it++);
|
||||
writeSpace = false;
|
||||
}
|
||||
else{
|
||||
it++;
|
||||
writeSpace = true;
|
||||
}
|
||||
}
|
||||
ret[i] = '\0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
void fucking_string_empty(void *context, char **worker_ports){
|
||||
THREAD_ARGS *args = malloc(sizeof(THREAD_ARGS));
|
||||
if(!args){
|
||||
@@ -306,8 +261,8 @@ void map(size_t worker_count, char **worker_ports, const char *filename, void *c
|
||||
exit(0);
|
||||
}
|
||||
*/
|
||||
char *content = sanitize_input(raw);
|
||||
free(raw);
|
||||
char *content = raw; // sanitize_input(raw);
|
||||
// free(raw);
|
||||
if (!content) {
|
||||
pthread_mutex_destroy(&words_mutex);
|
||||
pthread_mutex_destroy(&context_mutex);
|
||||
@@ -515,8 +470,7 @@ void rip(size_t worker_count, char **worker_ports, void *context){
|
||||
pthread_t *threads = malloc(sizeof(pthread_t) * max_threads);
|
||||
if(!threads){
|
||||
// perror("[MAIN- reduce] Failed to allocate memory for threads");
|
||||
pthread_mutex_destroy(&words_mutex);
|
||||
exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
size_t thread_count = 0;
|
||||
@@ -526,8 +480,7 @@ void rip(size_t worker_count, char **worker_ports, void *context){
|
||||
if(!args){
|
||||
// perror("[MAIN - rip] Failed to allocate memory for args");
|
||||
free(threads);
|
||||
pthread_mutex_destroy(&words_mutex);
|
||||
exit(1);
|
||||
return;
|
||||
}
|
||||
args->port = atol(worker_ports[(int)i]);
|
||||
args->data = strdup("rip");
|
||||
@@ -555,8 +508,7 @@ void rip(size_t worker_count, char **worker_ports, void *context){
|
||||
if (!tmp) {
|
||||
// perror("[MAIN - map] Failed to reallocate memory for threads");
|
||||
free(threads);
|
||||
pthread_mutex_destroy(&words_mutex);
|
||||
exit(1);
|
||||
return;
|
||||
}
|
||||
threads = tmp;
|
||||
}
|
||||
@@ -665,15 +617,14 @@ int main(const int argc, char **argv) {
|
||||
words_list = NULL;
|
||||
|
||||
// fprintf(stderr, "REDUCE:\n%s\n", word_list_reduced);
|
||||
// RIP
|
||||
rip(argc - 2, argv + 2, context);
|
||||
|
||||
// print words_list
|
||||
print_words_list(word_list_reduced);
|
||||
free(word_list_reduced);
|
||||
word_list_reduced = NULL;
|
||||
|
||||
// RIP
|
||||
rip(argc - 2, argv + 2, context);
|
||||
|
||||
pthread_mutex_destroy(&words_mutex);
|
||||
pthread_mutex_destroy(&context_mutex);
|
||||
zmq_ctx_destroy(context);
|
||||
|
||||
Reference in New Issue
Block a user