]> git.vomp.tv Git - vompclient-marten.git/commitdiff
Client side timeouts
authorChris Tallon <chris@vomp.tv>
Sun, 25 May 2008 15:55:21 +0000 (15:55 +0000)
committerChris Tallon <chris@vomp.tv>
Sun, 25 May 2008 15:55:21 +0000 (15:55 +0000)
eventdispatcher.cc
vdr.cc

index 9a732355636a16579c162e3069068841f62e223e..f7217f906fa80c9483a66b8d0bc55d271d774ca1 100644 (file)
@@ -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 0e1ba97fd669e6bacb8cde4d4644d7178dcfb7ac..d01e7e31a6efe784207fa19367b98c76e91f67e9 100644 (file)
--- 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();