--- deliantra/server/socket/loop.C 2007/07/01 05:00:20 1.55 +++ deliantra/server/socket/loop.C 2007/07/29 02:24:34 1.65 @@ -48,7 +48,7 @@ #define BG_SCRUB_RATE 4 // how often to send a face in the background -#define MAX_QUEUE_DEPTH 500 +#define MAX_QUEUE_DEPTH 50 #define MAX_QUEUE_BACKLOG 3. void @@ -167,13 +167,15 @@ ++scrub_idx; if (!faces_sent [scrub_idx]) - { - send_face (scrub_idx); - flush_fx (); + if (faceinfo *f = face_info (scrub_idx)) + if (f->type == FT_FACE) // only scrub faces for now + { + send_face (scrub_idx, -120); + flush_fx (); - bg_scrub = 1; // send up to one face per tick, unless an image was requested - break; - } + bg_scrub = 1; // send up to one face per tick, unless an image was requested + break; + } } rate_avail = max_rate - outputbuffer_len (); @@ -182,14 +184,20 @@ { int ol = outputbuffer_len (); - rate_avail = min (max_rate, rate_avail + max_rate); - rate_avail -= ol; + rate_avail = min (max_rate + mss, rate_avail + max_rate); int avail = rate_avail; - // if we can split images, transfer up to mss-sized packets if possible - // but never 768 bytes more. - if (fxix) avail += min (768, mss - (ol % mss)); + // if we can split images, round to next-lowest mss + if (fxix) avail -= avail % mss; + + rate_avail -= ol; + avail -= ol; + +#if HAVE_TCP_INFO + // further restrict the available bandwidth by the excess bandwidth available + avail = max (0, min (avail, (tcpi.tcpi_snd_cwnd - tcpi.tcpi_unacked + tcpi.tcpi_sacked) * mss)); +#endif bg_scrub = BG_SCRUB_RATE; @@ -201,14 +209,21 @@ { if (fxix) { - // 9 bytes is enough for fx_FFFOOO, 40 leaves some room for image data - int chunk = min (min (avail - 40, MAXSOCKBUF - 9), ix.ofs); - - if (chunk <= 0) + // estimate the packet header overhead "ix " + idx + (new)ofs + int pktlen = 3 + ber32::encoded_size (ix.idx) + ber32::encoded_size (ix.ofs); + int chunk = min (avail - packet::hdrlen, MAXSOCKBUF) - pktlen; + + // only transfer something if the amount of data transferred + // has a healthy relation to the header overhead + if (chunk < 64) break; + chunk = min (chunk, (int)ix.ofs); + ix.ofs -= chunk; + //fprintf (stderr, "i%dx %6d: %5d+%4d (%4d)\n", fxix, ix.idx,ix.ofs,chunk, ixface.size());//D + packet sl ("ix"); sl << ber32 (ix.idx) @@ -226,7 +241,7 @@ else ix.ofs = 0; - int consumed = ol - outputbuffer_len (); + int consumed = outputbuffer_len () - ol; avail -= consumed; rate_avail -= consumed; @@ -236,6 +251,7 @@ if (!ix.ofs) { ixface.pop_back (); + if (ixface.empty ()) break; }