stop http worker on shutdown

This commit is contained in:
Axel Cocat
2021-08-06 18:24:16 +02:00
parent d7260a0811
commit dd1b8aa71d
2 changed files with 77 additions and 38 deletions

View File

@@ -35,23 +35,26 @@ class HttpManager
{
public:
HttpManager();
~HttpManager();
void PushRequest(HttpWorkItem* item);
void StartHttpWorker();
void StopHttpWorker();
void PushRequest(HttpWorkItem* item);
void HandleHttpResponses();
private:
void ClearQueues();
void HttpWorkerThread();
bool ParseUrl(const std::string& url, std::string& host, std::string& path);
httplib::Result DoRequest(httplib::Client& client, HttpWorkItem* req, const std::string& path);
rigtorp::SPSCQueue<HttpWorkItem*> httpWorkQueue;
rigtorp::SPSCQueue<HttpResponse*> httpResponseQueue;
std::thread httpWorkerThread;
bool startedHttpWorkerThread;
std::atomic_bool httpCancelationToken;
std::condition_variable httpCondVar;
std::mutex httpCondVarMutex;
rigtorp::SPSCQueue<HttpWorkItem*> workQueue;
rigtorp::SPSCQueue<HttpResponse*> responseQueue;
std::thread workerThread;
bool startedWorkerThread;
std::atomic_bool cancelationToken;
std::condition_variable condVar;
std::mutex condVarMutex;
std::regex parseUrlRegex;
};