From ee220daeef25057083545713ded32c24e712f3d5 Mon Sep 17 00:00:00 2001 From: rayburgemeestre Date: Sun, 19 Jun 2016 12:50:40 +0200 Subject: [PATCH] expose server stop() in Crow app to allow shutdown other than signal. --- include/crow.h | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/include/crow.h b/include/crow.h index 31b96cbe8..aff671698 100644 --- a/include/crow.h +++ b/include/crow.h @@ -94,14 +94,28 @@ namespace crow #ifdef CROW_ENABLE_SSL if (use_ssl_) { - ssl_server_t server(this, bindaddr_, port_, &middlewares_, concurrency_, &ssl_context_); - server.run(); + ssl_server_ = std::move(std::unique_ptr(new ssl_server_t(this, bindaddr_, port_, &middlewares_, concurrency_, &ssl_context_))); + ssl_server_->run(); } else #endif { - server_t server(this, bindaddr_, port_, &middlewares_, concurrency_, nullptr); - server.run(); + server_ = std::move(std::unique_ptr(new server_t(this, bindaddr_, port_, &middlewares_, concurrency_, nullptr))); + server_->run(); + } + } + + void stop() + { +#ifdef CROW_ENABLE_SSL + if (use_ssl_) + { + ssl_server_->stop(); + } + else +#endif + { + server_->stop(); } } @@ -197,6 +211,11 @@ namespace crow Router router_; std::tuple middlewares_; + +#ifdef CROW_ENABLE_SSL + std::unique_ptr ssl_server_; +#endif + std::unique_ptr server_; }; template using App = Crow;