Added DTSC ping command, to keep alive idle connections.

This commit is contained in:
Thulinma 2016-09-02 17:51:19 +02:00
parent 63c0dbb18d
commit 3ae2dc0ae8
2 changed files with 22 additions and 0 deletions

View file

@ -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(){

View file

@ -11,7 +11,9 @@ namespace Mist {
void sendNext();
void sendHeader();
void initialSeek();
void stats(bool force = false);
private:
unsigned int lastActive;///<Time of last sending of data.
std::string getStatsName();
std::string salt;
bool pushing;