From e41ffbd58fefdf9e78a4d6fdf354eb37f387c5db Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 7 May 2023 01:55:19 +0000 Subject: [PATCH] 1 --- server/wsproxy/iomgr.cc | 17 ++++++++++++++--- server/wsproxy/iomgr.h | 3 +++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/server/wsproxy/iomgr.cc b/server/wsproxy/iomgr.cc index 460f1c7..a130c21 100644 --- a/server/wsproxy/iomgr.cc +++ b/server/wsproxy/iomgr.cc @@ -8,6 +8,9 @@ void IoMgr::Init() { for (int i = 0; i < IC_Max; ++i) { io_contexts_.push_back(std::vector>()); + auto& contexts = io_contexts_.at(i); + contexts.push_back(std::make_shared()); + new std::thread(&IoMgr::WorkerThreadProc, this, contexts.at(0)); } } @@ -19,12 +22,20 @@ void IoMgr::UnInit() std::shared_ptr IoMgr::GetIoContext(int type) { if (type >= 0 && type < io_contexts_.size()) { - auto& s = io_contexts_.at(type); - if (s.empty()) { - return s.at(rand() % s.size()); + auto& contexts = io_contexts_.at(type); + if (contexts.empty()) { + return contexts.at(rand() % contexts.size()); } } return nullptr; } +void IoMgr::WorkerThreadProc(std::shared_ptr io_context) +{ + while (true) { + io_context->run(); + io_context->reset(); + } +} + #endif diff --git a/server/wsproxy/iomgr.h b/server/wsproxy/iomgr.h index bcae64b..4008af8 100644 --- a/server/wsproxy/iomgr.h +++ b/server/wsproxy/iomgr.h @@ -17,6 +17,9 @@ public: std::shared_ptr GetIoContext(int type); + private: + void WorkerThreadProc(std::shared_ptr io_context); + private: std::vector>> io_contexts_;