From 48295756bf604d161515b89a3a9dc95103f0c8ab Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 7 May 2023 01:07:17 +0000 Subject: [PATCH] 1 --- server/wsproxy/constant.h | 7 +++++++ server/wsproxy/iomgr.cc | 11 +++++++++++ server/wsproxy/iomgr.h | 7 +++++++ 3 files changed, 25 insertions(+) diff --git a/server/wsproxy/constant.h b/server/wsproxy/constant.h index 8b27483..bd6c99a 100644 --- a/server/wsproxy/constant.h +++ b/server/wsproxy/constant.h @@ -23,6 +23,13 @@ enum InnerMesssage_e IM_HandleRedirect }; +enum IoContext_e +{ + IC_Master, + IC_Upstream, + IC_Max +}; + //网络处理对象 enum NetHandler_e { diff --git a/server/wsproxy/iomgr.cc b/server/wsproxy/iomgr.cc index 0276de4..05c8e27 100644 --- a/server/wsproxy/iomgr.cc +++ b/server/wsproxy/iomgr.cc @@ -14,4 +14,15 @@ 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()); + } + } + return nullptr; +} + #endif diff --git a/server/wsproxy/iomgr.h b/server/wsproxy/iomgr.h index 2bf963b..bcae64b 100644 --- a/server/wsproxy/iomgr.h +++ b/server/wsproxy/iomgr.h @@ -2,6 +2,8 @@ #ifdef USE_ASIO +#include + class IoMgr : public a8::Singleton { private: @@ -13,6 +15,11 @@ public: void Init(); void UnInit(); + std::shared_ptr GetIoContext(int type); + + private: + + std::vector>> io_contexts_; }; #endif