My algorithm is.. (C-like code)
Adron
Posted On 05/25/01 06:18AM
/* If this returns non-zero, delay that many milliseconds
   before trying again. If this returns zero, send your
   data.
*/
unsigned long RequiredDelay(unsigned long bytes)
{
    static unsigned long lasttick = 0;    // time (ms) of last call to function
    static unsigned long sentbytes = 0;   // number of outstanding bytes
    const unsigned long perpacket = 200;  // extra bytes per packet
    const unsigned long msperbyte = 10;   // milliseconds per byte
    const unsigned long maxbytes = 600;   // max bytes outstanding
    unsigned long tick = GetTickCount();
    if(lasttick - tick > sentbytes * msperbyte)
        sentbytes = 0;
    else
        sentbytes -= (lasttick-tick) / msperbyte;
    lasttick = tick;
    if(sentbytes + perpacket + bytes > maxbytes)
        return (sentbytes + perpacket + bytes - maxbytes) * msperbyte;
    sentbytes += perpacket + bytes;
    return 0;
}
Message edited on 05/25/01 06:26AM by Adron