diff options
author | ipknHama <ipknhama@gmail.com> | 2017-12-25 00:40:39 +0900 |
---|---|---|
committer | ipknHama <ipknhama@gmail.com> | 2017-12-25 15:31:20 +0900 |
commit | b7360a2bacb426401636a1e76e5e713ed0c3b0fc (patch) | |
tree | 20fcc49e00bd9878887f46153a84bdb7625fd23f /include/crow/app.h | |
parent | daa1e3eadcfb99bde158a6a9d9455d113b005df5 (diff) | |
download | crow-b7360a2bacb426401636a1e76e5e713ed0c3b0fc.tar.gz crow-b7360a2bacb426401636a1e76e5e713ed0c3b0fc.zip |
Support multiple methods for same URL
- fix broken unittests because of server initializing order change
- add a function to wait until server is up
Diffstat (limited to 'include/crow/app.h')
-rw-r--r-- | include/crow/app.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/crow/app.h b/include/crow/app.h index b454bf0..a380a79 100644 --- a/include/crow/app.h +++ b/include/crow/app.h @@ -8,6 +8,7 @@ #include <cstdint> #include <type_traits> #include <thread> +#include <condition_variable> #include "crow/settings.h" #include "crow/logging.h" @@ -95,6 +96,13 @@ namespace crow router_.validate(); } + void notify_server_start() + { + std::unique_lock<std::mutex> lock(start_mutex_); + server_started_ = true; + cv_started_.notify_all(); + } + void run() { validate(); @@ -103,6 +111,7 @@ namespace crow { ssl_server_ = std::move(std::unique_ptr<ssl_server_t>(new ssl_server_t(this, bindaddr_, port_, &middlewares_, concurrency_, &ssl_context_))); ssl_server_->set_tick_function(tick_interval_, tick_function_); + notify_server_start(); ssl_server_->run(); } else @@ -110,6 +119,7 @@ namespace crow { server_ = std::move(std::unique_ptr<server_t>(new server_t(this, bindaddr_, port_, &middlewares_, concurrency_, nullptr))); server_->set_tick_function(tick_interval_, tick_function_); + notify_server_start(); server_->run(); } } @@ -226,6 +236,14 @@ namespace crow return *this; } + void wait_for_server_start() + { + std::unique_lock<std::mutex> lock(start_mutex_); + if (server_started_) + return; + cv_started_.wait(lock); + } + private: uint16_t port_ = 80; uint16_t concurrency_ = 1; @@ -241,6 +259,10 @@ namespace crow std::unique_ptr<ssl_server_t> ssl_server_; #endif std::unique_ptr<server_t> server_; + + bool server_started_{false}; + std::condition_variable cv_started_; + std::mutex start_mutex_; }; template <typename ... Middlewares> using App = Crow<Middlewares...>; |