<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Framented packet bug ?</TITLE>
<META content="MSHTML 6.00.2800.1479" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=643570017-09122004><FONT
face="Lucida Console" color=#0000ff size=2>It seems that the following fixes the
problem, but I'd rather have an official fix :-)</FONT></SPAN><SPAN
class=643570017-09122004><FONT face="Lucida Console" color=#0000ff
size=2></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=643570017-09122004><FONT
face="Lucida Console" color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=643570017-09122004><FONT
face="Lucida Console" color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=643570017-09122004><FONT
face="Lucida Console" color=#0000ff size=2>ENetIncomingCommand
*<BR>enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol *
command, ENetPacket * packet, enet_uint32
fragmentCount)<BR>{<BR> ENetChannel * channel = & peer
-> channels [command -> header.channelID];<BR>
enet_uint32 unreliableSequenceNumber = 0;<BR>
ENetIncomingCommand * incomingCommand;<BR> ENetListIterator
currentCommand;</FONT></SPAN></DIV>
<DIV><FONT face="Lucida Console" color=#0000ff size=2></FONT> </DIV>
<DIV dir=ltr align=left><SPAN class=643570017-09122004><FONT
face="Lucida Console" color=#0000ff size=2> switch (command
-> header.command)<BR> {<BR>+ case
ENET_PROTOCOL_COMMAND_SEND_FRAGMENT:<BR> case
ENET_PROTOCOL_COMMAND_SEND_RELIABLE:<BR> for
(currentCommand = enet_list_previous (enet_list_end (& channel ->
incomingReliableCommands));<BR></FONT></SPAN></DIV>
<DIV><FONT face="Lucida Console" color=#0000ff size=2></FONT> </DIV>
<DIV><FONT face="Lucida Console" color=#0000ff size=2><SPAN
class=643570017-09122004>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. <SPAN
class=643570017-09122004><FONT face="Lucida Console" color=#0000ff size=2>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:</FONT></SPAN><FONT
face="Lucida Console"><BR></FONT></SPAN></FONT></DIV>
<DIV><FONT face="Lucida Console" color=#0000ff size=2></FONT> </DIV>
<DIV><FONT face="Lucida Console"><FONT color=#0000ff><FONT size=2><SPAN
class=643570017-09122004>-</SPAN> if ((startCommand -> fragments
[fragmentNumber / 32] & (1 << fragmentNumber)) == 0)<BR><SPAN
class=643570017-09122004>+</SPAN> if ((startCommand -> fragments
[fragmentNumber / 32] & (1 << (fragmentNumber & 31))) ==
0)<BR><SPAN class=643570017-09122004>+</SPAN>
{<BR> -- startCommand ->
fragmentsRemaining;</FONT></FONT></FONT></DIV>
<DIV><FONT face="Lucida Console" color=#0000ff size=2></FONT> </DIV>
<DIV><FONT face="Lucida Console"><FONT color=#0000ff><FONT size=2><SPAN
class=643570017-09122004>-</SPAN> startCommand -> fragments
[fragmentNumber / 32] |= (1 << fragmentNumber);<BR><SPAN
class=643570017-09122004>+</SPAN> startCommand -> fragments
[fragmentNumber / 32] |= (1 << (fragmentNumber &
31));</FONT></FONT></FONT></DIV>
<DIV><FONT face="Lucida Console" color=#0000ff size=2></FONT> </DIV>
<DIV><FONT face="Lucida Console" color=#0000ff
size=2> if (fragmentOffset + fragmentLength >
startCommand -> packet ->
dataLength)<BR> fragmentLength =
startCommand -> packet -> dataLength - fragmentOffset;</FONT></DIV>
<DIV><FONT face="Lucida Console" color=#0000ff size=2></FONT> </DIV>
<DIV><FONT face="Lucida Console" color=#0000ff
size=2> memcpy (packet_data(startCommand ->
packet) +
fragmentOffset,<BR>
(enet_uint8 *) command + sizeof
(ENetProtocolSendFragment),<BR>
fragmentLength);<BR><SPAN class=643570017-09122004>+</SPAN>
}<BR>}</FONT></DIV>
<DIV><FONT><FONT face="Lucida Console"><FONT color=#0000ff
size=2></FONT></FONT> </DIV></FONT>
<DIV><FONT face="Lucida Console" color=#0000ff size=2></FONT> </DIV>
<P><FONT face="Lucida Console" color=#800000
size=2>__________________________________</FONT> <BR><FONT face="Lucida Console"
color=#800000 size=2>Benoit Germain</FONT> <BR><FONT face="Lucida Console"
color=#800000 size=2>][ Engineer</FONT> <BR><FONT face="Lucida Console"
color=#800000 size=2><A
href="mailto:bgermain@ubisoft.fr">mailto:bgermain@ubisoft.fr</A></FONT>
<BR><FONT face="Lucida Console" color=#800000
size=2>__________________________________</FONT> </P>
<DIV><FONT face="Lucida Console" color=#0000ff
size=2></FONT> </DIV></BODY></HTML>