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_;