Skip to content

Commit 5d8c9ed

Browse files
authored
Merge pull request #1215 from pntzio/fix-y2038-lowspeed
Changed LowSpeed to use std::chrono
2 parents c6f02b4 + de969e6 commit 5d8c9ed

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

include/cpr/low_speed.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
#define CPR_LOW_SPEED_H
33

44
#include <cstdint>
5+
#include <chrono>
56

67
namespace cpr {
78

89
class LowSpeed {
910
public:
10-
LowSpeed(const std::int32_t p_limit, const std::int32_t p_time) : limit(p_limit), time(p_time) {}
11+
12+
[[deprecated("Will be removed in CPR 2.x - Use the constructor with std::chrono::seconds instead of std::int32_t")]]
13+
LowSpeed(const std::int32_t p_limit, const std::int32_t p_time) : limit(p_limit), time(std::chrono::seconds(p_time)) {}
14+
15+
LowSpeed(const std::int32_t p_limit, const std::chrono::seconds p_time) : limit(p_limit), time(p_time) {}
1116

1217
std::int32_t limit;
13-
std::int32_t time;
18+
std::chrono::seconds time;
1419
};
1520

1621
} // namespace cpr

test/error_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ TEST(ErrorTests, ChronoConnectTimeoutFailure) {
5959

6060
TEST(ErrorTests, LowSpeedTimeFailure) {
6161
Url url{server->GetBaseUrl() + "/low_speed.html"};
62-
Response response = cpr::Get(url, cpr::LowSpeed{1000, 1});
62+
Response response = cpr::Get(url, cpr::LowSpeed{1000, std::chrono::seconds(1)});
6363
// Do not check for the HTTP status code, since libcurl always provides the status code of the header if it was received
6464
EXPECT_EQ(ErrorCode::OPERATION_TIMEDOUT, response.error.code);
6565
}
6666

6767
TEST(ErrorTests, LowSpeedBytesFailure) {
6868
Url url{server->GetBaseUrl() + "/low_speed_bytes.html"};
69-
Response response = cpr::Get(url, cpr::LowSpeed{1000, 1});
69+
Response response = cpr::Get(url, cpr::LowSpeed{1000, std::chrono::seconds(1)});
7070
// Do not check for the HTTP status code, since libcurl always provides the status code of the header if it was received
7171
EXPECT_EQ(ErrorCode::OPERATION_TIMEDOUT, response.error.code);
7272
}

test/session_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ TEST(LowSpeedTests, SetLowSpeedTest) {
591591
Url url{server->GetBaseUrl() + "/hello.html"};
592592
Session session;
593593
session.SetUrl(url);
594-
session.SetLowSpeed({1, 1});
594+
session.SetLowSpeed({1, std::chrono::seconds(1)});
595595
Response response = session.Get();
596596
std::string expected_text{"Hello world!"};
597597
EXPECT_EQ(expected_text, response.text);

0 commit comments

Comments
 (0)