From 3ae2dc0ae88b0977660d3ce673c31a28be70e9a5 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Fri, 2 Sep 2016 17:51:19 +0200 Subject: [PATCH] Added DTSC ping command, to keep alive idle connections. --- src/output/output_dtsc.cpp | 20 ++++++++++++++++++++ src/output/output_dtsc.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/output/output_dtsc.cpp b/src/output/output_dtsc.cpp index 0f8afe0e..063b8420 100644 --- a/src/output/output_dtsc.cpp +++ b/src/output/output_dtsc.cpp @@ -29,10 +29,29 @@ namespace Mist { myConn.SendNow(sSize, 4); prep.sendTo(myConn); pushing = false; + lastActive = Util::epoch(); } OutDTSC::~OutDTSC() {} + + void OutDTSC::stats(bool force){ + unsigned long long int now = Util::epoch(); + if (now - lastActive > 1 && !pushing){ + MEDIUM_MSG("Ping!"); + JSON::Value prep; + prep["cmd"] = "ping"; + unsigned long sendSize = prep.packedSize(); + myConn.SendNow("DTCM"); + char sSize[4] = {0, 0, 0, 0}; + Bit::htobl(sSize, prep.packedSize()); + myConn.SendNow(sSize, 4); + prep.sendTo(myConn); + lastActive = now; + } + Output::stats(force); + } + void OutDTSC::init(Util::Config * cfg){ Output::init(cfg); capa["name"] = "DTSC"; @@ -109,6 +128,7 @@ namespace Mist { } } myConn.SendNow(thisPacket.getData(), thisPacket.getDataLen()); + lastActive = Util::epoch(); } void OutDTSC::sendHeader(){ diff --git a/src/output/output_dtsc.h b/src/output/output_dtsc.h index 7721fe38..df379b53 100644 --- a/src/output/output_dtsc.h +++ b/src/output/output_dtsc.h @@ -11,7 +11,9 @@ namespace Mist { void sendNext(); void sendHeader(); void initialSeek(); + void stats(bool force = false); private: + unsigned int lastActive;///