From 223040c158a7f412f76ef93421396ce935a55b39 Mon Sep 17 00:00:00 2001 From: havoc Date: Fri, 11 Sep 2009 07:59:59 +0000 Subject: [PATCH] reworked unreliable message queue to ALWAYS dequeue the first entry, even if it does not fit (and throw it away if so) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9173 d7cf8633-e32d-0410-b094-e92efae38249 --- sv_main.c | 54 ++++++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/sv_main.c b/sv_main.c index a353b11a..b6471287 100644 --- a/sv_main.c +++ b/sv_main.c @@ -1829,7 +1829,7 @@ void SV_FlushBroadcastMessages(void) SZ_Clear(&sv.datagram); } -static void SV_WriteUnreliableMessages(client_t *client, sizebuf_t *msg, int maxsize) +static void SV_WriteUnreliableMessages(client_t *client, sizebuf_t *msg, int maxsize, int maxsize2) { // scan the splitpoints to find out how many we can fit in int numsegments, j, split; @@ -1838,34 +1838,28 @@ static void SV_WriteUnreliableMessages(client_t *client, sizebuf_t *msg, int max // always accept the first one if it's within 1024 bytes, this ensures // that very big datagrams which are over the rate limit still get // through, just to keep it working - j = msg->cursize + client->unreliablemsg_splitpoint[0]; - if (maxsize < 1024 && j > maxsize && j <= 1024) - { - numsegments = 1; - maxsize = 1024; - } - else - for (numsegments = 0;numsegments < client->unreliablemsg_splitpoints;numsegments++) - if (msg->cursize + client->unreliablemsg_splitpoint[numsegments] > maxsize) - break; - if (numsegments > 0) - { - // some will fit, so add the ones that will fit - split = client->unreliablemsg_splitpoint[numsegments-1]; - // note this discards ones that were accepted by the segments scan but - // can not fit, such as a really huge first one that will never ever - // fit in a packet... - if (msg->cursize + split <= maxsize) - SZ_Write(msg, client->unreliablemsg.data, split); - // remove the part we sent, keeping any remaining data - client->unreliablemsg.cursize -= split; - if (client->unreliablemsg.cursize > 0) - memmove(client->unreliablemsg.data, client->unreliablemsg.data + split, client->unreliablemsg.cursize); - // adjust remaining splitpoints - client->unreliablemsg_splitpoints -= numsegments; - for (j = 0;j < client->unreliablemsg_splitpoints;j++) - client->unreliablemsg_splitpoint[j] = client->unreliablemsg_splitpoint[numsegments + j] - split; - } + for (numsegments = 1;numsegments < client->unreliablemsg_splitpoints;numsegments++) + if (msg->cursize + client->unreliablemsg_splitpoint[numsegments] > maxsize) + break; + // the first segment gets an exemption from the rate limiting, otherwise + // it could get dropped consistently due to a low rate limit + if (numsegments == 1) + maxsize = maxsize2; + // some will fit, so add the ones that will fit + split = client->unreliablemsg_splitpoint[numsegments-1]; + // note this discards ones that were accepted by the segments scan but + // can not fit, such as a really huge first one that will never ever + // fit in a packet... + if (msg->cursize + split <= maxsize) + SZ_Write(msg, client->unreliablemsg.data, split); + // remove the part we sent, keeping any remaining data + client->unreliablemsg.cursize -= split; + if (client->unreliablemsg.cursize > 0) + memmove(client->unreliablemsg.data, client->unreliablemsg.data + split, client->unreliablemsg.cursize); + // adjust remaining splitpoints + client->unreliablemsg_splitpoints -= numsegments; + for (j = 0;j < client->unreliablemsg_splitpoints;j++) + client->unreliablemsg_splitpoint[j] = client->unreliablemsg_splitpoint[numsegments + j] - split; } /* @@ -1971,7 +1965,7 @@ static void SV_SendClientDatagram (client_t *client) // add as many queued unreliable messages (effects) as we can fit // limit effects to half of the remaining space if (client->unreliablemsg.cursize) - SV_WriteUnreliableMessages (client, &msg, (msg.cursize + maxsize) / 2); + SV_WriteUnreliableMessages (client, &msg, maxsize/2, maxsize2); // now write as many entities as we can fit, and also sends stats SV_WriteEntitiesToClient (client, client->edict, &msg, maxsize); -- 2.39.2