[Box Backup-commit] COMMIT r1180 - box/chris/merge/lib/common

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Sun Nov 26 19:54:00 GMT 2006


Author: chris
Date: 2006-11-26 19:54:00 +0000 (Sun, 26 Nov 2006)
New Revision: 1180

Modified:
   box/chris/merge/lib/common/Timer.cpp
Log:

 * Fix timer expiry calculation when timers expire in the past
 * Fix handling of timers which never expire (zero deadline) (refs #9)


Modified: box/chris/merge/lib/common/Timer.cpp
===================================================================
--- box/chris/merge/lib/common/Timer.cpp	2006-11-26 19:49:27 UTC (rev 1179)
+++ box/chris/merge/lib/common/Timer.cpp	2006-11-26 19:54:00 UTC (rev 1180)
@@ -143,7 +143,7 @@
 	ASSERT(spTimers);
 
 	box_time_t timeNow = GetCurrentBoxTime();
-	box_time_t timeToNextEvent = 0;
+	int64_t timeToNextEvent = 0;
 	
 	for (std::vector<Timer*>::iterator i = spTimers->begin();
 		i != spTimers->end(); i++)
@@ -151,7 +151,8 @@
 		Timer& rTimer = **i;
 		ASSERT(!rTimer.HasExpired());
 		
-		box_time_t timeToExpiry = rTimer.GetExpiryTime() - timeNow;
+		int64_t timeToExpiry = rTimer.GetExpiryTime() - timeNow;
+		if (timeToExpiry <= 0) timeToExpiry = 1;
 		
 		if (timeToNextEvent == 0 || timeToNextEvent > timeToExpiry)
 		{
@@ -203,7 +204,7 @@
 		Timer& rTimer = **i;
 		ASSERT(!rTimer.HasExpired());
 		
-		box_time_t timeToExpiry = rTimer.GetExpiryTime() - timeNow;
+		int64_t timeToExpiry = rTimer.GetExpiryTime() - timeNow;
 		
 		if (timeToExpiry <= 0)
 		{
@@ -218,7 +219,14 @@
 : mExpires(GetCurrentBoxTime() + SecondsToBoxTime(timeoutSecs)),
   mExpired(false)
 {
-	Timers::Add(*this);
+	if (timeoutSecs == 0)
+	{
+		mExpires = 0;
+	}
+	else
+	{
+		Timers::Add(*this);
+	}
 }
 
 Timer::~Timer()
@@ -230,7 +238,10 @@
 : mExpires(rToCopy.mExpires),
   mExpired(rToCopy.mExpired)
 {
-	Timers::Add(*this);
+	if (mExpires != 0)
+	{
+		Timers::Add(*this);
+	}
 }
 
 Timer& Timer::operator=(const Timer& rToCopy)
@@ -238,10 +249,11 @@
 	Timers::Remove(*this);
 	mExpires = rToCopy.mExpires;
 	mExpired = rToCopy.mExpired;
-	if (!mExpired)
+	if (!mExpired && mExpires != 0)
 	{
 		Timers::Add(*this);
 	}
+	return *this;
 }
 
 void Timer::OnExpire()




More information about the Boxbackup-commit mailing list