# HG changeset patch # User Mark Doliner # Date 1165089467 0 # Node ID 525607f86ccea21ca04409da48d4c45db20552fc # Parent 9cdc8bb39cf2c4d940e14ff6e35919176ba1ecac [gaim-migrate @ 17877] Millisecond accuracy for the rolling average thing. It still seems pretty inaccurate. committer: Tailor Script diff -r 9cdc8bb39cf2 -r 525607f86cce libgaim/protocols/oscar/family_oservice.c --- 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); diff -r 9cdc8bb39cf2 -r 525607f86cce libgaim/protocols/oscar/flap_connection.c --- 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; } } diff -r 9cdc8bb39cf2 -r 525607f86cce libgaim/protocols/oscar/oscar.h --- 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);