mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 16:57:16 +01:00
4a6bfc086c
Switched to POCO library for unified platform/library interface. Deprecated the external module API. It was creating more problems than solving. Removed most built-in libraries in favor of system libraries for easier maintenance. Cleaned and secured code with help from static analyzers.
35 lines
1.1 KiB
C++
35 lines
1.1 KiB
C++
#include "cpr/timeout.h"
|
|
|
|
#include <limits>
|
|
#include <stdexcept>
|
|
#include <type_traits>
|
|
#include <string>
|
|
|
|
namespace cpr {
|
|
|
|
// No way around since curl uses a long here.
|
|
// NOLINTNEXTLINE(google-runtime-int)
|
|
long Timeout::Milliseconds() const {
|
|
static_assert(std::is_same<std::chrono::milliseconds, decltype(ms)>::value,
|
|
"Following casting expects milliseconds.");
|
|
|
|
// No way around since curl uses a long here.
|
|
// NOLINTNEXTLINE(google-runtime-int)
|
|
if (ms.count() > std::numeric_limits<long>::max()) {
|
|
throw std::overflow_error(
|
|
"cpr::Timeout: timeout value overflow: " + std::to_string(ms.count()) + " ms.");
|
|
}
|
|
// No way around since curl uses a long here.
|
|
// NOLINTNEXTLINE(google-runtime-int)
|
|
if (ms.count() < std::numeric_limits<long>::min()) {
|
|
throw std::underflow_error(
|
|
"cpr::Timeout: timeout value underflow: " + std::to_string(ms.count()) + " ms.");
|
|
}
|
|
|
|
// No way around since curl uses a long here.
|
|
// NOLINTNEXTLINE(google-runtime-int)
|
|
return static_cast<long>(ms.count());
|
|
}
|
|
|
|
} // namespace cpr
|