From 40f1cec8f9ed76a7f2ddd1bd7dfeb97b38a4bf56 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Sun, 15 Jan 2017 17:35:00 +0100 Subject: [PATCH] Added 5 minute timeout to idle connections --- src/output/output.cpp | 11 +++++++++-- src/output/output.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/output/output.cpp b/src/output/output.cpp index f67ca2a4..eb985351 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -44,6 +44,7 @@ namespace Mist{ maxSkipAhead = 7500; minSkipAhead = 5000; realTime = 1000; + lastRecv = Util::epoch(); if (myConn){ setBlocking(true); }else{ @@ -658,11 +659,17 @@ namespace Mist{ static bool firstData = true;//only the first time, we call onRequest if there's data buffered already. if ((firstData && myConn.Received().size()) || myConn.spool()){ firstData = false; - DEBUG_MSG(DLVL_DONTEVEN, "onRequest"); + DONTEVEN_MSG("onRequest"); onRequest(); + lastRecv = Util::epoch(); }else{ if (!isBlocking && !parseData){ - Util::sleep(500); + if (Util::epoch() - lastRecv > 300){ + WARN_MSG("Disconnecting 5 minute idle connection"); + myConn.close(); + }else{ + Util::sleep(500); + } } } } diff --git a/src/output/output.h b/src/output/output.h index 5580542d..518f868e 100644 --- a/src/output/output.h +++ b/src/output/output.h @@ -84,6 +84,7 @@ namespace Mist { std::map nxtKeyNum;///< Contains the number of the next key, for page seeking purposes. std::set buffer;///< A sorted list of next-to-be-loaded packets. bool sought;///