From 5928e0af1a81e66f661254c55eda98c000bcb8a1 Mon Sep 17 00:00:00 2001 From: evg82 <61060683+evg82@users.noreply.github.com> Date: Sat, 25 Apr 2020 23:55:20 +0200 Subject: [PATCH] TaskQueue method to internal size adjust (#442) I use a custom TaskQueue, with variable number of workers, adding workers on demand is an easy task when new connection arrive (in enqueue function) however i need another funtion to be called even (or better) went no new connections arrives to reduce workers count. I only added a new virtual method in TaskQueue class to allow custom class to adjust workers size over time. Even if this methods is called frequenlty custom class can keep a "last_update" counter to check if need to adjust worker count or any other internal task. Without this function i need an external thread to make this adjust task. --- httplib.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/httplib.h b/httplib.h index 56a70c1..922a5fb 100644 --- a/httplib.h +++ b/httplib.h @@ -368,6 +368,7 @@ public: TaskQueue() = default; virtual ~TaskQueue() = default; virtual void enqueue(std::function fn) = 0; + virtual void queue_adjust() { }; virtual void shutdown() = 0; }; @@ -3497,6 +3498,7 @@ inline bool Server::listen_internal() { auto val = detail::select_read(svr_sock_, 0, 100000); if (val == 0) { // Timeout + task_queue->queue_adjust(); continue; }