From 8ad02499693d14680665db088734b02c113ec32a Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 9 Oct 2008 18:09:25 +0000 Subject: * refactor: separate process of extracting packet from received data from actually processing that packet --- .../Region/ClientStack/LindenUDP/LLUDPServer.cs | 75 ++++++++++++---------- 1 file changed, 41 insertions(+), 34 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index 8643382..34481df 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -171,8 +171,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP } /// - /// This method is called every time that we receive new UDP data. We pass this data on to the LLPacketServer - /// except in the case that the packet is UseCircuitCode. In this case we set up the circuit code instead. + /// This method is called every time that we receive new UDP data. /// /// protected virtual void OnReceivedData(IAsyncResult result) @@ -252,46 +251,54 @@ namespace OpenSim.Region.ClientStack.LindenUDP BeginReceive(); if (packet != null) + ProcessInPacket(packet); + } + + /// + /// Process a successfully received packet. We pass the packet on to the LLPacketServer + /// except in the case that the packet is UseCircuitCode. In that case we set up the circuit code instead. + /// + /// + protected virtual void ProcessInPacket(Packet packet) + { + try { - try - { - // do we already have a circuit for this endpoint - uint circuit; + // do we already have a circuit for this endpoint + uint circuit; - bool ret; - lock (clientCircuits) - { - ret = clientCircuits.TryGetValue(epSender, out circuit); - } + bool ret; + lock (clientCircuits) + { + ret = clientCircuits.TryGetValue(epSender, out circuit); + } - if (ret) - { - //if so then send packet to the packetserver - //m_log.DebugFormat("[UDPSERVER]: For endpoint {0} got packet {1}", epSender, packet.Type); + if (ret) + { + //if so then send packet to the packetserver + //m_log.DebugFormat("[UDPSERVER]: For endpoint {0} got packet {1}", epSender, packet.Type); - m_packetServer.InPacket(circuit, packet); - } - else if (packet.Type == PacketType.UseCircuitCode) - { - AddNewClient(packet); - - UseCircuitCodePacket p = (UseCircuitCodePacket)packet; - - // Ack the first UseCircuitCode packet - PacketAckPacket ack_it = (PacketAckPacket)PacketPool.Instance.GetPacket(PacketType.PacketAck); - // TODO: don't create new blocks if recycling an old packet - ack_it.Packets = new PacketAckPacket.PacketsBlock[1]; - ack_it.Packets[0] = new PacketAckPacket.PacketsBlock(); - ack_it.Packets[0].ID = packet.Header.Sequence; - ack_it.Header.Reliable = false; - SendPacketTo(ack_it.ToBytes(),ack_it.ToBytes().Length,SocketFlags.None,p.CircuitCode.Code); - } + m_packetServer.InPacket(circuit, packet); } - catch (Exception e) + else if (packet.Type == PacketType.UseCircuitCode) { - m_log.Error("[CLIENT]: Exception in processing packet - ignoring: ", e); + AddNewClient(packet); + + UseCircuitCodePacket p = (UseCircuitCodePacket)packet; + + // Ack the first UseCircuitCode packet + PacketAckPacket ack_it = (PacketAckPacket)PacketPool.Instance.GetPacket(PacketType.PacketAck); + // TODO: don't create new blocks if recycling an old packet + ack_it.Packets = new PacketAckPacket.PacketsBlock[1]; + ack_it.Packets[0] = new PacketAckPacket.PacketsBlock(); + ack_it.Packets[0].ID = packet.Header.Sequence; + ack_it.Header.Reliable = false; + SendPacketTo(ack_it.ToBytes(),ack_it.ToBytes().Length,SocketFlags.None,p.CircuitCode.Code); } } + catch (Exception e) + { + m_log.Error("[CLIENT]: Exception in processing packet - ignoring: ", e); + } } private void BeginReceive() -- cgit v1.1