diff --git a/server/robotserver/iomgr.cc b/server/robotserver/iomgr.cc new file mode 100644 index 00000000..5f692e8f --- /dev/null +++ b/server/robotserver/iomgr.cc @@ -0,0 +1,39 @@ +#include "precompile.h" + +#include "iomgr.h" + +static const int IC_Max = 4; + +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)); + } +} + +void IoMgr::UnInit() +{ + +} + +std::shared_ptr IoMgr::GetIoContext(int type) +{ + if (type >= 0 && type < io_contexts_.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(); + } +} diff --git a/server/robotserver/iomgr.h b/server/robotserver/iomgr.h new file mode 100644 index 00000000..1f6d55e8 --- /dev/null +++ b/server/robotserver/iomgr.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +#include + +class IoMgr : public a8::Singleton +{ +private: + IoMgr() {}; + friend class a8::Singleton; + +public: + + void Init(); + void UnInit(); + + std::shared_ptr GetIoContext(int type); + + private: + void WorkerThreadProc(std::shared_ptr io_context); + + private: + + std::vector>> io_contexts_; +}; diff --git a/server/robotserver/playermgr.cc b/server/robotserver/playermgr.cc index 030dfee4..aec972e1 100644 --- a/server/robotserver/playermgr.cc +++ b/server/robotserver/playermgr.cc @@ -1,5 +1,7 @@ #include "precompile.h" +#include + #include #include #include @@ -9,6 +11,7 @@ #include "playermgr.h" #include "player.h" #include "httpproxy.h" +#include "iomgr.h" void PlayerMgr::Init() { @@ -33,6 +36,12 @@ void PlayerMgr::Init() abort(); } }); + auto web_socket = std::make_shared + ( + *IoMgr::Instance()->GetIoContext(0), + "192.168.100.21", + 7601 + ); } void PlayerMgr::UnInit() diff --git a/third_party/a8 b/third_party/a8 index 7f568dcb..33a65a4c 160000 --- a/third_party/a8 +++ b/third_party/a8 @@ -1 +1 @@ -Subproject commit 7f568dcbd9a0134fd98b59e20768086c87cda483 +Subproject commit 33a65a4cf309412b9adcce44353293f06cd30010