if (totalTimeout) {
time_t now = time(nullptr);
const auto elapsed = now - start;
- if (elapsed > 0 && elapsed >= static_cast<decltype(elapsed)>(remainingTotal)) {
+ if (elapsed >= static_cast<decltype(elapsed)>(remainingTotal)) {
throw NetworkError("Timeout while reading data");
}
start = now;
- remainingTotal -= elapsed;
+ if (elapsed > 0) {
+ remainingTotal -= elapsed;
+ }
}
}
return n;
{
if (maxConnectionDuration) {
time_t elapsed = time(nullptr) - start;
- if (elapsed > 0 && elapsed >= maxConnectionDuration) {
+ if (elapsed >= maxConnectionDuration) {
return true;
}
- remainingTime = static_cast<unsigned int >(maxConnectionDuration - elapsed);
+ if (elapsed > 0) {
+ remainingTime = static_cast<unsigned int >(maxConnectionDuration - elapsed);
+ }
}
return false;
}