From f68dc50d5b1bb0aee9bbdecc93eae93a8b2e513c Mon Sep 17 00:00:00 2001 From: malloc Date: Fri, 13 Apr 2018 15:57:30 -0500 Subject: [PATCH] oblong pools --- server/CMakeLists.txt | 2 +- server/src/db/database.cpp | 1 + server/src/db/database.hpp | 11 ++++++++++ server/src/main.cpp | 2 +- server/src/sock/pool.hpp | 41 ++++++++++++++++++++++++++++++++++---- 5 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 server/src/db/database.cpp create mode 100644 server/src/db/database.hpp diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 545177f..9e53827 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.6) -project(server) +project(server) file(GLOB_RECURSE server_src "src/*.hpp" diff --git a/server/src/db/database.cpp b/server/src/db/database.cpp new file mode 100644 index 0000000..85ca9b7 --- /dev/null +++ b/server/src/db/database.cpp @@ -0,0 +1 @@ +#include "database.hpp" diff --git a/server/src/db/database.hpp b/server/src/db/database.hpp new file mode 100644 index 0000000..d467dfc --- /dev/null +++ b/server/src/db/database.hpp @@ -0,0 +1,11 @@ +#ifndef SOSC_DATABASE_H +#define SOSC_DATABASE_H + +#include "sqlite/sqlite3.h" + +namespace sosc { +namespace db { + +}} + +#endif diff --git a/server/src/main.cpp b/server/src/main.cpp index 88b0ff6..4d41a44 100644 --- a/server/src/main.cpp +++ b/server/src/main.cpp @@ -37,7 +37,7 @@ int main(int argc, char **argv) { bool loop = true; while(loop) { - if(!client.Handshaked()) + if(!client.Handshaked()) client.Handshake(); else { sosc::Packet pck; diff --git a/server/src/sock/pool.hpp b/server/src/sock/pool.hpp index a3d9295..0e9ae04 100644 --- a/server/src/sock/pool.hpp +++ b/server/src/sock/pool.hpp @@ -1,7 +1,6 @@ #ifndef SOSC_POOL_H #define SOSC_POOL_H -#include #include #include #include @@ -42,7 +41,7 @@ protected: private: class Stack { public: - Stack(Pool *pool); + Stack(Pool* pool); void Start(); void AddClient(T* client); @@ -50,6 +49,8 @@ private: void Stop(); private: + void StackThread(); + std::thread thread; Pool *pool; bool is_open; @@ -61,6 +62,7 @@ private: poolinfo_t info; bool is_running; std::vector stacks; + friend class Stack; }; @@ -72,7 +74,7 @@ Pool::Pool(const poolinfo_t& info) { template void Pool::Start() { - if(this->is_running == true) + if(this->is_running) return; for(int i = 0; i < this->info.initial_count; ++i) { @@ -85,18 +87,49 @@ void Pool::Start() { template bool Pool::AddClient(T* client) { - + // TODO return false; } template int Pool::ClientCount() const { + if(!this->is_running) + return 0; + int count = 0; for(auto i = this->stacks.begin(); i != this->stacks.end(); ++i) count += i->ClientCount(); return count; } + +template +void Pool::Stop() { + if(!this->is_running) + return; + + for(auto i = this->stacks.begin(); i != this->stacks.end(); ++i) + i->Stop(); + + stacks->clear(); + this->is_running = false; +} + +template +Pool::Stack::Stack(Pool* pool) { + this->pool = pool; + this->is_open = false; +} + +template +void Pool::Stack::Start() { + if(this->is_open) + return; + + this->thread = std::thread(this->StackThread, this); + + this->is_open = true; +} } #endif