improved testing capabilities and fixed bug that pre ended chunk sending
This commit is contained in:
+25
-27
@@ -7,6 +7,7 @@
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "multiprocessing.h"
|
||||
#include "pipeline.h"
|
||||
#include "queue.h"
|
||||
#include "scanner.h"
|
||||
#include "socket.h"
|
||||
@@ -24,9 +25,6 @@ int send_chunk(Client *client, Chunk *chunk, bool use_compression) {
|
||||
send_str(client->file_descriptor, file->path);
|
||||
send_data(client->file_descriptor, file->data, file->stats.st_size);
|
||||
}
|
||||
send_status(client->file_descriptor, FINISHED);
|
||||
if (receive_status(client->file_descriptor) != OK)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -105,12 +103,14 @@ int send_files(Config *config) {
|
||||
DirectoryScanner *scanner = directory_scanner_create(config->send_directory);
|
||||
Chunk *current_chunk;
|
||||
while ((current_chunk = directory_scanner_next(scanner)) != NULL) {
|
||||
chunk_print(current_chunk);
|
||||
for (int i = 0; i < current_chunk->element_count; i++)
|
||||
file_load_data(current_chunk->items[i]);
|
||||
send_chunk(client, current_chunk, config->use_compression);
|
||||
chunk_destroy(current_chunk);
|
||||
}
|
||||
send_status(client->file_descriptor, FINISHED);
|
||||
if (receive_status(client->file_descriptor) != OK)
|
||||
return -1;
|
||||
printf("FINISHED");
|
||||
directory_scanner_destroy(scanner);
|
||||
client_disconnect(client);
|
||||
@@ -149,42 +149,40 @@ int send_files_multithreaded(Config *config) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int send_files_multiprocessed(Config *config) {
|
||||
int cores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
int pid = fork();
|
||||
if (pid == -1) {
|
||||
perror("Error Forking!");
|
||||
return 1;
|
||||
} else if (pid == 0) {
|
||||
}
|
||||
for (int i = 0; i < cores; i++) {
|
||||
int pid = fork();
|
||||
if (pid == -1) {
|
||||
perror("Error forking!");
|
||||
return 1;
|
||||
} else if (pid == 0) {
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// int send_files_multiprocessed(Config *config) {
|
||||
// int cores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
// int pid = fork();
|
||||
// if (pid == -1) {
|
||||
// perror("Error Forking!");
|
||||
// return 1;
|
||||
// } else if (pid == 0) {
|
||||
// }
|
||||
// for (int i = 0; i < cores; i++) {
|
||||
// int pid = fork();
|
||||
// if (pid == -1) {
|
||||
// perror("Error forking!");
|
||||
// return 1;
|
||||
// } else if (pid == 0) {
|
||||
// }
|
||||
// }
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
Config *config = config_create(
|
||||
str_dup("1.0.0"), str_dup("/home/taptap/Nextcloud/Uni/moodle/MINT-Raum"),
|
||||
str_dup("./data_copied"), false, false, false, false, false, 1);
|
||||
str_dup("./data_copied"), false, false, false, false, 1);
|
||||
for (int i = 1; i < argc; i++) {
|
||||
handle_arg(argv[i], "-m", &config->use_multithreading,
|
||||
"Enabled Multithreading");
|
||||
handle_arg(argv[i], "-s", &config->use_chunk_serialization,
|
||||
"Enabled Chunk Serialization");
|
||||
handle_arg(argv[i], "-c", &config->use_compression, "Enabled Compression");
|
||||
handle_arg(argv[i], "-p", &config->use_multiprocessing,
|
||||
"Enabled Multiprocessing");
|
||||
}
|
||||
|
||||
if (config->use_multithreading)
|
||||
return send_files_multithreaded(config);
|
||||
else if (config->use_multiprocessing)
|
||||
return send_files_multiprocessed(config);
|
||||
// else if (config->use_multiprocessing)
|
||||
// return send_files_multiprocessed(config);
|
||||
return send_files(config);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@ Chunk *directory_scanner_next(DirectoryScanner *scanner) {
|
||||
perror("Could not open directory!");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("%s", path);
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
|
||||
continue;
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
FileReceive *receive_file_receive(int file_descriptor) {
|
||||
char *path = (char *)receive_str(file_descriptor);
|
||||
printf("%s\n", path);
|
||||
DataFragment *file_data_fragment = receive_data(file_descriptor);
|
||||
FileReceive *file = file_receive_create(path, file_data_fragment);
|
||||
return file;
|
||||
|
||||
+1
-5
@@ -7,8 +7,7 @@
|
||||
Config *config_create(char *version, char *send_directory,
|
||||
char *receive_directory, bool save_to_disk,
|
||||
bool use_multithreading, bool use_chunk_serialization,
|
||||
bool use_compression, bool use_multiprocessing,
|
||||
int num_connections) {
|
||||
bool use_compression, int num_connections) {
|
||||
|
||||
Config *config = malloc(sizeof(Config));
|
||||
config->version = version;
|
||||
@@ -18,7 +17,6 @@ Config *config_create(char *version, char *send_directory,
|
||||
config->use_multithreading = use_multithreading;
|
||||
config->use_chunk_serialization = use_chunk_serialization;
|
||||
config->use_compression = use_compression;
|
||||
config->use_multiprocessing = use_multiprocessing;
|
||||
config->num_connections = num_connections;
|
||||
return config;
|
||||
}
|
||||
@@ -38,7 +36,6 @@ void config_send(int file_descriptor, Config *config) {
|
||||
send_int(file_descriptor, config->use_multithreading);
|
||||
send_int(file_descriptor, config->use_chunk_serialization);
|
||||
send_int(file_descriptor, config->use_compression);
|
||||
send_int(file_descriptor, config->use_multiprocessing);
|
||||
send_int(file_descriptor, config->num_connections);
|
||||
if (receive_status(file_descriptor) != OK) {
|
||||
perror("Error transmitting config!");
|
||||
@@ -55,7 +52,6 @@ Config *config_receive(int file_descriptor) {
|
||||
config->use_multithreading = receive_int(file_descriptor);
|
||||
config->use_chunk_serialization = receive_int(file_descriptor);
|
||||
config->use_compression = receive_int(file_descriptor);
|
||||
config->use_multiprocessing = receive_int(file_descriptor);
|
||||
config->num_connections = receive_int(file_descriptor);
|
||||
send_status(file_descriptor, OK);
|
||||
return config;
|
||||
|
||||
+1
-3
@@ -11,15 +11,13 @@ typedef struct Config {
|
||||
bool use_multithreading;
|
||||
bool use_chunk_serialization;
|
||||
bool use_compression;
|
||||
bool use_multiprocessing;
|
||||
int num_connections;
|
||||
} Config;
|
||||
|
||||
Config *config_create(char *version, char *send_directory,
|
||||
char *receive_directory, bool save_to_disk,
|
||||
bool use_multithreading, bool use_chunk_serialization,
|
||||
bool use_compression, bool use_multiprocessing,
|
||||
int num_connections);
|
||||
bool use_compression, int num_connections);
|
||||
void config_delete(Config *config);
|
||||
void config_send(int file_descriptor, Config *config);
|
||||
Config *config_receive(int file_descriptor);
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef PIPELINE_H
|
||||
#define PIPELINE_H
|
||||
|
||||
struct
|
||||
|
||||
#endif
|
||||
+17
-2
@@ -198,14 +198,29 @@ int receive_int(int file_descriptor) {
|
||||
return data;
|
||||
}
|
||||
|
||||
const char *status_to_string(Status status) {
|
||||
switch (status) {
|
||||
case OK:
|
||||
return "OK";
|
||||
case ERROR:
|
||||
return "ERROR";
|
||||
case FINISHED:
|
||||
return "FINISHED";
|
||||
case NEXT:
|
||||
return "NEXT";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
void send_status(int file_descriptor, Status status) {
|
||||
send_n_data(file_descriptor, &status, sizeof(Status));
|
||||
log_message(LOG_LEVEL_DEBUG, "Send Status: %d", status);
|
||||
log_message(LOG_LEVEL_DEBUG, "Send Status: %s", status_to_string(status));
|
||||
}
|
||||
|
||||
Status receive_status(int file_descriptor) {
|
||||
Status data;
|
||||
receive_n_data(file_descriptor, &data, sizeof(Status));
|
||||
log_message(LOG_LEVEL_DEBUG, "Received Status: %d", data);
|
||||
log_message(LOG_LEVEL_DEBUG, "Received Status: %s", status_to_string(data));
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user