@@ -270,6 +270,15 @@ std::string ConcatenateDnsAddresses(
270
270
271
271
return result;
272
272
}
273
+
274
+ // Returns an integer value of the duration in specified representation.
275
+ // Casts to long, as long is a type expected by `curl_easy_setopt`
276
+ template <typename ToDuration, typename Duration>
277
+ long CountIn (Duration&& duration) {
278
+ const auto count = std::chrono::duration_cast<ToDuration>(duration).count ();
279
+ return static_cast <long >(count);
280
+ }
281
+
273
282
} // anonymous namespace
274
283
275
284
NetworkCurl::NetworkCurl (NetworkInitializationSettings settings)
@@ -671,12 +680,19 @@ ErrorCode NetworkCurl::SendImplementation(
671
680
#endif
672
681
673
682
curl_easy_setopt (handle->handle , CURLOPT_FOLLOWLOCATION, 1L );
683
+
684
+ // `::count` is defined on all duration types, to be on the safe side
685
+ // regarding durations on NetworkConfig. Refactoring of NetworkConfig to
686
+ // return different types will be handled gracefully here. Force specific type
687
+ // of the representation & type expected by curl.
688
+ const long connect_timeout_ms =
689
+ CountIn<std::chrono::milliseconds>(config.GetConnectionTimeoutDuration ());
690
+ const long timeout_ms =
691
+ CountIn<std::chrono::milliseconds>(config.GetTransferTimeoutDuration ());
692
+
674
693
curl_easy_setopt (handle->handle , CURLOPT_CONNECTTIMEOUT_MS,
675
- config.GetConnectionTimeoutDuration ().count ());
676
- curl_easy_setopt (handle->handle , CURLOPT_SERVER_RESPONSE_TIMEOUT,
677
- std::chrono::duration_cast<std::chrono::seconds>(
678
- config.GetTransferTimeoutDuration ())
679
- .count ());
694
+ connect_timeout_ms);
695
+ curl_easy_setopt (handle->handle , CURLOPT_TIMEOUT_MS, timeout_ms);
680
696
curl_easy_setopt (handle->handle , CURLOPT_WRITEFUNCTION,
681
697
&NetworkCurl::RxFunction);
682
698
curl_easy_setopt (handle->handle , CURLOPT_WRITEDATA, handle);
0 commit comments