From 78fea899e0ea79447f64bfd2804cae84bba3b2f8 Mon Sep 17 00:00:00 2001 From: Guillaume Maudoux Date: Thu, 9 Feb 2023 13:56:50 +0100 Subject: Check interupts even when download stalled --- src/libstore/filetransfer.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/libstore/filetransfer.cc') diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index 756bd4423..2818043e8 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -828,15 +828,14 @@ void FileTransfer::download(FileTransferRequest && request, Sink & sink) { auto state(_state->lock()); - while (state->data.empty()) { + if (state->quit) { + if (state->exc) std::rethrow_exception(state->exc); + return; + } - if (state->quit) { - if (state->exc) std::rethrow_exception(state->exc); - return; - } + state.wait(state->avail); - state.wait(state->avail); - } + if (state->data.empty()) continue; chunk = std::move(state->data); -- cgit v1.2.3 From aa18404ecb1fd9cbcb663355e8f5c26ff2b00694 Mon Sep 17 00:00:00 2001 From: Guillaume Maudoux Date: Fri, 10 Feb 2023 00:54:29 +0100 Subject: Flush data when download ends --- src/libstore/filetransfer.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/libstore/filetransfer.cc') diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index 2818043e8..a9a5d1389 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -828,17 +828,18 @@ void FileTransfer::download(FileTransferRequest && request, Sink & sink) { auto state(_state->lock()); - if (state->quit) { - if (state->exc) std::rethrow_exception(state->exc); - return; - } + if (state->data.empty()) { + if (state->quit) { + if (state->exc) std::rethrow_exception(state->exc); + return; + } - state.wait(state->avail); + state.wait(state->avail); - if (state->data.empty()) continue; + if (state->data.empty()) continue; + } chunk = std::move(state->data); - state->request.notify_one(); } -- cgit v1.2.3 From e6ad8e844029ac340dc3f2a4693c3f4a1d645226 Mon Sep 17 00:00:00 2001 From: Guillaume Maudoux Date: Fri, 10 Feb 2023 00:57:56 +0100 Subject: nit: cleaner diff --- src/libstore/filetransfer.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/libstore/filetransfer.cc') diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index a9a5d1389..3ca40db72 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -829,6 +829,7 @@ void FileTransfer::download(FileTransferRequest && request, Sink & sink) auto state(_state->lock()); if (state->data.empty()) { + if (state->quit) { if (state->exc) std::rethrow_exception(state->exc); return; @@ -840,6 +841,7 @@ void FileTransfer::download(FileTransferRequest && request, Sink & sink) } chunk = std::move(state->data); + state->request.notify_one(); } -- cgit v1.2.3