Merge branch 'master' into httptests

This commit is contained in:
UbitUmarov
2017-06-14 03:04:14 +01:00
42 changed files with 733 additions and 283 deletions

View File

@@ -325,6 +325,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// </summary>
public LLImageManager ImageManager { get; private set; }
public JobEngine m_asyncPacketProcess;
private readonly LLUDPServer m_udpServer;
private readonly LLUDPClient m_udpClient;
private readonly UUID m_sessionId;
@@ -378,7 +379,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
protected Scene m_scene;
protected string m_firstName;
protected string m_lastName;
protected Thread m_clientThread;
protected Vector3 m_startpos;
protected UUID m_activeGroupID;
protected string m_activeGroupName = String.Empty;
@@ -529,7 +529,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_prioritizer = new Prioritizer(m_scene);
RegisterLocalPacketHandlers();
string name = string.Format("AsyncInUDP-{0}",m_agentId.ToString());
m_asyncPacketProcess = new JobEngine(name, name, 10000);
IsActive = true;
}
@@ -592,6 +593,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (OnConnectionClosed != null)
OnConnectionClosed(this);
m_asyncPacketProcess.Stop();
// Flush all of the packets out of the UDP server for this client
if (m_udpServer != null)
@@ -778,12 +780,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
cinfo.AsyncRequests[packet.Type.ToString()]++;
object obj = new AsyncPacketProcess(this, pprocessor.method, packet);
/*
if (pprocessor.InEngine)
m_udpServer.IpahEngine.QueueJob(packet.Type.ToString(), () => ProcessSpecificPacketAsync(obj));
else
Util.FireAndForget(ProcessSpecificPacketAsync, obj, packet.Type.ToString());
*/
m_asyncPacketProcess.QueueJob(packet.Type.ToString(), () => ProcessSpecificPacketAsync(obj));
result = true;
}
else
@@ -841,6 +844,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public virtual void Start()
{
m_asyncPacketProcess.Start();
m_scene.AddNewAgent(this, PresenceType.User);
// RefreshGroupMembership();
@@ -6036,8 +6040,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
AddLocalPacketHandler(PacketType.ObjectExtraParams, HandleObjectExtraParams);
AddLocalPacketHandler(PacketType.ObjectDuplicate, HandleObjectDuplicate);
AddLocalPacketHandler(PacketType.RequestMultipleObjects, HandleRequestMultipleObjects);
AddLocalPacketHandler(PacketType.ObjectSelect, HandleObjectSelect);
AddLocalPacketHandler(PacketType.ObjectDeselect, HandleObjectDeselect);
AddLocalPacketHandler(PacketType.ObjectSelect, HandleObjectSelect, true, true);
AddLocalPacketHandler(PacketType.ObjectDeselect, HandleObjectDeselect, true, true);
AddLocalPacketHandler(PacketType.ObjectPosition, HandleObjectPosition);
AddLocalPacketHandler(PacketType.ObjectScale, HandleObjectScale);
AddLocalPacketHandler(PacketType.ObjectRotation, HandleObjectRotation);
@@ -8030,19 +8034,41 @@ namespace OpenSim.Region.ClientStack.LindenUDP
return true;
}
Dictionary<uint, uint> objImageSeqs = null;
double lastobjImageSeqsMS = 0.0;
private bool HandleObjectImage(IClientAPI sender, Packet Pack)
{
ObjectImagePacket imagePack = (ObjectImagePacket)Pack;
UpdatePrimTexture handlerUpdatePrimTexture = null;
UpdatePrimTexture handlerUpdatePrimTexture = OnUpdatePrimTexture;
if (handlerUpdatePrimTexture == null)
return true;
double now = Util.GetTimeStampMS();
if(objImageSeqs == null || ( now - lastobjImageSeqsMS > 30000.0))
{
objImageSeqs = null; // yeah i know superstition...
objImageSeqs = new Dictionary<uint, uint>(16);
}
lastobjImageSeqsMS = now;
uint seq = Pack.Header.Sequence;
uint id;
uint lastseq;
ObjectImagePacket.ObjectDataBlock o;
for (int i = 0; i < imagePack.ObjectData.Length; i++)
{
handlerUpdatePrimTexture = OnUpdatePrimTexture;
if (handlerUpdatePrimTexture != null)
{
handlerUpdatePrimTexture(imagePack.ObjectData[i].ObjectLocalID,
imagePack.ObjectData[i].TextureEntry, this);
}
o = imagePack.ObjectData[i];
id = o.ObjectLocalID;
if(objImageSeqs.TryGetValue(id, out lastseq))
{
if(seq <= lastseq)
continue;
}
objImageSeqs[id] = seq;
handlerUpdatePrimTexture(id, o.TextureEntry, this);
}
return true;
}

View File

@@ -312,9 +312,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// stack. Use zero to leave this value as the default</summary>
protected int m_recvBufferSize;
/// <summary>Flag to process packets asynchronously or synchronously</summary>
protected bool m_asyncPacketHandling;
/// <summary>Tracks whether or not a packet was sent each round so we know
/// whether or not to sleep</summary>
protected bool m_packetSent;
@@ -417,7 +414,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// Queue some low priority but potentially high volume async requests so that they don't overwhelm available
/// threadpool threads.
/// </summary>
public JobEngine IpahEngine { get; protected set; }
// public JobEngine IpahEngine { get; protected set; }
/// <summary>
/// Run queue empty processing within a single persistent thread.
@@ -473,7 +470,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
IConfig config = configSource.Configs["ClientStack.LindenUDP"];
if (config != null)
{
m_asyncPacketHandling = config.GetBoolean("async_packet_handling", true);
m_recvBufferSize = config.GetInt("client_socket_rcvbuf_size", 0);
sceneThrottleBps = config.GetInt("scene_throttle_max_bps", 0);
@@ -531,7 +527,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
{
StartInbound();
StartOutbound();
IpahEngine.Start();
// IpahEngine.Start();
OqrEngine.Start();
m_elapsedMSSinceLastStatReport = Environment.TickCount;
@@ -540,10 +536,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public void StartInbound()
{
m_log.InfoFormat(
"[LLUDPSERVER]: Starting inbound packet processing for the LLUDP server in {0} mode with UsePools = {1}",
m_asyncPacketHandling ? "asynchronous" : "synchronous", UsePools);
"[LLUDPSERVER]: Starting inbound packet processing for the LLUDP server");
base.StartInbound(m_recvBufferSize, m_asyncPacketHandling);
base.StartInbound(m_recvBufferSize);
// This thread will process the packets received that are placed on the packetInbox
WorkManager.StartThread(
@@ -577,7 +572,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_log.Info("[LLUDPSERVER]: Shutting down the LLUDP server for " + Scene.Name);
base.StopOutbound();
base.StopInbound();
IpahEngine.Stop();
// IpahEngine.Stop();
OqrEngine.Stop();
}
@@ -696,12 +691,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
Scene = (Scene)scene;
m_location = new Location(Scene.RegionInfo.RegionHandle);
/*
IpahEngine
= new JobEngine(
string.Format("Incoming Packet Async Handling Engine ({0})", Scene.Name),
"INCOMING PACKET ASYNC HANDLING ENGINE");
*/
OqrEngine
= new JobEngine(
string.Format("Outgoing Queue Refill Engine ({0})", Scene.Name),
@@ -786,7 +781,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
MeasuresOfInterest.AverageChangeOverTime,
stat => stat.Value = GetTotalQueuedOutgoingPackets(),
StatVerbosity.Info));
/*
StatsManager.RegisterStat(
new Stat(
"IncomingPacketAsyncRequestsWaiting",
@@ -799,7 +794,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
MeasuresOfInterest.None,
stat => stat.Value = IpahEngine.JobsWaiting,
StatVerbosity.Debug));
*/
StatsManager.RegisterStat(
new Stat(
"OQRERequestsWaiting",
@@ -1227,7 +1222,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
outgoingPacket.SequenceNumber, isReliable, isResend, udpClient.AgentID, Scene.Name);
// Put the UDP payload on the wire
AsyncBeginSend(buffer);
// AsyncBeginSend(buffer);
SyncSend(buffer);
// Keep track of when this packet was sent out (right now)
outgoingPacket.TickCount = Environment.TickCount & Int32.MaxValue;
@@ -1912,7 +1908,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
Buffer.BlockCopy(packetData, 0, buffer.Data, 0, length);
AsyncBeginSend(buffer);
// AsyncBeginSend(buffer);
SyncSend(buffer);
}
protected bool IsClientAuthorized(UseCircuitCodePacket useCircuitCode, out AuthenticateResponse sessionInfo)

View File

@@ -57,9 +57,6 @@ namespace OpenMetaverse
/// <summary>UDP socket, used in either client or server mode</summary>
private Socket m_udpSocket;
/// <summary>Flag to process packets asynchronously or synchronously</summary>
private bool m_asyncPacketHandling;
/// <summary>
/// Are we to use object pool(s) to reduce memory churn when receiving data?
/// </summary>
@@ -205,10 +202,8 @@ namespace OpenMetaverse
/// manner (not throwing an exception when the remote side resets the
/// connection). This call is ignored on Mono where the flag is not
/// necessary</remarks>
public virtual void StartInbound(int recvBufferSize, bool asyncPacketHandling)
public virtual void StartInbound(int recvBufferSize)
{
m_asyncPacketHandling = asyncPacketHandling;
if (!IsRunningInbound)
{
m_log.DebugFormat("[UDPBASE]: Starting inbound UDP loop");
@@ -407,12 +402,7 @@ namespace OpenMetaverse
if (IsRunningInbound)
{
UdpReceives++;
// Asynchronous mode will start another receive before the
// callback for this packet is even fired. Very parallel :-)
if (m_asyncPacketHandling)
AsyncBeginReceive();
try
{
// get the buffer that was created in AsyncBeginReceive
@@ -469,10 +459,7 @@ namespace OpenMetaverse
// if (UsePools)
// Pool.ReturnObject(buffer);
// Synchronous mode waits until the packet callback completes
// before starting the receive to fetch another packet
if (!m_asyncPacketHandling)
AsyncBeginReceive();
AsyncBeginReceive();
}
}
}
@@ -500,7 +487,7 @@ namespace OpenMetaverse
}
catch (SocketException) { }
catch (ObjectDisposedException) { }
// }
// }
}
void AsyncEndSend(IAsyncResult result)
@@ -515,5 +502,25 @@ namespace OpenMetaverse
catch (SocketException) { }
catch (ObjectDisposedException) { }
}
public void SyncSend(UDPPacketBuffer buf)
{
try
{
m_udpSocket.SendTo(
buf.Data,
0,
buf.DataLength,
SocketFlags.None,
buf.RemoteEndPoint
);
UdpSends++;
}
catch (SocketException e)
{
m_log.Warn("[UDPBASE]: sync send SocketException {0} " + e.Message);
}
catch (ObjectDisposedException) { }
}
}
}

View File

@@ -91,6 +91,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
/// <summary>
/// Test adding a client to the stack
/// </summary>
/*
[Test]
public void TestAddClient()
{
@@ -165,7 +166,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
ScenePresence spAfterAckTimeout = m_scene.GetScenePresence(sp.UUID);
Assert.That(spAfterAckTimeout, Is.Null);
}
*/
// /// <summary>
// /// Test removing a client from the stack
// /// </summary>