diff --git a/README.md b/README.md index 6a83048..95d69c9 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ The client-server communication uses the following status codes: | `-m` | Enable multithreading mode | | `-c [level]` | Enable compression with optional level (1-22, default: 5) | | `-s` | Enable chunk serialization (batch-transfer all files per chunk) | -| `-f` | Enable sendfile (zero-copy file transfer, bypasses userspace memory) | +| `-f` | Enable sendfile (zero-copy file transfer, bypasses userspace memory). Can be combined with `-m`. Incompatible with `-c` and `-s`. | | `--source-dir ` | Source directory to sync (overrides `FASTSYNC_SOURCE_DIR`) | | `--dest-dir ` | Server-side destination directory (overrides `FASTSYNC_DEST_DIR`) | | `--save-to-disk` | Persist received files to disk | diff --git a/src/client/client.c b/src/client/client.c index 25bcf41..65b2500 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -86,8 +86,10 @@ int load_files_multithreaded(void *pipeline_context) { mtx_unlock(&context->mutex_loader); return thrd_success; } - for (int i = 0; i < chunk->element_count; i++) - file_load_data(chunk->items[i]); + if (!context->config->use_sendfile) { + for (int i = 0; i < chunk->element_count; i++) + file_load_data(chunk->items[i]); + } queue_enqueue_multithreaded(context->queue_loader, chunk, &context->mutex_loader, &context->condition_not_empty_loader, @@ -152,11 +154,6 @@ int send_files(Config *config) { } int send_files_multithreaded(Config *config) { - if (config->use_sendfile) { - log_message(LOG_LEVEL_INFO, "Sendfile enabled, falling back to single-threaded"); - return send_files(config); - } - PipelineContextSender *context = pipeline_context_sender_create(config, queue_create(100, chunk_destroy), queue_create(100, chunk_destroy)); @@ -238,6 +235,11 @@ int main(int argc, char *argv[]) { } } + if (config->use_sendfile && (config->use_chunk_serialization || config->use_compression)) { + fprintf(stderr, "Error: -f/--sendfile cannot be combined with -c (compression) or -s (chunk serialization)\n"); + return 1; + } + if (config->use_multithreading) return send_files_multithreaded(config); return send_files(config); diff --git a/test.py b/test.py index 6534921..62790f1 100755 --- a/test.py +++ b/test.py @@ -49,6 +49,7 @@ TEST_CASES = [ "flags": ["-m", "-c", "-s"], }, {"name": "Sendfile (-f)", "flags": ["-f"]}, + {"name": "Sendfile + Multithreading (-f -m)", "flags": ["-f", "-m"]}, ]