From 98de90b8bf846f9fb0a1e6d87efffa3a614cd1e4 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 25 May 2008 15:55:21 +0000 Subject: [PATCH] Client side timeouts --- eventdispatcher.cc | 7 ++++++- vdr.cc | 35 +++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/eventdispatcher.cc b/eventdispatcher.cc index 9a73235..f7217f9 100644 --- a/eventdispatcher.cc +++ b/eventdispatcher.cc @@ -111,8 +111,13 @@ void EventDispatcher::edUnregister(EDReceiver* edr) if (*i == edr) break; // found } - if (i == receivers.end()) return; // Not in the list. Already unregistered? Perhaps vdr::connectionDied already removed this streamclient + // Not in the list. Already unregistered? Perhaps vdr::connectionDied already removed this streamclient // FIXME, this should probably be done another way. A call to edUnregister with an object that may or may not be in the list? Not good. + if (i == receivers.end()) + { + edUnlock(); + return; + } if (!edr->callinprogress) { diff --git a/vdr.cc b/vdr.cc index 0e1ba97..d01e7e3 100644 --- a/vdr.cc +++ b/vdr.cc @@ -204,7 +204,7 @@ void VDR::threadMethod() while(1) { - if (!tcp->readData((UCHAR*)&channelID, sizeof(ULONG))) // 2s timeout atm + if (!tcp->readData((UCHAR*)&channelID, sizeof(ULONG))) // 2s timeout atm { ++timeoutCount; @@ -234,30 +234,40 @@ void VDR::threadMethod() if (!tcp->isConnected()) { connectionDied(); return; } // return to stop this thread - timeoutCount = 0; // disable it for now + timeoutCount = 0; // disable it for now - if (timeoutCount >= 10) //20s + if (timeoutCount >= 3) // x2 for seconds { timeNow = (ULONG)time(NULL); - if (lastKAsent > (timeNow - 20)) continue; + if (lastKAsent > (timeNow - 6)) continue; if (lastKAsent == 0) { - logger->log("VDR", Log::DEBUG, "Sending KA packet"); - if (!sendKA(timeNow)) { connectionDied(); return; } + logger->log("VDR", Log::DEBUG, "(Not actually) Sending KA packet"); +// if (!sendKA(timeNow)) +// { +// logger->log("VDR", Log::DEBUG, "Could not send KA, calling connectionDied"); +// connectionDied(); +// return; +// } lastKAsent = timeNow; continue; } - if (lastKAsent <= (timeNow - 20)) { connectionDied(); return; } + if (lastKAsent <= (timeNow - 6)) + { + logger->log("VDR", Log::DEBUG, "lastKA over 20s ago, calling connectionDied"); + connectionDied(); + return; + } } continue; } // Data was read - + timeoutCount = 0; channelID = ntohl(channelID); @@ -339,6 +349,8 @@ void VDR::threadMethod() // If RR, the individual protocol functions must delete vresp. // If stream, the data and length is taken out in ed_cb_call and vresp is deleted there. } + + connectionDied(); } void VDR::connectionDied() @@ -396,7 +408,8 @@ void VDR::connectionDied() } edUnlock(); // Ok, all event receviers should be dealt with. just in case there weren't any, inform command - + logger->log("VDR", Log::DEBUG, "edUnlock at end of connectionDied"); + Command::getInstance()->connectionLost(); } @@ -444,9 +457,11 @@ VDR_ResponsePacket* VDR::RequestResponse(VDR_RequestPacket* vrp) // vdrpr.requestTime = time(NULL); vdrpr.receiverChannel = VDR::CHANNEL_REQUEST_RESPONSE; vdrpr.requestSerialNumber = vrp->getSerial(); + edRegister(&vdrpr); - + edLock(); + if ((ULONG)tcp->sendData(vrp->getPtr(), vrp->getLen()) != vrp->getLen()) { edUnlock(); -- 2.39.5