From 1c17ced79815c94d704bc042f22dc5a0df1df187 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 30 Mar 2022 18:55:34 +0200 Subject: Removed windows header uses in HttpServletExec --- NetEx/HttpServletExec.cpp | 33 ++++++++------------------------- NetEx/HttpServletExec.h | 9 +++++---- 2 files changed, 13 insertions(+), 29 deletions(-) (limited to 'NetEx') diff --git a/NetEx/HttpServletExec.cpp b/NetEx/HttpServletExec.cpp index e7e1c2b..bbd7efe 100644 --- a/NetEx/HttpServletExec.cpp +++ b/NetEx/HttpServletExec.cpp @@ -14,7 +14,9 @@ #include "HttpServletExec.h" #include -#include + +#include +#include #include "HttpRequest.h" #include "HttpResponse.h" @@ -93,18 +95,13 @@ public: }; -DWORD WINAPI HttpServletExecSessionProc(LPVOID link); - - -HttpServletExec::HttpServletExec(WORD port, int poolsize) : +HttpServletExec::HttpServletExec(std::uint16_t port, int poolsize) : HttpServer(port, poolsize), session_timeout(60), exec_shutdown(false) { http_server_name = "Generic HttpServletExec 1.0"; - - DWORD thread_id = 0; - hsession = CreateThread(0, 4096, HttpServletExecSessionProc, (LPVOID) this, 0, &thread_id); + hsession = std::thread([&]{ CheckSessions(); }); } @@ -113,9 +110,8 @@ HttpServletExec::~HttpServletExec() if (!exec_shutdown) exec_shutdown = true; - WaitForSingleObject(hsession, 1000); - CloseHandle(hsession); - hsession = 0; + if (hsession.joinable()) + hsession.join(); sessions.destroy(); } @@ -189,18 +185,7 @@ HttpServletExec::DoGet(HttpRequest& request, HttpResponse& response) } -DWORD WINAPI HttpServletExecSessionProc(LPVOID link) -{ - HttpServletExec* exec = (HttpServletExec*) link; - - if (exec) - return exec->CheckSessions(); - - return (DWORD) E_POINTER; -} - - -DWORD +void HttpServletExec::CheckSessions() { while (!exec_shutdown) { @@ -223,8 +208,6 @@ HttpServletExec::CheckSessions() sync.unlock(); Sleep(100); } - - return 0; } diff --git a/NetEx/HttpServletExec.h b/NetEx/HttpServletExec.h index 8c9fd2b..8f06d73 100644 --- a/NetEx/HttpServletExec.h +++ b/NetEx/HttpServletExec.h @@ -14,7 +14,8 @@ #ifndef HttpServletExec_h #define HttpServletExec_h -#include +#include +#include #include "HttpRequest.h" #include "HttpResponse.h" @@ -29,7 +30,7 @@ class HttpServletExec : public HttpServer public: static const char* TYPENAME() { return "HttpServletExec"; } - HttpServletExec(WORD port, int poolsize=1); + HttpServletExec(std::uint16_t port, int poolsize=1); virtual ~HttpServletExec(); int operator == (const HttpServletExec& l) const { return addr == l.addr; } @@ -39,7 +40,7 @@ public: virtual HttpServlet* GetServlet(HttpRequest& request); virtual HttpSession* GetSession(HttpRequest& request); - virtual DWORD CheckSessions(); + virtual void CheckSessions(); virtual int GetSessionTimeout() const { return session_timeout; } virtual void SetSessionTimeout(int t) { session_timeout = t; } @@ -49,7 +50,7 @@ protected: List sessions; int session_timeout; - HANDLE hsession; + std::thread hsession; bool exec_shutdown; }; -- cgit v1.1