mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-11-22 20:11:46 +00:00
Let the parking loop wait without a cap when nothing is due
parking_loop capped every Poller::wait() at one minute only to keep the millisecond timeout within an int, so an idle server woke once a minute for nothing. detail::poll_timeout_until() turns a deadline into the timeout instead: -1 when there is none, which Poller::wait() already defines as waiting until a descriptor is ready or wake() is called, otherwise whole milliseconds, rounded up and capped at INT_MAX. The rounding is now exact: adding 999 us turned a deadline 1 ns away into a timeout of 0. The loop relies on a negative timeout for the first time, so the Poller contract tests now check it on every backend.
This commit is contained in:
1 parent
51b186974b
commit
0fe58217ea
2 files changed
+49
-10
No files matched your search
@@ -34049,6 +34049,20 @@ TEST_P(PollerTest, WaitHonoursItsTimeout) {
|
||||
EXPECT_LT(elapsed, std::chrono::seconds(1));
|
||||
}
|
||||
|
||||
TEST_P(PollerTest, NegativeTimeoutWaitsUntilReady) {
|
||||
TestSocketPair sp;
|
||||
ASSERT_TRUE(sp.ok());
|
||||
ASSERT_TRUE(poller_->arm(sp.reader(), 3));
|
||||
std::thread writer([&] {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||
sp.make_readable();
|
||||
});
|
||||
|
||||
auto ready = wait_for(-1);
|
||||
writer.join();
|
||||
EXPECT_EQ(Tokens{3}, ready);
|
||||
}
|
||||
|
||||
TEST_P(PollerTest, OnlyTheReadyDescriptorsAreDelivered) {
|
||||
std::vector<std::unique_ptr<TestSocketPair>> sps;
|
||||
for (detail::Poller::Token i = 0; i < 8; i++) {
|
||||
@@ -34167,6 +34181,20 @@ TEST(PollerFactoryTest, MakePollerWorks) {
|
||||
EXPECT_TRUE(poller->wait(1000, ready));
|
||||
}
|
||||
|
||||
TEST(PollTimeoutTest, LastsUntilTheDeadline) {
|
||||
using namespace std::chrono;
|
||||
const auto now = steady_clock::now();
|
||||
auto timeout = [&](steady_clock::time_point deadline) {
|
||||
return detail::poll_timeout_until(deadline, now);
|
||||
};
|
||||
EXPECT_EQ(-1, timeout((steady_clock::time_point::max)()));
|
||||
EXPECT_EQ(0, timeout(now - milliseconds(5)));
|
||||
EXPECT_EQ(1, timeout(now + nanoseconds(1)));
|
||||
EXPECT_EQ(1, timeout(now + milliseconds(1)));
|
||||
EXPECT_EQ(2, timeout(now + microseconds(1001)));
|
||||
EXPECT_EQ((std::numeric_limits<int>::max)(), timeout(now + hours(1000)));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Keep-alive parking
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user