mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
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.
This commit is contained in:
parent
a5005789ff
commit
5928e0af1a
1 changed files with 2 additions and 0 deletions
|
@ -368,6 +368,7 @@ public:
|
|||
TaskQueue() = default;
|
||||
virtual ~TaskQueue() = default;
|
||||
virtual void enqueue(std::function<void()> 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue