From: <the...@us...> - 2006-12-02 19:57:47
|
Revision: 17877 http://svn.sourceforge.net/gaim/?rev=17877&view=rev Author: thekingant Date: 2006-12-02 11:57:47 -0800 (Sat, 02 Dec 2006) Log Message: ----------- Millisecond accuracy for the rolling average thing. It still seems pretty inaccurate. Modified Paths: -------------- trunk/libgaim/protocols/oscar/family_oservice.c trunk/libgaim/protocols/oscar/flap_connection.c trunk/libgaim/protocols/oscar/oscar.h Modified: trunk/libgaim/protocols/oscar/family_oservice.c =================================================================== --- trunk/libgaim/protocols/oscar/family_oservice.c 2006-12-02 10:43:06 UTC (rev 17876) +++ trunk/libgaim/protocols/oscar/family_oservice.c 2006-12-02 19:57:47 UTC (rev 17877) @@ -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); Modified: trunk/libgaim/protocols/oscar/flap_connection.c =================================================================== --- trunk/libgaim/protocols/oscar/flap_connection.c 2006-12-02 10:43:06 UTC (rev 17876) +++ trunk/libgaim/protocols/oscar/flap_connection.c 2006-12-02 19:57:47 UTC (rev 17877) @@ -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; } } Modified: trunk/libgaim/protocols/oscar/oscar.h =================================================================== --- trunk/libgaim/protocols/oscar/oscar.h 2006-12-02 10:43:06 UTC (rev 17876) +++ trunk/libgaim/protocols/oscar/oscar.h 2006-12-02 19:57:47 UTC (rev 17877) @@ -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); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |