From b8624f190a66d88a43b9d9464190c80a213af61f Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 28 Apr 2021 21:17:57 +0200 Subject: [PATCH] Remove static handlers from http server. --- core/http_server.cpp | 11 ++++------- core/http_server.h | 12 ++++++------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/core/http_server.cpp b/core/http_server.cpp index 29760cf..36cfefe 100644 --- a/core/http_server.cpp +++ b/core/http_server.cpp @@ -99,10 +99,10 @@ void HTTPServer::initialize() { builder.setAddr(false, "0.0.0.0", p_port); }); - listenBuilder->configureEnterCallback([](const HttpSession::Ptr &httpSession, HttpSessionHandlers &handlers) { - handlers.setHttpCallback(HTTPServer::httpEnterCallbackDefault); - handlers.setClosedCallback(HTTPServer::closedCallbackDefault); - handlers.setWSCallback(HTTPServer::wsEnterCallbackDefault); + listenBuilder->configureEnterCallback([this](const HttpSession::Ptr &httpSession, HttpSessionHandlers &handlers) { + handlers.setHttpCallback([this](const HTTPParser &httpParser, const HttpSession::Ptr &session){ this->httpEnterCallbackDefault(httpParser, session); }); + handlers.setWSCallback([this](const HttpSession::Ptr &httpSession, WebSocketFormat::WebSocketFrameType opcode, const std::string &payload){ this->wsEnterCallbackDefault(httpSession, opcode, payload); }); + handlers.setClosedCallback([this](const HttpSession::Ptr &session){ this->closedCallbackDefault(session); }); }); listenBuilder->asyncRun(); @@ -130,6 +130,3 @@ HTTPServer::HTTPServer() { HTTPServer::~HTTPServer() { delete listenBuilder; } - -std::map HTTPServer::_request_map; -std::mutex HTTPServer::_request_map_mutex; diff --git a/core/http_server.h b/core/http_server.h index fa155ab..b9f993f 100644 --- a/core/http_server.h +++ b/core/http_server.h @@ -27,11 +27,11 @@ public: std::shared_ptr service; wrapper::HttpListenerBuilder *listenBuilder; - static void http_callback_handler(Request *response); + void http_callback_handler(Request *response); - static void httpEnterCallbackDefault(const HTTPParser &httpParser, const HttpSession::Ptr &session); - static void wsEnterCallbackDefault(const HttpSession::Ptr &httpSession, WebSocketFormat::WebSocketFrameType opcode, const std::string &payload); - static void closedCallbackDefault(const HttpSession::Ptr &session); + void httpEnterCallbackDefault(const HTTPParser &httpParser, const HttpSession::Ptr &session); + void wsEnterCallbackDefault(const HttpSession::Ptr &httpSession, WebSocketFormat::WebSocketFrameType opcode, const std::string &payload); + void closedCallbackDefault(const HttpSession::Ptr &session); virtual void configure(); virtual void initialize(); @@ -42,8 +42,8 @@ public: virtual ~HTTPServer(); protected: - static std::map _request_map; - static std::mutex _request_map_mutex; + std::map _request_map; + std::mutex _request_map_mutex; }; #endif \ No newline at end of file