Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix warnings in unittest #917

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions include/crow/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -702,19 +702,32 @@ namespace crow
}

/// \brief Wait until the server has properly started
void wait_for_server_start()
std::cv_status wait_for_server_start(std::chrono::milliseconds wait_timeout = std::chrono::milliseconds(3000))
{
std::cv_status status = std::cv_status::no_timeout;
auto wait_until = std::chrono::steady_clock::now() + wait_timeout;
{
std::unique_lock<std::mutex> lock(start_mutex_);
while (!server_started_)
cv_started_.wait(lock);
while (!server_started_ && (status == std::cv_status::no_timeout))
{
status = cv_started_.wait_until(lock, wait_until);
}
}
if (server_)
server_->wait_for_start();

if (status == std::cv_status::no_timeout)
{
if (server_)
{
status = server_->wait_for_start(wait_until);
}
#ifdef CROW_ENABLE_SSL
else if (ssl_server_)
ssl_server_->wait_for_start();
else if (ssl_server_)
{
status = ssl_server_->wait_for_start(wait_until);
}
#endif
}
return status;
}

private:
Expand Down
11 changes: 7 additions & 4 deletions include/crow/http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,15 @@ namespace crow // NOTE: Already documented in "crow/app.h"
return acceptor_.local_endpoint().port();
}

/// Wait until the server has properly started
void wait_for_start()
/// Wait until the server has properly started or until timeout
std::cv_status wait_for_start(std::chrono::steady_clock::time_point wait_until)
{
std::unique_lock<std::mutex> lock(start_mutex_);
while (!server_started_)
cv_started_.wait(lock);

std::cv_status status = std::cv_status::no_timeout;
while (!server_started_ && ( status==std::cv_status::no_timeout ))
status = cv_started_.wait_until(lock,wait_until);
return status;
}

void signal_clear()
Expand Down
Loading