From bf89c6a3c1039c5832bfcd64b24d083a2f78c99d Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 19 Apr 2018 11:08:05 +0200 Subject: [PATCH] Implemented ?stream=STREAMNAME in load balancer --- src/utils/util_load.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/utils/util_load.cpp b/src/utils/util_load.cpp index 3a49234c..d71b0986 100644 --- a/src/utils/util_load.cpp +++ b/src/utils/util_load.cpp @@ -168,6 +168,13 @@ public: r[jt->first] = r[jt->first].asInt() + jt->second.total; } } + /// Returns viewcount for the given stream + long long getViewers(const std::string &strm){ + if (!hostMutex){hostMutex = new tthread::mutex();} + tthread::lock_guard guard(*hostMutex); + if (!streams.count(strm)){return 0;} + return streams[strm].total; + } /// Scores a potential new connection to this server /// 0 means not possible, the higher the better. unsigned int rate(std::string &s, double lati = 0, double longi = 0){ @@ -369,6 +376,7 @@ int handleRequest(Socket::Connection &conn){ } std::string host = H.GetVar("host"); std::string viewers = H.GetVar("viewers"); + std::string stream = H.GetVar("stream"); std::string source = H.GetVar("source"); std::string fback = H.GetVar("fallback"); std::string lstserver = H.GetVar("lstserver"); @@ -472,6 +480,17 @@ int handleRequest(Socket::Connection &conn){ H.Clean(); continue; } + if (stream.size()){ + long long count = 0; + for (HOSTLOOP){ + HOSTCHECK; + count += HOST(i).details->getViewers(stream); + } + H.SetBody(JSON::Value(count).asString()); + H.SendResponse("200", "OK", conn); + H.Clean(); + continue; + } // Find source for given stream if (source.size()){ INFO_MSG("Finding source for stream %s", source.c_str());