Replies: 2 comments
-
You can use app.close() |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks!, that works fine when the uWS::App is on the stack (? I'm trying to wrap the app in a singleton in order to gracefully close once a signal comes but it crashes in that case when calling the
void Application::configure_server()
{
app.get("/stop", [this](auto *res, auto *) {
res->end("Server stopped");
stop();
});
app.listen("0.0.0.0", 8080, [this](auto *socket) {
if (socket != nullptr) {
logger->info("Server listening on {}:{}", "0.0.0.0", 8080);
}
});
}
void Application::stop()
{
const auto loop = app.getLoop();
loop->defer([this] {
logger->warn("Stopping server...");
app.close();
});
}
class Application
{
public:
Application(Application const &) = delete;
Application &operator=(Application const &) = delete;
Application(Application &&) = delete;
Application &operator=(Application &&) = delete;
static auto instance() -> std::shared_ptr<Application>
{
static const std::shared_ptr<Application> ptr{new Application()};
return ptr;
}
void stop();
void run();
private:
Application();
std::shared_ptr<spdlog::logger> logger;
uWS::App app;
std::vector<std::shared_ptr<BaseController>> controllers;
void create_loggers();
void register_controllers();
void configure_server();
};
#include "application.hpp"
int main()
{
const auto app = Application::instance();
app->run();
return 0;
} Seems to be crashing on the Could it be a bug? Thanks for the help and the awesome library. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to develop a simple rest api but when trying to gracefully stop the server I'm getting a
0xC0000005
error on windows. According to previous discussions this should be the correct way to do it but the error is showing up. Perhaps this is an issue with only windows and doesn't show on linux/macos.Beta Was this translation helpful? Give feedback.
All reactions