Merge branch 'main' into metadata-transfer, resolve conflicts
Conflicts resolved: - config_create signature: added both use_metadata and use_sendfile params - config_send/config_receive: wire protocol includes both use_metadata and use_sendfile - client.c: config_create call updated, arg parsing includes both -M/--preserve and -f/--sendfile - test_config.c: all three config_create calls updated - file_send_sendfile: use file->data->size instead of removed struct stat
This commit is contained in:
+5
-2
@@ -7,8 +7,8 @@
|
||||
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_metadata,
|
||||
int compression_level, int num_connections) {
|
||||
bool use_compression, bool use_metadata,
|
||||
int compression_level, int num_connections, bool use_sendfile) {
|
||||
|
||||
Config *config = malloc(sizeof(Config));
|
||||
config->version = version;
|
||||
@@ -21,6 +21,7 @@ Config *config_create(char *version, char *send_directory,
|
||||
config->use_metadata = use_metadata;
|
||||
config->compression_level = compression_level;
|
||||
config->num_connections = num_connections;
|
||||
config->use_sendfile = use_sendfile;
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -42,6 +43,7 @@ void config_send(int file_descriptor, Config *config) {
|
||||
send_int(file_descriptor, config->use_metadata);
|
||||
send_int(file_descriptor, config->compression_level);
|
||||
send_int(file_descriptor, config->num_connections);
|
||||
send_int(file_descriptor, config->use_sendfile);
|
||||
if (receive_status(file_descriptor) != STATUS_OK) {
|
||||
perror("Error transmitting config!");
|
||||
exit(EXIT_FAILURE);
|
||||
@@ -60,6 +62,7 @@ Config *config_receive(int file_descriptor) {
|
||||
config->use_metadata = receive_int(file_descriptor);
|
||||
config->compression_level = receive_int(file_descriptor);
|
||||
config->num_connections = receive_int(file_descriptor);
|
||||
config->use_sendfile = receive_int(file_descriptor);
|
||||
send_status(file_descriptor, STATUS_OK);
|
||||
return config;
|
||||
}
|
||||
|
||||
+3
-2
@@ -11,6 +11,7 @@ typedef struct Config {
|
||||
bool use_multithreading;
|
||||
bool use_chunk_serialization;
|
||||
bool use_compression;
|
||||
bool use_sendfile;
|
||||
bool use_single_send_per_file;
|
||||
bool use_metadata;
|
||||
int compression_level;
|
||||
@@ -20,8 +21,8 @@ typedef struct 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_metadata,
|
||||
int compression_level, int num_connections);
|
||||
bool use_compression, bool use_metadata,
|
||||
int compression_level, int num_connections, bool use_sendfile);
|
||||
void config_delete(Config *config);
|
||||
void config_send(int file_descriptor, Config *config);
|
||||
Config *config_receive(int file_descriptor);
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <libgen.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <unistd.h>
|
||||
#include <zstd.h>
|
||||
|
||||
#include "data.h"
|
||||
@@ -122,6 +125,31 @@ void file_send_single_calls(File *file, int file_descriptor) {
|
||||
send_data(file_descriptor, file->data->data, file->data->size);
|
||||
}
|
||||
|
||||
void file_send_sendfile(File *file, int file_descriptor) {
|
||||
send_str(file_descriptor, file->path);
|
||||
|
||||
int fd = open(file->path, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
perror("Could not open file for sendfile");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
unsigned long long file_size = file->data->size;
|
||||
send_n_data(file_descriptor, &file_size, sizeof(unsigned long long));
|
||||
|
||||
off_t offset = 0;
|
||||
while (offset < file_size) {
|
||||
ssize_t sent = sendfile(file_descriptor, fd, &offset, file_size - offset);
|
||||
if (sent == -1) {
|
||||
perror("sendfile failed");
|
||||
close(fd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
size_t file_content_to_buffer(File *file) {
|
||||
FILE *file_pointer = fopen(file->path, "rb");
|
||||
if (file_pointer == NULL) {
|
||||
|
||||
@@ -23,6 +23,7 @@ void file_destroy(void *item);
|
||||
void file_load_data(File *file);
|
||||
void file_print(void *item);
|
||||
void file_send_single_calls(File *file, int file_descriptor);
|
||||
void file_send_sendfile(File *file, int file_descriptor);
|
||||
size_t file_content_to_buffer(File *file);
|
||||
FileMetadata *file_metadata_create(struct stat *stats);
|
||||
void file_metadata_destroy(void *metadata);
|
||||
|
||||
Reference in New Issue
Block a user