diff options
author | Justin Clarke Casey | 2008-10-23 17:16:13 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2008-10-23 17:16:13 +0000 |
commit | ee3c428040fd026a92f3dd9a43ab4f88dec38181 (patch) | |
tree | 1e165d077d9fe2ba88a9b064c79faa827baf19f7 | |
parent | adding documentation for region_master_uuid to XML doc comments (diff) | |
download | opensim-SC-ee3c428040fd026a92f3dd9a43ab4f88dec38181.zip opensim-SC-ee3c428040fd026a92f3dd9a43ab4f88dec38181.tar.gz opensim-SC-ee3c428040fd026a92f3dd9a43ab4f88dec38181.tar.bz2 opensim-SC-ee3c428040fd026a92f3dd9a43ab4f88dec38181.tar.xz |
* Refactor LLUDPServer slightly so that unit tests can pass in data synchronously. Shouldn't be any functional change
3 files changed, 105 insertions, 34 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index e3ded7f..22086f8 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs | |||
@@ -180,39 +180,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
180 | { | 180 | { |
181 | Packet packet = null; | 181 | Packet packet = null; |
182 | int numBytes = 1; | 182 | int numBytes = 1; |
183 | bool ok = false; | ||
184 | EndPoint epSender = new IPEndPoint(IPAddress.Any, 0); | 183 | EndPoint epSender = new IPEndPoint(IPAddress.Any, 0); |
185 | 184 | ||
186 | try | 185 | if (EndReceive(out numBytes, result, ref epSender)) |
187 | { | ||
188 | numBytes = m_socket.EndReceiveFrom(result, ref epSender); | ||
189 | ok = true; | ||
190 | } | ||
191 | catch (SocketException e) | ||
192 | { | ||
193 | // TODO : Actually only handle those states that we have control over, re-throw everything else, | ||
194 | // TODO: implement cases as we encounter them. | ||
195 | //m_log.Error("[[CLIENT]: ]: Connection Error! - " + e.ToString()); | ||
196 | switch (e.SocketErrorCode) | ||
197 | { | ||
198 | case SocketError.AlreadyInProgress: | ||
199 | return; | ||
200 | |||
201 | case SocketError.NetworkReset: | ||
202 | case SocketError.ConnectionReset: | ||
203 | break; | ||
204 | |||
205 | default: | ||
206 | throw; | ||
207 | } | ||
208 | } | ||
209 | catch (ObjectDisposedException e) | ||
210 | { | ||
211 | m_log.DebugFormat("[CLIENT]: ObjectDisposedException: Object {0} disposed.", e.ObjectName); | ||
212 | // Uhh, what object, and why? this needs better handling. | ||
213 | } | ||
214 | |||
215 | if (ok) | ||
216 | { | 186 | { |
217 | // Make sure we are getting zeroes when running off the | 187 | // Make sure we are getting zeroes when running off the |
218 | // end of grab / degrab packets from old clients | 188 | // end of grab / degrab packets from old clients |
@@ -297,7 +267,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
297 | } | 267 | } |
298 | } | 268 | } |
299 | 269 | ||
300 | private void BeginReceive() | 270 | /// <summary> |
271 | /// Begin an asynchronous receive of the next bit of raw data | ||
272 | /// </summary> | ||
273 | protected virtual void BeginReceive() | ||
301 | { | 274 | { |
302 | try | 275 | try |
303 | { | 276 | { |
@@ -315,6 +288,50 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
315 | ResetEndPoint(); | 288 | ResetEndPoint(); |
316 | } | 289 | } |
317 | } | 290 | } |
291 | |||
292 | /// <summary> | ||
293 | /// Finish the process of asynchronously receiving the next bit of raw data | ||
294 | /// </summary> | ||
295 | /// <param name="numBytes">The number of bytes received. Will return 0 if no bytes were recieved | ||
296 | /// <param name="result"></param> | ||
297 | /// <param name="epSender">The sender of the data</param> | ||
298 | /// <returns></returns> | ||
299 | protected virtual bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender) | ||
300 | { | ||
301 | bool hasReceivedOkay = false; | ||
302 | numBytes = 0; | ||
303 | |||
304 | try | ||
305 | { | ||
306 | numBytes = m_socket.EndReceiveFrom(result, ref epSender); | ||
307 | hasReceivedOkay = true; | ||
308 | } | ||
309 | catch (SocketException e) | ||
310 | { | ||
311 | // TODO : Actually only handle those states that we have control over, re-throw everything else, | ||
312 | // TODO: implement cases as we encounter them. | ||
313 | //m_log.Error("[[CLIENT]: ]: Connection Error! - " + e.ToString()); | ||
314 | switch (e.SocketErrorCode) | ||
315 | { | ||
316 | case SocketError.AlreadyInProgress: | ||
317 | return hasReceivedOkay; | ||
318 | |||
319 | case SocketError.NetworkReset: | ||
320 | case SocketError.ConnectionReset: | ||
321 | break; | ||
322 | |||
323 | default: | ||
324 | throw; | ||
325 | } | ||
326 | } | ||
327 | catch (ObjectDisposedException e) | ||
328 | { | ||
329 | m_log.DebugFormat("[CLIENT]: ObjectDisposedException: Object {0} disposed.", e.ObjectName); | ||
330 | // Uhh, what object, and why? this needs better handling. | ||
331 | } | ||
332 | |||
333 | return hasReceivedOkay; | ||
334 | } | ||
318 | 335 | ||
319 | private void ResetEndPoint() | 336 | private void ResetEndPoint() |
320 | { | 337 | { |
diff --git a/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs b/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs index 3b3eb91..cf24e58 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs | |||
@@ -44,10 +44,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
44 | [Test] | 44 | [Test] |
45 | public void TestAddClient() | 45 | public void TestAddClient() |
46 | { | 46 | { |
47 | IClientNetworkServer llUdpServer = new LLUDPServer(); | 47 | TestLLUDPServer testLLUDPServer = new TestLLUDPServer(); |
48 | 48 | ||
49 | uint port = 666; | 49 | uint port = 666; |
50 | llUdpServer.Initialise(null, ref port, -1, false, new ClientStackUserSettings(), null, null); | 50 | testLLUDPServer.Initialise(null, ref port, -1, false, new ClientStackUserSettings(), null, null); |
51 | 51 | ||
52 | //UseCircuitCodePacket uccp = new UseCircuitCodePacket(); | 52 | //UseCircuitCodePacket uccp = new UseCircuitCodePacket(); |
53 | //llUdpServer.epS | 53 | //llUdpServer.epS |
diff --git a/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs new file mode 100755 index 0000000..5e7cbca --- /dev/null +++ b/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs | |||
@@ -0,0 +1,54 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Net; | ||
30 | using OpenSim.Framework; | ||
31 | using OpenSim.Framework.Communications.Cache; | ||
32 | |||
33 | namespace OpenSim.Region.ClientStack.LindenUDP | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// This class enables synchronous testing of the LLUDPServer by allowing us to load our own data into the end | ||
37 | /// receive event | ||
38 | /// </summary> | ||
39 | public class TestLLUDPServer : LLUDPServer | ||
40 | { | ||
41 | protected override void BeginReceive() | ||
42 | { | ||
43 | // Do nothing | ||
44 | } | ||
45 | |||
46 | protected override bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender) | ||
47 | { | ||
48 | // TODO: Return a packet loaded in by a test | ||
49 | numBytes = 0; | ||
50 | |||
51 | return true; | ||
52 | } | ||
53 | } | ||
54 | } | ||