aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs')
-rwxr-xr-xOpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs66
1 files changed, 63 insertions, 3 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs
index 5e7cbca..bd5b282 100755
--- a/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs
@@ -26,11 +26,13 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic;
29using System.Net; 30using System.Net;
31using OpenMetaverse.Packets;
30using OpenSim.Framework; 32using OpenSim.Framework;
31using OpenSim.Framework.Communications.Cache; 33using OpenSim.Framework.Communications.Cache;
32 34
33namespace OpenSim.Region.ClientStack.LindenUDP 35namespace OpenSim.Region.ClientStack.LindenUDP.Tests
34{ 36{
35 /// <summary> 37 /// <summary>
36 /// This class enables synchronous testing of the LLUDPServer by allowing us to load our own data into the end 38 /// This class enables synchronous testing of the LLUDPServer by allowing us to load our own data into the end
@@ -38,6 +40,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
38 /// </summary> 40 /// </summary>
39 public class TestLLUDPServer : LLUDPServer 41 public class TestLLUDPServer : LLUDPServer
40 { 42 {
43 /// <summary>
44 /// The chunks of data to pass to the LLUDPServer when it calls EndReceive
45 /// </summary>
46 protected Queue<ChunkSenderTuple> m_chunksToLoad = new Queue<ChunkSenderTuple>();
47
41 protected override void BeginReceive() 48 protected override void BeginReceive()
42 { 49 {
43 // Do nothing 50 // Do nothing
@@ -45,10 +52,63 @@ namespace OpenSim.Region.ClientStack.LindenUDP
45 52
46 protected override bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender) 53 protected override bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender)
47 { 54 {
48 // TODO: Return a packet loaded in by a test
49 numBytes = 0; 55 numBytes = 0;
50 56
57 if (m_chunksToLoad.Count <= 0)
58 return false;
59
60 ChunkSenderTuple tuple = m_chunksToLoad.Dequeue();
61 RecvBuffer = tuple.Data;
62 numBytes = tuple.Data.Length;
63 epSender = tuple.Sender;
64
51 return true; 65 return true;
52 } 66 }
67
68 /// <summary>
69 /// Load a packet to be received by the LLUDPServer on the next receive call
70 /// </summary>
71 /// <param name="packet"></param>
72 public void LoadReceive(Packet packet, EndPoint epSender)
73 {
74 m_chunksToLoad.Enqueue(new ChunkSenderTuple(packet.ToBytes(), epSender));
75 }
76
77 /// <summary>
78 /// Calls the protected asynchronous result method
79 /// </summary>
80 /// <param name="result"></param>
81 public void ReceiveData(IAsyncResult result)
82 {
83 OnReceivedData(result);
84 }
85
86 /// <summary>
87 /// Has a circuit with the given code been established?
88 /// </summary>
89 /// <param name="circuitCode"></param>
90 /// <returns></returns>
91 public bool HasCircuit(uint circuitCode)
92 {
93 lock (clientCircuits_reverse)
94 {
95 return clientCircuits_reverse.ContainsKey(circuitCode);
96 }
97 }
98 }
99
100 /// <summary>
101 /// Record the data and sender tuple
102 /// </summary>
103 public class ChunkSenderTuple
104 {
105 public byte[] Data;
106 public EndPoint Sender;
107
108 public ChunkSenderTuple(byte[] data, EndPoint sender)
109 {
110 Data = data;
111 Sender = sender;
112 }
53 } 113 }
54} 114} \ No newline at end of file