changeset 15091:525607f86cce

[gaim-migrate @ 17877] Millisecond accuracy for the rolling average thing. It still seems pretty inaccurate. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 02 Dec 2006 19:57:47 +0000
parents 9cdc8bb39cf2
children 4ba77924fc08
files libgaim/protocols/oscar/family_oservice.c libgaim/protocols/oscar/flap_connection.c libgaim/protocols/oscar/oscar.h
diffstat 3 files changed, 20 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/libgaim/protocols/oscar/family_oservice.c	Sat Dec 02 10:43:06 2006 +0000
+++ b/libgaim/protocols/oscar/family_oservice.c	Sat Dec 02 19:57:47 2006 +0000
@@ -326,6 +326,8 @@
 		if (mod->version >= 3)
 			byte_stream_getrawbuf(bs, rateclass->unknown, sizeof(rateclass->unknown));
 
+		rateclass->last.tv_sec = 0;
+		rateclass->last.tv_usec = 0;
 		conn->rateclasses = g_slist_prepend(conn->rateclasses, rateclass);
 	}
 	conn->rateclasses = g_slist_reverse(conn->rateclasses);
--- a/libgaim/protocols/oscar/flap_connection.c	Sat Dec 02 10:43:06 2006 +0000
+++ b/libgaim/protocols/oscar/flap_connection.c	Sat Dec 02 19:57:47 2006 +0000
@@ -89,18 +89,25 @@
 			if ((snacpair->group == family) && (snacpair->subtype == subtype))
 			{
 				/*
-				 * We've found the rateclass for this SNAC family and
-				 * subtype!  Update our "current" average by calculating
-				 * a rolling average.  This is pretty shoddy.  We should
-				 * really keep track of the times when the last last
-				 * windowsize messages that were sent and just calculate
-				 * the REAL average.
+				 * We've found the rateclass for this SNAC family
+				 * and subtype!  Update our "current" average by
+				 * calculating a rolling average.  This is pretty
+				 * shoddy.  We should really keep track of the times
+				 * when the last windowsize messages that were sent
+				 * and just calculate the REAL average.
 				 */
-				time_t now;
-				now = time(NULL);
+				struct timeval now;
+				struct timezone tz;
+				unsigned long timediff; /* In milliseconds */
+
+				gettimeofday(&now, &tz);
+				timediff = MIN((now.tv_sec - rateclass->last.tv_sec) * 1000 + (now.tv_usec - rateclass->last.tv_usec) / 1000, rateclass->max);
+
 				/* This formula is taken from the joscar API docs. */
-				rateclass->current = MIN(((rateclass->current * (rateclass->windowsize - 1)) + (now - rateclass->last)) / rateclass->windowsize, rateclass->max);
-				rateclass->last = now;
+				rateclass->current = MIN(((rateclass->current * (rateclass->windowsize - 1)) + timediff) / rateclass->windowsize, rateclass->max);
+				rateclass->last.tv_sec = now.tv_sec;
+				rateclass->last.tv_usec = now.tv_usec;
+
 				return;
 			}
 		}
--- a/libgaim/protocols/oscar/oscar.h	Sat Dec 02 10:43:06 2006 +0000
+++ b/libgaim/protocols/oscar/oscar.h	Sat Dec 02 19:57:47 2006 +0000
@@ -1578,7 +1578,7 @@
 	GSList *members; /* Contains node of struct snacpair */
 	/* TODO: Maybe use a GHashTable for members */
 
-	time_t last; /**< The time when we last sent a SNAC of this rate class. */
+	struct timeval last; /**< The time when we last sent a SNAC of this rate class. */
 };
 
 int aim_cachecookie(OscarData *od, IcbmCookie *cookie);