Added 5 minute timeout to idle connections

This commit is contained in:
Thulinma 2017-01-15 17:35:00 +01:00
parent b106a1eede
commit 40f1cec8f9
2 changed files with 10 additions and 2 deletions

View file

@ -44,6 +44,7 @@ namespace Mist{
maxSkipAhead = 7500; maxSkipAhead = 7500;
minSkipAhead = 5000; minSkipAhead = 5000;
realTime = 1000; realTime = 1000;
lastRecv = Util::epoch();
if (myConn){ if (myConn){
setBlocking(true); setBlocking(true);
}else{ }else{
@ -658,14 +659,20 @@ namespace Mist{
static bool firstData = true;//only the first time, we call onRequest if there's data buffered already. static bool firstData = true;//only the first time, we call onRequest if there's data buffered already.
if ((firstData && myConn.Received().size()) || myConn.spool()){ if ((firstData && myConn.Received().size()) || myConn.spool()){
firstData = false; firstData = false;
DEBUG_MSG(DLVL_DONTEVEN, "onRequest"); DONTEVEN_MSG("onRequest");
onRequest(); onRequest();
lastRecv = Util::epoch();
}else{ }else{
if (!isBlocking && !parseData){ if (!isBlocking && !parseData){
if (Util::epoch() - lastRecv > 300){
WARN_MSG("Disconnecting 5 minute idle connection");
myConn.close();
}else{
Util::sleep(500); Util::sleep(500);
} }
} }
} }
}
int Output::run(){ int Output::run(){
DONTEVEN_MSG("MistOut client handler started"); DONTEVEN_MSG("MistOut client handler started");

View file

@ -84,6 +84,7 @@ namespace Mist {
std::map<unsigned long, unsigned long> nxtKeyNum;///< Contains the number of the next key, for page seeking purposes. std::map<unsigned long, unsigned long> nxtKeyNum;///< Contains the number of the next key, for page seeking purposes.
std::set<sortedPageInfo> buffer;///< A sorted list of next-to-be-loaded packets. std::set<sortedPageInfo> buffer;///< A sorted list of next-to-be-loaded packets.
bool sought;///<If a seek has been done, this is set to true. Used for seeking on prepareNext(). bool sought;///<If a seek has been done, this is set to true. Used for seeking on prepareNext().
uint64_t lastRecv;
protected://these are to be messed with by child classes protected://these are to be messed with by child classes
virtual std::string getConnectedHost(); virtual std::string getConnectedHost();
virtual std::string getConnectedBinHost(); virtual std::string getConnectedBinHost();