* Transmit the survey. * * @param reason The reason for sending the survey. * @param blocking Whether to block until the survey is sent. */
| 84 | * @param blocking Whether to block until the survey is sent. |
| 85 | */ |
| 86 | void NetworkSurveyHandler::Transmit(Reason reason, bool blocking) |
| 87 | { |
| 88 | if constexpr (!NetworkSurveyHandler::IsSurveyPossible()) { |
| 89 | Debug(net, 4, "Survey: not possible to send survey; most likely due to missing JSON library at compile-time"); |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | if (_settings_client.network.participate_survey != PS_YES) { |
| 94 | Debug(net, 5, "Survey: user is not participating in survey; skipping survey"); |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | Debug(net, 1, "Survey: sending survey results"); |
| 99 | NetworkHTTPSocketHandler::Connect(NetworkSurveyUriString(), this, this->CreatePayload(reason)); |
| 100 | |
| 101 | if (blocking) { |
| 102 | std::unique_lock<std::mutex> lock(this->mutex); |
| 103 | |
| 104 | /* Block no longer than 2 seconds. If we failed to send the survey in that time, so be it. */ |
| 105 | std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now() + std::chrono::seconds(2); |
| 106 | |
| 107 | while (!this->transmitted && std::chrono::steady_clock::now() < end) { |
| 108 | NetworkBackgroundLoop(); |
| 109 | this->transmitted_cv.wait_for(lock, std::chrono::milliseconds(30)); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | void NetworkSurveyHandler::OnFailure() |
| 115 | { |
no test coverage detected