Give WebSocketClient the chrono::duration timeout setters ClientImpl has

WebSocketClient only accepted timeouts as (time_t sec, time_t usec), while
ClientImpl has taken std::chrono::duration overloads for its read, write and
connection timeouts for a long time. Add the same three overloads, forwarding
through the existing detail::duration_to_sec_and_usec helper so the split
matches ClientImpl exactly.

The template bodies go above the first split.py BORDER, next to the class, so
that the .h/.cc split keeps them in the header where instantiation needs them.
This commit is contained in:
yhirose committed 2026-08-07 13:41:38 -04:00
1 parent b2b1d56d6d
commit a1aa2ad9cd
2 files changed
+55

No files matched your search

+22
View File
@@ -20487,6 +20487,28 @@ TEST_F(WebSocketIntegrationTest, SocketSettings) {
client.close();
}
TEST_F(WebSocketIntegrationTest, ChronoTimeoutSetters) {
ws::WebSocketClient client("ws://localhost:" + std::to_string(port_) +
"/ws-echo");
client.set_connection_timeout(std::chrono::seconds(3));
client.set_write_timeout(std::chrono::seconds(3));
// A sub-second remainder exercises the seconds/microseconds split.
client.set_read_timeout(std::chrono::milliseconds(1500));
ASSERT_TRUE(client.connect());
auto start = std::chrono::steady_clock::now();
std::string msg;
EXPECT_EQ(client.read(msg), ws::ReadResult::Fail);
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - start)
.count();
// Above 1s so that dropping the microseconds half of the split fails here,
// and well under the 300s default so that ignoring the setter fails too.
EXPECT_GE(elapsed, 1400);
EXPECT_LT(elapsed, 30000);
}
TEST(WebSocketPreRoutingTest, RejectWithoutAuth) {
Server svr;