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] Make signal handler optional #85

Merged
merged 1 commit into from
Dec 20, 2020
Merged
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
19 changes: 19 additions & 0 deletions include/crow/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ namespace crow
return router_.new_rule_tagged<Tag>(std::move(rule));
}

self_t& signal_clear()
{
signals_.clear();
return *this;
}

self_t& signal_add(int signal_number)
{
signals_.push_back(signal_number);
return *this;
}

///Set the port that Crow will handle requests on
self_t& port(std::uint16_t port)
{
Expand Down Expand Up @@ -191,6 +203,11 @@ namespace crow
{
server_ = std::move(std::unique_ptr<server_t>(new server_t(this, bindaddr_, port_, server_name_, &middlewares_, concurrency_, nullptr)));
server_->set_tick_function(tick_interval_, tick_function_);
server_->signal_clear();
for (auto snum : signals_)
{
server_->signal_add(snum);
}
notify_server_start();
server_->run();
}
Expand Down Expand Up @@ -332,6 +349,8 @@ namespace crow
#endif
std::unique_ptr<server_t> server_;

std::vector<int> signals_{SIGINT, SIGTERM};

bool server_started_{false};
std::condition_variable cv_started_;
std::mutex start_mutex_;
Expand Down
10 changes: 10 additions & 0 deletions include/crow/http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ namespace crow
io_service->stop();
}

void signal_clear()
{
signals_.clear();
}

void signal_add(int signal_number)
{
signals_.add(signal_number);
}

private:
asio::io_service& pick_io_service()
{
Expand Down