* Refactor LLUDPServer slightly so that unit tests can pass in data synchronously. Shouldn't be any functional change
parent
f5371b6635
commit
ee3c428040
|
@ -180,39 +180,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
|||
{
|
||||
Packet packet = null;
|
||||
int numBytes = 1;
|
||||
bool ok = false;
|
||||
EndPoint epSender = new IPEndPoint(IPAddress.Any, 0);
|
||||
|
||||
try
|
||||
{
|
||||
numBytes = m_socket.EndReceiveFrom(result, ref epSender);
|
||||
ok = true;
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
// TODO : Actually only handle those states that we have control over, re-throw everything else,
|
||||
// TODO: implement cases as we encounter them.
|
||||
//m_log.Error("[[CLIENT]: ]: Connection Error! - " + e.ToString());
|
||||
switch (e.SocketErrorCode)
|
||||
{
|
||||
case SocketError.AlreadyInProgress:
|
||||
return;
|
||||
|
||||
case SocketError.NetworkReset:
|
||||
case SocketError.ConnectionReset:
|
||||
break;
|
||||
|
||||
default:
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch (ObjectDisposedException e)
|
||||
{
|
||||
m_log.DebugFormat("[CLIENT]: ObjectDisposedException: Object {0} disposed.", e.ObjectName);
|
||||
// Uhh, what object, and why? this needs better handling.
|
||||
}
|
||||
|
||||
if (ok)
|
||||
if (EndReceive(out numBytes, result, ref epSender))
|
||||
{
|
||||
// Make sure we are getting zeroes when running off the
|
||||
// end of grab / degrab packets from old clients
|
||||
|
@ -297,7 +267,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
|||
}
|
||||
}
|
||||
|
||||
private void BeginReceive()
|
||||
/// <summary>
|
||||
/// Begin an asynchronous receive of the next bit of raw data
|
||||
/// </summary>
|
||||
protected virtual void BeginReceive()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -315,6 +288,50 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
|||
ResetEndPoint();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finish the process of asynchronously receiving the next bit of raw data
|
||||
/// </summary>
|
||||
/// <param name="numBytes">The number of bytes received. Will return 0 if no bytes were recieved
|
||||
/// <param name="result"></param>
|
||||
/// <param name="epSender">The sender of the data</param>
|
||||
/// <returns></returns>
|
||||
protected virtual bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender)
|
||||
{
|
||||
bool hasReceivedOkay = false;
|
||||
numBytes = 0;
|
||||
|
||||
try
|
||||
{
|
||||
numBytes = m_socket.EndReceiveFrom(result, ref epSender);
|
||||
hasReceivedOkay = true;
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
// TODO : Actually only handle those states that we have control over, re-throw everything else,
|
||||
// TODO: implement cases as we encounter them.
|
||||
//m_log.Error("[[CLIENT]: ]: Connection Error! - " + e.ToString());
|
||||
switch (e.SocketErrorCode)
|
||||
{
|
||||
case SocketError.AlreadyInProgress:
|
||||
return hasReceivedOkay;
|
||||
|
||||
case SocketError.NetworkReset:
|
||||
case SocketError.ConnectionReset:
|
||||
break;
|
||||
|
||||
default:
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch (ObjectDisposedException e)
|
||||
{
|
||||
m_log.DebugFormat("[CLIENT]: ObjectDisposedException: Object {0} disposed.", e.ObjectName);
|
||||
// Uhh, what object, and why? this needs better handling.
|
||||
}
|
||||
|
||||
return hasReceivedOkay;
|
||||
}
|
||||
|
||||
private void ResetEndPoint()
|
||||
{
|
||||
|
|
|
@ -44,10 +44,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
|||
[Test]
|
||||
public void TestAddClient()
|
||||
{
|
||||
IClientNetworkServer llUdpServer = new LLUDPServer();
|
||||
TestLLUDPServer testLLUDPServer = new TestLLUDPServer();
|
||||
|
||||
uint port = 666;
|
||||
llUdpServer.Initialise(null, ref port, -1, false, new ClientStackUserSettings(), null, null);
|
||||
testLLUDPServer.Initialise(null, ref port, -1, false, new ClientStackUserSettings(), null, null);
|
||||
|
||||
//UseCircuitCodePacket uccp = new UseCircuitCodePacket();
|
||||
//llUdpServer.epS
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Communications.Cache;
|
||||
|
||||
namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
{
|
||||
/// <summary>
|
||||
/// This class enables synchronous testing of the LLUDPServer by allowing us to load our own data into the end
|
||||
/// receive event
|
||||
/// </summary>
|
||||
public class TestLLUDPServer : LLUDPServer
|
||||
{
|
||||
protected override void BeginReceive()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
protected override bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender)
|
||||
{
|
||||
// TODO: Return a packet loaded in by a test
|
||||
numBytes = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue