1
0
mirror of synced 2025-04-19 00:24:02 +03:00

Adjust sleep

This commit is contained in:
yhirose 2024-09-05 22:54:28 -04:00
parent c099b42ba3
commit 969a9f99d5

View File

@ -3192,6 +3192,7 @@ private:
inline bool keep_alive(socket_t sock, time_t keep_alive_timeout_sec) { inline bool keep_alive(socket_t sock, time_t keep_alive_timeout_sec) {
using namespace std::chrono; using namespace std::chrono;
auto timeout = keep_alive_timeout_sec * 1000;
auto start = steady_clock::now(); auto start = steady_clock::now();
while (true) { while (true) {
auto val = select_read(sock, 0, 10000); auto val = select_read(sock, 0, 10000);
@ -3199,10 +3200,9 @@ inline bool keep_alive(socket_t sock, time_t keep_alive_timeout_sec) {
return false; return false;
} else if (val == 0) { } else if (val == 0) {
auto current = steady_clock::now(); auto current = steady_clock::now();
auto duration = duration_cast<microseconds>(current - start); auto duration = duration_cast<milliseconds>(current - start);
auto timeout = keep_alive_timeout_sec * 1000 * 1000;
if (duration.count() > timeout) { return false; } if (duration.count() > timeout) { return false; }
std::this_thread::sleep_for(std::chrono::microseconds{1}); std::this_thread::sleep_for(std::chrono::milliseconds{10});
} else { } else {
return true; return true;
} }
@ -4303,7 +4303,7 @@ bool read_content(Stream &strm, T &x, size_t payload_max_length, int &status,
} }
inline ssize_t write_request_line(Stream &strm, const std::string &method, inline ssize_t write_request_line(Stream &strm, const std::string &method,
const std::string &path) { const std::string &path) {
std::string s = method; std::string s = method;
s += " "; s += " ";
s += path; s += path;
@ -6213,7 +6213,7 @@ inline bool Server::is_running() const { return is_running_; }
inline void Server::wait_until_ready() const { inline void Server::wait_until_ready() const {
while (!is_running_ && !is_decommisioned) { while (!is_running_ && !is_decommisioned) {
std::this_thread::sleep_for(std::chrono::microseconds{1}); std::this_thread::sleep_for(std::chrono::milliseconds{1});
} }
} }