minor refactor so that I can now grok what happens for outgoing packets

afrisby
Sean Dague 2007-12-04 20:20:15 +00:00
parent c1fdba8a6f
commit 2adcdd3d15
1 changed files with 89 additions and 77 deletions

View File

@ -2240,14 +2240,11 @@ namespace OpenSim.Region.ClientStack
set { m_circuitCode = value; } set { m_circuitCode = value; }
} }
protected virtual void ProcessOutPacket(Packet Pack) // A thread safe sequence number allocator.
{ protected uint NextSeqNum()
// Keep track of when this packet was sent out
Pack.TickCount = System.Environment.TickCount;
if (!Pack.Header.Resent)
{ {
// Set the sequence number // Set the sequence number
uint seq = 1;
lock (SequenceLock) lock (SequenceLock)
{ {
if (Sequence >= MAX_SEQUENCE) if (Sequence >= MAX_SEQUENCE)
@ -2258,11 +2255,12 @@ namespace OpenSim.Region.ClientStack
{ {
Sequence++; Sequence++;
} }
seq = Sequence;
Pack.Header.Sequence = Sequence; }
return seq;
} }
if (Pack.Header.Reliable) //DIRTY HACK protected void AddAck(Packet Pack)
{ {
lock (NeedAck) lock (NeedAck)
{ {
@ -2288,17 +2286,15 @@ namespace OpenSim.Region.ClientStack
// packet.Type.ToString(), Helpers.LogLevel.Warning); // packet.Type.ToString(), Helpers.LogLevel.Warning);
} }
} }
}
// Don't append ACKs to resent packets, in case that's what was causing the protected virtual void SetPendingAcks(ref Packet Pack)
// delivery to fail
if (!Pack.Header.Resent)
{ {
// Append any ACKs that need to be sent out to this packet // Append any ACKs that need to be sent out to this packet
lock (PendingAcks) lock (PendingAcks)
{ {
if (PendingAcks.Count > 0 && PendingAcks.Count < MAX_APPENDED_ACKS && // TODO: If we are over MAX_APPENDED_ACKS we should drain off some of these
Pack.Type != PacketType.PacketAck && if (PendingAcks.Count > 0 && PendingAcks.Count < MAX_APPENDED_ACKS)
Pack.Type != PacketType.LogoutRequest)
{ {
Pack.Header.AckList = new uint[PendingAcks.Count]; Pack.Header.AckList = new uint[PendingAcks.Count];
int i = 0; int i = 0;
@ -2314,24 +2310,40 @@ namespace OpenSim.Region.ClientStack
} }
} }
} }
protected virtual void ProcessOutPacket(Packet Pack)
{
// Keep track of when this packet was sent out
Pack.TickCount = System.Environment.TickCount;
if (!Pack.Header.Resent)
{
Pack.Header.Sequence = NextSeqNum();
if (Pack.Header.Reliable) //DIRTY HACK
{
AddAck(Pack); // this adds the need to ack this packet later
if (Pack.Type != PacketType.PacketAck && Pack.Type != PacketType.LogoutRequest)
{
SetPendingAcks(ref Pack);
}
} }
} }
byte[] ZeroOutBuffer = new byte[4096]; // Actually make the byte array and send it
byte[] sendbuffer;
sendbuffer = Pack.ToBytes();
try try
{ {
byte[] sendbuffer = Pack.ToBytes();
if (Pack.Header.Zerocoded) if (Pack.Header.Zerocoded)
{ {
byte[] ZeroOutBuffer = new byte[4096];
int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer); int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer);
m_networkServer.SendPacketTo(ZeroOutBuffer, packetsize, SocketFlags.None, m_circuitCode); //userEP); m_networkServer.SendPacketTo(ZeroOutBuffer, packetsize, SocketFlags.None, m_circuitCode);
} }
else else
{ {
m_networkServer.SendPacketTo(sendbuffer, sendbuffer.Length, SocketFlags.None, m_circuitCode); m_networkServer.SendPacketTo(sendbuffer, sendbuffer.Length, SocketFlags.None, m_circuitCode);
//userEP);
} }
} }
catch (Exception e) catch (Exception e)