libstore: remove our custom early timeout handling
curl handles timeouts internally when it acts as the main event loop. we
only need to wake up to add new transfers to the multi handle or restart
an existing transfer that has passed its restart wait time. periodically
waking up is not required for curl, and we don't need it any more either
Change-Id: Ic774e1d9519f807cda1a89694bc3ede75216f329
This commit is contained in:
parent
4ae6fb5a8f
commit
beb193d1e2
|
@ -591,7 +591,9 @@ struct curlFileTransfer : public FileTransfer
|
|||
|
||||
bool quit = false;
|
||||
|
||||
std::chrono::steady_clock::time_point nextWakeup;
|
||||
// NOTE: we will need to use CURLMOPT_TIMERFUNCTION to integrate this
|
||||
// loop with kj. until then curl will handle its timeouts internally.
|
||||
int64_t timeoutMs = INT64_MAX;
|
||||
|
||||
while (!quit) {
|
||||
checkInterrupt();
|
||||
|
@ -616,18 +618,10 @@ struct curlFileTransfer : public FileTransfer
|
|||
}
|
||||
|
||||
/* Wait for activity, including wakeup events. */
|
||||
long maxSleepTimeMs = items.empty() ? 10000 : 100;
|
||||
auto sleepTimeMs =
|
||||
nextWakeup != std::chrono::steady_clock::time_point()
|
||||
? std::max(0, (int) std::chrono::duration_cast<std::chrono::milliseconds>(nextWakeup - std::chrono::steady_clock::now()).count())
|
||||
: maxSleepTimeMs;
|
||||
vomit("download thread waiting for %d ms", sleepTimeMs);
|
||||
mc = curl_multi_poll(curlm, nullptr, 0, sleepTimeMs, nullptr);
|
||||
mc = curl_multi_poll(curlm, nullptr, 0, std::min<int64_t>(timeoutMs, INT_MAX), nullptr);
|
||||
if (mc != CURLM_OK)
|
||||
throw nix::Error("unexpected error from curl_multi_poll(): %s", curl_multi_strerror(mc));
|
||||
|
||||
nextWakeup = std::chrono::steady_clock::time_point();
|
||||
|
||||
/* Add new curl requests from the incoming requests queue,
|
||||
except for requests that are embargoed (waiting for a
|
||||
retry timeout to expire). */
|
||||
|
@ -635,6 +629,8 @@ struct curlFileTransfer : public FileTransfer
|
|||
std::vector<std::shared_ptr<TransferItem>> incoming;
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
|
||||
timeoutMs = INT64_MAX;
|
||||
|
||||
{
|
||||
auto state(state_.lock());
|
||||
for (auto & item : state->unpause) {
|
||||
|
@ -647,9 +643,9 @@ struct curlFileTransfer : public FileTransfer
|
|||
incoming.push_back(item);
|
||||
state->incoming.pop();
|
||||
} else {
|
||||
if (nextWakeup == std::chrono::steady_clock::time_point()
|
||||
|| item->embargo < nextWakeup)
|
||||
nextWakeup = item->embargo;
|
||||
using namespace std::chrono;
|
||||
auto wait = duration_cast<milliseconds>(item->embargo - now);
|
||||
timeoutMs = std::min<int64_t>(timeoutMs, wait.count());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue