refactor: split transfer and protocol responsibilities #212
@@ -60,6 +60,7 @@ static Client* connect_transfer_client(const Config* config) {
|
|||||||
connected = client_connect(client, config->server_host, config->server_port);
|
connected = client_connect(client, config->server_host, config->server_port);
|
||||||
}
|
}
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
|
client_disconnect(client);
|
||||||
client_delete(client);
|
client_delete(client);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -399,6 +400,13 @@ static int send_chunks_multithreaded(void* pipeline_context) {
|
|||||||
context->queue_loader, &context->mutex_loader, &context->condition_not_empty_loader,
|
context->queue_loader, &context->mutex_loader, &context->condition_not_empty_loader,
|
||||||
&context->condition_not_full_loader, &context->loader_done);
|
&context->condition_not_full_loader, &context->loader_done);
|
||||||
if (current_chunk == NULL) {
|
if (current_chunk == NULL) {
|
||||||
|
if (atomic_load(&context->cancelled)) {
|
||||||
|
pipeline_cancel(context);
|
||||||
|
disconnect_transfer_client(client);
|
||||||
|
mark_sender_done(context);
|
||||||
|
protocol_session_unbind();
|
||||||
|
return thrd_error;
|
||||||
|
}
|
||||||
if (context->config->use_delete) {
|
if (context->config->use_delete) {
|
||||||
if (send_delete_manifest(client->file_descriptor, context->manifest) != 0)
|
if (send_delete_manifest(client->file_descriptor, context->manifest) != 0)
|
||||||
goto send_fail;
|
goto send_fail;
|
||||||
@@ -523,9 +531,7 @@ static int load_files_multithreaded(void* pipeline_context) {
|
|||||||
&context->condition_not_full_loader,
|
&context->condition_not_full_loader,
|
||||||
&context->cancelled)) {
|
&context->cancelled)) {
|
||||||
chunk_destroy(chunk);
|
chunk_destroy(chunk);
|
||||||
atomic_store(&context->cancelled, true);
|
pipeline_cancel(context);
|
||||||
cnd_broadcast(&context->condition_not_full_loader);
|
|
||||||
cnd_broadcast(&context->condition_not_empty_loader);
|
|
||||||
return thrd_error;
|
return thrd_error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,6 +183,15 @@ int write_thread(void* pipeline_context) {
|
|||||||
bool save_to_disk = context->config->save_to_disk;
|
bool save_to_disk = context->config->save_to_disk;
|
||||||
char* root_directory = str_dup(context->config->receive_root_directory);
|
char* root_directory = str_dup(context->config->receive_root_directory);
|
||||||
mtx_unlock(&context->mutex);
|
mtx_unlock(&context->mutex);
|
||||||
|
if (save_to_disk && !root_directory) {
|
||||||
|
mtx_lock(&context->mutex);
|
||||||
|
atomic_store(&context->cancelled, true);
|
||||||
|
context->receiver_done = true;
|
||||||
|
cnd_broadcast(&context->condition_not_full);
|
||||||
|
cnd_broadcast(&context->condition_not_empty);
|
||||||
|
mtx_unlock(&context->mutex);
|
||||||
|
return thrd_error;
|
||||||
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
File* file =
|
File* file =
|
||||||
|
|||||||
Reference in New Issue
Block a user