aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/LindenUDP/LLPacketHandler.cs
diff options
context:
space:
mode:
authorMelanie Thielker2008-08-07 14:48:45 +0000
committerMelanie Thielker2008-08-07 14:48:45 +0000
commit51f90af4b735efbe0c6bdccd93c887b266f91488 (patch)
tree9bf4a3463da24290eac50b1c1aa375a5a5790d30 /OpenSim/Region/ClientStack/LindenUDP/LLPacketHandler.cs
parentMinor formatting cleanup. (diff)
downloadopensim-SC_OLD-51f90af4b735efbe0c6bdccd93c887b266f91488.zip
opensim-SC_OLD-51f90af4b735efbe0c6bdccd93c887b266f91488.tar.gz
opensim-SC_OLD-51f90af4b735efbe0c6bdccd93c887b266f91488.tar.bz2
opensim-SC_OLD-51f90af4b735efbe0c6bdccd93c887b266f91488.tar.xz
Patch #9158
Refactor packet sending into LLPacketHandler. Change packet sequencing and ack lists to ensure packet sequences conform to wire order.
Diffstat (limited to 'OpenSim/Region/ClientStack/LindenUDP/LLPacketHandler.cs')
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLPacketHandler.cs85
1 files changed, 73 insertions, 12 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLPacketHandler.cs b/OpenSim/Region/ClientStack/LindenUDP/LLPacketHandler.cs
index b035150..51448f2 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLPacketHandler.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLPacketHandler.cs
@@ -31,10 +31,13 @@ using System.Collections.Generic;
31using System.Net; 31using System.Net;
32using System.Net.Sockets; 32using System.Net.Sockets;
33using System.Timers; 33using System.Timers;
34using System.Reflection;
34using libsecondlife; 35using libsecondlife;
35using libsecondlife.Packets; 36using libsecondlife.Packets;
36using Timer = System.Timers.Timer; 37using Timer = System.Timers.Timer;
37using OpenSim.Framework; 38using OpenSim.Framework;
39using OpenSim.Region.ClientStack.LindenUDP;
40using log4net;
38 41
39namespace OpenSim.Region.ClientStack.LindenUDP 42namespace OpenSim.Region.ClientStack.LindenUDP
40{ 43{
@@ -55,7 +58,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
55 uint ResendTimeout { get; set; } 58 uint ResendTimeout { get; set; }
56 59
57 void InPacket(Packet packet); 60 void InPacket(Packet packet);
58 void ProcessInPacket(Packet packet); 61 void ProcessInPacket(LLQueItem item);
62 void ProcessOutPacket(LLQueItem item);
59 void OutPacket(Packet NewPack, 63 void OutPacket(Packet NewPack,
60 ThrottleOutPacketType throttlePacketType); 64 ThrottleOutPacketType throttlePacketType);
61 void OutPacket(Packet NewPack, 65 void OutPacket(Packet NewPack,
@@ -72,6 +76,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
72 76
73 public class LLPacketHandler : IPacketHandler 77 public class LLPacketHandler : IPacketHandler
74 { 78 {
79 private static readonly ILog m_log =
80 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
81
75 // Packet queues 82 // Packet queues
76 // 83 //
77 LLPacketQueue m_PacketQueue; 84 LLPacketQueue m_PacketQueue;
@@ -181,13 +188,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP
181 188
182 List<PacketType> m_ImportantPackets = new List<PacketType>(); 189 List<PacketType> m_ImportantPackets = new List<PacketType>();
183 190
191 LLPacketServer m_PacketServer;
192 private byte[] m_ZeroOutBuffer = new byte[4096];
193
184 //////////////////////////////////////////////////////////////////// 194 ////////////////////////////////////////////////////////////////////
185 195
186 // Constructors 196 // Constructors
187 // 197 //
188 public LLPacketHandler(IClientAPI client) 198 public LLPacketHandler(IClientAPI client, LLPacketServer server)
189 { 199 {
190 m_Client = client; 200 m_Client = client;
201 m_PacketServer = server;
191 202
192 m_PacketQueue = new LLPacketQueue(client.AgentId); 203 m_PacketQueue = new LLPacketQueue(client.AgentId);
193 204
@@ -228,21 +239,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
228 return; 239 return;
229 } 240 }
230 241
231 packet.Header.Sequence = NextPacketSequenceNumber();
232
233 lock (m_NeedAck) 242 lock (m_NeedAck)
234 { 243 {
235 DropResend(id); 244 DropResend(id);
236 245
237 AddAcks(ref packet); 246 AddAcks(ref packet);
238 QueuePacket(packet, throttlePacketType, id); 247 QueuePacket(packet, throttlePacketType, id);
239
240 // We want to see that packet arrive if it's reliable
241 if (packet.Header.Reliable)
242 {
243 m_UnackedBytes += packet.ToBytes().Length;
244 m_NeedAck[packet.Header.Sequence] = new AckData(packet, id);
245 }
246 } 248 }
247 } 249 }
248 250
@@ -531,8 +533,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
531 } 533 }
532 } 534 }
533 535
534 public void ProcessInPacket(Packet packet) 536 public void ProcessInPacket(LLQueItem item)
535 { 537 {
538 Packet packet = item.Packet;
539
536 // Always ack the packet! 540 // Always ack the packet!
537 // 541 //
538 if (packet.Header.Reliable) 542 if (packet.Header.Reliable)
@@ -698,5 +702,62 @@ namespace OpenSim.Region.ClientStack.LindenUDP
698 702
699 handlerPacketDrop(packet, id); 703 handlerPacketDrop(packet, id);
700 } 704 }
705
706 // Convert the packet to bytes and stuff it onto the send queue
707 //
708 public void ProcessOutPacket(LLQueItem item)
709 {
710 Packet packet = item.Packet;
711
712 // Keep track of when this packet was sent out
713 packet.TickCount = System.Environment.TickCount;
714
715 // Assign sequence number here to prevent out of order packets
716 packet.Header.Sequence = NextPacketSequenceNumber();
717
718 lock(m_NeedAck)
719 {
720 // We want to see that packet arrive if it's reliable
721 if (packet.Header.Reliable)
722 {
723 m_UnackedBytes += packet.ToBytes().Length;
724 m_NeedAck[packet.Header.Sequence] = new AckData(packet,
725 item.Identifier);
726 }
727 }
728
729 // Actually make the byte array and send it
730 try
731 {
732 byte[] sendbuffer = packet.ToBytes();
733
734 if (packet.Header.Zerocoded)
735 {
736 int packetsize = Helpers.ZeroEncode(sendbuffer,
737 sendbuffer.Length, m_ZeroOutBuffer);
738 m_PacketServer.SendPacketTo(m_ZeroOutBuffer, packetsize,
739 SocketFlags.None, m_Client.CircuitCode);
740 }
741 else
742 {
743 // Need some extra space in case we need to add proxy
744 // information to the message later
745 Buffer.BlockCopy(sendbuffer, 0, m_ZeroOutBuffer, 0,
746 sendbuffer.Length);
747 m_PacketServer.SendPacketTo(m_ZeroOutBuffer,
748 sendbuffer.Length, SocketFlags.None, m_Client.CircuitCode);
749 }
750
751 PacketPool.Instance.ReturnPacket(packet);
752 }
753 catch (Exception e)
754 {
755 m_log.Warn("[client]: " +
756 "PacketHandler:ProcessOutPacket() - WARNING: Socket "+
757 "exception occurred - killing thread");
758 m_log.Error(e.ToString());
759 m_Client.Close(true);
760 }
761 }
701 } 762 }
702} 763}