From efe7325af3331e8eacb9953663bb66d710e9e174 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Mon, 12 Nov 2018 15:48:03 +0100 Subject: [PATCH] meso: impl AddServerSession --- .../mesosphere/processes/KClientPort.hpp | 1 + .../include/mesosphere/processes/KPort.hpp | 5 ++++- .../mesosphere/processes/KServerPort.hpp | 2 ++ mesosphere/source/processes/KPort.cpp | 17 ++++++++++++++++- mesosphere/source/processes/KServerPort.cpp | 18 +++++++++++++++++- 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/mesosphere/include/mesosphere/processes/KClientPort.hpp b/mesosphere/include/mesosphere/processes/KClientPort.hpp index 1aa721f05..e278d310d 100644 --- a/mesosphere/include/mesosphere/processes/KClientPort.hpp +++ b/mesosphere/include/mesosphere/processes/KClientPort.hpp @@ -27,6 +27,7 @@ class KClientPort final : private: friend class KPort; + std::atomic numSessions{0}, currentCapacity{0}, maxSessions{0}; }; MESOSPHERE_AUTO_OBJECT_DEFINE_INCREF(ClientPort); diff --git a/mesosphere/include/mesosphere/processes/KPort.hpp b/mesosphere/include/mesosphere/processes/KPort.hpp index 2d08c9144..3ca294c6f 100644 --- a/mesosphere/include/mesosphere/processes/KPort.hpp +++ b/mesosphere/include/mesosphere/processes/KPort.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace mesosphere { @@ -20,12 +21,14 @@ class KPort final : virtual ~KPort(); - Result Initialize(); + Result Initialize(int maxSessions, bool isLight); private: friend class KClientPort; friend class KServerPort; + Result AddServerSession(KLightServerSession &lightServerSession); + bool isClientAlive = false; bool isServerAlive = false; bool isLight = false; diff --git a/mesosphere/include/mesosphere/processes/KServerPort.hpp b/mesosphere/include/mesosphere/processes/KServerPort.hpp index 958c5ac71..7b55dd5ab 100644 --- a/mesosphere/include/mesosphere/processes/KServerPort.hpp +++ b/mesosphere/include/mesosphere/processes/KServerPort.hpp @@ -23,7 +23,9 @@ class KServerPort final : private: friend class KPort; + Result AddServerSession(KLightServerSession &lightServerSession); + KLightServerSession::List lightServerSessions{}; }; MESOSPHERE_AUTO_OBJECT_DEFINE_INCREF(ServerPort); diff --git a/mesosphere/source/processes/KPort.cpp b/mesosphere/source/processes/KPort.cpp index d6942c04c..f9d1b9833 100644 --- a/mesosphere/source/processes/KPort.cpp +++ b/mesosphere/source/processes/KPort.cpp @@ -1,5 +1,6 @@ #include #include +#include namespace mesosphere { @@ -8,13 +9,27 @@ KPort::~KPort() { } -Result KPort::Initialize() +Result KPort::Initialize(int maxSessions, bool isLight) { SetClientServerParent(); isClientAlive = true; isServerAlive = true; + client.maxSessions = maxSessions; + this->isLight = isLight; + return ResultSuccess(); } +Result KPort::AddServerSession(KLightServerSession &lightServerSession) +{ + KScopedCriticalSection critsec{}; + if (isClientAlive || isServerAlive) { + return ResultKernelConnectionRefused(); + } else { + return server.AddServerSession(lightServerSession); + } +} + + } diff --git a/mesosphere/source/processes/KServerPort.cpp b/mesosphere/source/processes/KServerPort.cpp index c6fe88479..d91846c92 100644 --- a/mesosphere/source/processes/KServerPort.cpp +++ b/mesosphere/source/processes/KServerPort.cpp @@ -14,7 +14,23 @@ KServerPort::~KServerPort() bool KServerPort::IsSignaled() const { - return false; // TODO + if (!parent->isLight) { + return false; // TODO + } else { + return !lightServerSessions.empty(); + } +} + +Result KServerPort::AddServerSession(KLightServerSession &lightServerSession) +{ + KScopedCriticalSection critsec{}; + bool wasEmpty = lightServerSessions.empty(); + lightServerSessions.push_back(lightServerSession); + if (wasEmpty && !lightServerSessions.empty()) { + NotifyWaiters(); + } + + return ResultSuccess(); } }