[ENet-discuss] Framented packet bug ?
Benoit Germain
bgermain at ubisoft.fr
Thu Dec 9 09:08:34 PST 2004
It seems that the following fixes the problem, but I'd rather have an
official fix :-)
ENetIncomingCommand *
enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol *
command, ENetPacket * packet, enet_uint32 fragmentCount)
{
ENetChannel * channel = & peer -> channels [command ->
header.channelID];
enet_uint32 unreliableSequenceNumber = 0;
ENetIncomingCommand * incomingCommand;
ENetListIterator currentCommand;
switch (command -> header.command)
{
+ case ENET_PROTOCOL_COMMAND_SEND_FRAGMENT:
case ENET_PROTOCOL_COMMAND_SEND_RELIABLE:
for (currentCommand = enet_list_previous (enet_list_end (& channel ->
incomingReliableCommands));
There is another bug though, when the data being sent spans more that 32
fragments: the fragment reception bitfield is not properly updated, which
causes all fragments above 32 included to be dropped, because (1<<n) where
n>31 is always 0. Thus the following fix. BTW, note that data copying into
the reunited packet needs only to be done for new received fragments, hence
the enclosing braces that I added:
- if ((startCommand -> fragments [fragmentNumber / 32] & (1 <<
fragmentNumber)) == 0)
+ if ((startCommand -> fragments [fragmentNumber / 32] & (1 <<
(fragmentNumber & 31))) == 0)
+ {
-- startCommand -> fragmentsRemaining;
- startCommand -> fragments [fragmentNumber / 32] |= (1 <<
fragmentNumber);
+ startCommand -> fragments [fragmentNumber / 32] |= (1 <<
(fragmentNumber & 31));
if (fragmentOffset + fragmentLength > startCommand -> packet ->
dataLength)
fragmentLength = startCommand -> packet -> dataLength -
fragmentOffset;
memcpy (packet_data(startCommand -> packet) + fragmentOffset,
(enet_uint8 *) command + sizeof (ENetProtocolSendFragment),
fragmentLength);
+ }
}
__________________________________
Benoit Germain
][ Engineer
mailto:bgermain at ubisoft.fr <mailto:bgermain at ubisoft.fr>
__________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.puremagic.com/pipermail/enet-discuss/attachments/20041209/03675b88/attachment.htm
More information about the ENet-discuss
mailing list