Remove static handlers from http server.

This commit is contained in:
Relintai 2021-04-28 21:17:57 +02:00
parent 23d085794c
commit b8624f190a
2 changed files with 10 additions and 13 deletions

View File

@ -99,10 +99,10 @@ void HTTPServer::initialize() {
builder.setAddr(false, "0.0.0.0", p_port); builder.setAddr(false, "0.0.0.0", p_port);
}); });
listenBuilder->configureEnterCallback([](const HttpSession::Ptr &httpSession, HttpSessionHandlers &handlers) { listenBuilder->configureEnterCallback([this](const HttpSession::Ptr &httpSession, HttpSessionHandlers &handlers) {
handlers.setHttpCallback(HTTPServer::httpEnterCallbackDefault); handlers.setHttpCallback([this](const HTTPParser &httpParser, const HttpSession::Ptr &session){ this->httpEnterCallbackDefault(httpParser, session); });
handlers.setClosedCallback(HTTPServer::closedCallbackDefault); handlers.setWSCallback([this](const HttpSession::Ptr &httpSession, WebSocketFormat::WebSocketFrameType opcode, const std::string &payload){ this->wsEnterCallbackDefault(httpSession, opcode, payload); });
handlers.setWSCallback(HTTPServer::wsEnterCallbackDefault); handlers.setClosedCallback([this](const HttpSession::Ptr &session){ this->closedCallbackDefault(session); });
}); });
listenBuilder->asyncRun(); listenBuilder->asyncRun();
@ -130,6 +130,3 @@ HTTPServer::HTTPServer() {
HTTPServer::~HTTPServer() { HTTPServer::~HTTPServer() {
delete listenBuilder; delete listenBuilder;
} }
std::map<HttpSession *, Request *> HTTPServer::_request_map;
std::mutex HTTPServer::_request_map_mutex;

View File

@ -27,11 +27,11 @@ public:
std::shared_ptr<TcpService> service; std::shared_ptr<TcpService> service;
wrapper::HttpListenerBuilder *listenBuilder; 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); void httpEnterCallbackDefault(const HTTPParser &httpParser, const HttpSession::Ptr &session);
static void wsEnterCallbackDefault(const HttpSession::Ptr &httpSession, WebSocketFormat::WebSocketFrameType opcode, const std::string &payload); void wsEnterCallbackDefault(const HttpSession::Ptr &httpSession, WebSocketFormat::WebSocketFrameType opcode, const std::string &payload);
static void closedCallbackDefault(const HttpSession::Ptr &session); void closedCallbackDefault(const HttpSession::Ptr &session);
virtual void configure(); virtual void configure();
virtual void initialize(); virtual void initialize();
@ -42,8 +42,8 @@ public:
virtual ~HTTPServer(); virtual ~HTTPServer();
protected: protected:
static std::map<HttpSession *, Request *> _request_map; std::map<HttpSession *, Request *> _request_map;
static std::mutex _request_map_mutex; std::mutex _request_map_mutex;
}; };
#endif #endif