本文整理汇总了C#中OpenSim.Region.ClientStack.LindenUDP.OutgoingPacket类的典型用法代码示例。如果您正苦于以下问题:C# OutgoingPacket类的具体用法?C# OutgoingPacket怎么用?C# OutgoingPacket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OutgoingPacket类属于OpenSim.Region.ClientStack.LindenUDP命名空间,在下文中一共展示了OutgoingPacket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnqueueOutgoing
public bool EnqueueOutgoing(OutgoingPacket packet)
{
int category = (int) packet.Category;
if (category >= 0 && category < (int) ThrottleOutPacketType.Count)
{
//All packets are enqueued, except those that don't have a queue
int prio = MapCatsToPriority[category];
m_outbox.Enqueue(prio, packet);
return true;
}
// We don't have a token bucket for this category,
// so it will not be queued and sent immediately
return false;
}
示例2: DequeueOutgoing
/// <summary>
/// tries to send queued packets
/// </summary>
/// <remarks>
/// This function is only called from a synchronous loop in the
/// UDPServer so we don't need to bother making this thread safe
/// </remarks>
/// <returns>True if any packets were sent, otherwise false</returns>
public bool DequeueOutgoing(int MaxNPacks)
{
bool packetSent = false;
for (int i = 0; i < MaxNPacks; i++)
{
OutgoingPacket packet;
if (m_nextOutPacket != null)
{
packet = m_nextOutPacket;
if (m_throttle.RemoveTokens(packet.Buffer.DataLength))
{
// Send the packet
m_udpServer.SendPacketFinal(packet);
m_nextOutPacket = null;
packetSent = true;
}
}
// No dequeued packet waiting to be sent, try to pull one off
// this queue
else if (m_outbox.Dequeue(out packet))
{
MainConsole.Instance.Output(AgentID + " - " + packet.Packet.Type, "Verbose");
// A packet was pulled off the queue. See if we have
// enough tokens in the bucket to send it out
if (packet.Category == ThrottleOutPacketType.OutBand ||
m_throttle.RemoveTokens(packet.Buffer.DataLength))
{
packetSent = true;
//Send the packet
PacketsCounts[(int) packet.Category] += packet.Packet.Length;
m_udpServer.SendPacketFinal(packet);
PacketsSent++;
}
else
{
m_nextOutPacket = packet;
break;
}
}
else
break;
}
if (packetSent)
{
if (m_throttle.MaxBurst < TotalRateRequested)
{
float tmp = m_throttle.MaxBurst*1.005f;
m_throttle.DripRate = (int) tmp;
m_throttle.MaxBurst = (int) tmp;
}
}
if (m_nextOnQueueEmpty != 0 && Util.EnvironmentTickCountSubtract(m_nextOnQueueEmpty) >= 0)
{
// Use a value of 0 to signal that FireQueueEmpty is running
m_nextOnQueueEmpty = 0;
// Asynchronously run the callback
int ptmp = m_outbox.queues[MapCatsToPriority[(int) ThrottleOutPacketType.Task]].Count;
int atmp = m_outbox.queues[MapCatsToPriority[(int) ThrottleOutPacketType.AvatarInfo]].Count;
int ttmp = m_outbox.queues[MapCatsToPriority[(int) ThrottleOutPacketType.Texture]].Count;
int[] arg = {ptmp, atmp, ttmp};
Util.FireAndForget(FireQueueEmpty, arg);
}
return packetSent;
}
示例3: EnqueueOutgoing
/// <summary>
/// Queue an outgoing packet if appropriate.
/// </summary>
/// <param name="packet"></param>
/// <param name="forceQueue">Always queue the packet if at all possible.</param>
/// <returns>
/// true if the packet has been queued,
/// false if the packet has not been queued and should be sent immediately.
/// </returns>
public bool EnqueueOutgoing(OutgoingPacket packet, bool forceQueue)
{
int category = (int)packet.Category;
if (category >= 0 && category < m_packetOutboxes.Length)
{
OpenSim.Framework.LocklessQueue<OutgoingPacket> queue = m_packetOutboxes[category];
TokenBucket bucket = m_throttleCategories[category];
// Don't send this packet if there is already a packet waiting in the queue
// even if we have the tokens to send it, tokens should go to the already
// queued packets
if (queue.Count > 0)
{
queue.Enqueue(packet);
return true;
}
if (!forceQueue && bucket.RemoveTokens(packet.Buffer.DataLength))
{
// Enough tokens were removed from the bucket, the packet will not be queued
return false;
}
else
{
// Force queue specified or not enough tokens in the bucket, queue this packet
queue.Enqueue(packet);
return true;
}
}
else
{
// We don't have a token bucket for this category, so it will not be queued
return false;
}
}
示例4: Dequeue
public bool Dequeue(out OutgoingPacket pack)
{
int i = nlevels;
while (--i >= 0) // go down levels looking for data
{
object o;
if (!queues[i].Dequeue(out o)) continue;
if (!(o is OutgoingPacket)) continue;
pack = (OutgoingPacket) o;
Interlocked.Decrement(ref Count);
return true;
// else do call to a funtion that will return the packet or whatever
}
pack = null;
return false;
}
示例5: SendPacketFinal
/// <summary>
/// Actually send a packet to a client.
/// </summary>
/// <param name="outgoingPacket"></param>
internal void SendPacketFinal(OutgoingPacket outgoingPacket)
{
UDPPacketBuffer buffer = outgoingPacket.Buffer;
byte flags = buffer.Data[0];
bool isResend = (flags & Helpers.MSG_RESENT) != 0;
bool isReliable = (flags & Helpers.MSG_RELIABLE) != 0;
bool isZerocoded = (flags & Helpers.MSG_ZEROCODED) != 0;
LLUDPClient udpClient = outgoingPacket.Client;
if (!udpClient.IsConnected)
return;
#region ACK Appending
int dataLength = buffer.DataLength;
// NOTE: I'm seeing problems with some viewers when ACKs are appended to zerocoded packets so I've disabled that here
if (!isZerocoded)
{
// Keep appending ACKs until there is no room left in the buffer or there are
// no more ACKs to append
uint ackCount = 0;
uint ack;
while (dataLength + 5 < buffer.Data.Length && udpClient.PendingAcks.Dequeue(out ack))
{
Utils.UIntToBytesBig(ack, buffer.Data, dataLength);
dataLength += 4;
++ackCount;
}
if (ackCount > 0)
{
// Set the last byte of the packet equal to the number of appended ACKs
buffer.Data[dataLength++] = (byte)ackCount;
// Set the appended ACKs flag on this packet
buffer.Data[0] = (byte)(buffer.Data[0] | Helpers.MSG_APPENDED_ACKS);
}
}
buffer.DataLength = dataLength;
#endregion ACK Appending
#region Sequence Number Assignment
if (!isResend)
{
// Not a resend, assign a new sequence number
uint sequenceNumber = (uint)Interlocked.Increment(ref udpClient.CurrentSequence);
Utils.UIntToBytesBig(sequenceNumber, buffer.Data, 1);
outgoingPacket.SequenceNumber = sequenceNumber;
if (isReliable)
{
// Add this packet to the list of ACK responses we are waiting on from the server
udpClient.NeedAcks.Add(outgoingPacket);
}
}
else
{
Interlocked.Increment(ref udpClient.PacketsResent);
}
#endregion Sequence Number Assignment
// Stats tracking
Interlocked.Increment(ref udpClient.PacketsSent);
// Put the UDP payload on the wire
AsyncBeginSend(buffer);
// Keep track of when this packet was sent out (right now)
outgoingPacket.TickCount = Environment.TickCount & Int32.MaxValue;
}
示例6: SendPacketData
public void SendPacketData(LLUDPClient udpClient, byte[] data, int dataLength, PacketType type,
ThrottleOutPacketType category, bool bufferAcquiredFromPool)
{
bool doZerocode = (data[0] & Helpers.MSG_ZEROCODED) != 0;
bool zeroCoded = false;
byte[] outBuffer = null;
// Zerocode if needed
if (doZerocode)
{
// Frequency analysis of outgoing packet sizes shows a large clump of packets at each end of the spectrum.
// The vast majority of packets are less than 200 bytes, although due to asset transfers and packet splitting
// there are a decent number of packets in the 1000-1140 byte range. We allocate one of two sizes of data here
// to accomodate for both common scenarios and provide ample room for ACK appending in both
int bufferSize = (dataLength > 180) ? LLUDPServer.MTU : 200;
try
{
//zerocode and return the current buffer to the pool if necessary
outBuffer = _bufferPool.LeaseBytes(bufferSize);
dataLength = Helpers.ZeroEncode(data, dataLength, outBuffer);
zeroCoded = true;
if (bufferAcquiredFromPool)
{
_bufferPool.ReturnBytes(data);
}
//now the buffer is from a pool most definitely
bufferAcquiredFromPool = true;
}
catch (IndexOutOfRangeException)
{
//TODO: Throwing an exception here needs to be revisted. I've seen an issue with
//70+ avatars where a very common high freq packet hits this code everytime
//that packet either needs to be split, or this needs to be revised to not throw
//and instead check the buffer size and return an error condition
// The packet grew larger than the bufferSize while zerocoding.
// Remove the MSG_ZEROCODED flag and send the unencoded data
// instead
m_log.Debug("[LLUDPSERVER]: Packet exceeded buffer size during zerocoding for " + type + ". DataLength=" + dataLength +
" and BufferLength=" + outBuffer.Length + ". Removing MSG_ZEROCODED flag");
data[0] = (byte)(data[0] & ~Helpers.MSG_ZEROCODED);
_bufferPool.ReturnBytes(outBuffer);
}
}
if (! zeroCoded)
{
outBuffer = data;
}
#region Queue or Send
OutgoingPacket outgoingPacket = new OutgoingPacket(udpClient, outBuffer, (int)category, dataLength,
udpClient.RemoteEndPoint, bufferAcquiredFromPool, type);
if (!udpClient.EnqueueOutgoing(outgoingPacket))
SendPacketFinal(outgoingPacket);
#endregion Queue or Send
}
示例7: EnqueueOutgoing
public bool EnqueueOutgoing(OutgoingPacket packet)
{
int category = (int)packet.Category;
int prio;
if (category >= 0 && category < m_packetOutboxes.Length )
{
//All packets are enqueued, except those that don't have a queue
prio = MapCatsToPriority[category];
m_outbox.Enqueue(prio, (object)packet);
return true;
}
else
{
// all known packs should have a known
// We don't have a token bucket for this category, so it will not be queued
return false;
}
}
示例8: EnqueueOutgoing
public bool EnqueueOutgoing(OutgoingPacket packet)
{
int category = (int)packet.Category;
if (category >= 0 && category < m_packetOutboxes.Length)
{
OpenSim.Framework.LocklessQueue<OutgoingPacket> queue = m_packetOutboxes[category];
// Not enough tokens in the bucket, queue this packet
//check the queue
//Dont drop resends this can mess up the buffer pool as well as make the connection situation much worse
if (_currentOutboundQueueSize > MAX_TOTAL_QUEUE_SIZE && (packet.Buffer[0] & Helpers.MSG_RESENT) == 0)
{
//queue already has too much data in it..
//can we drop this packet?
byte flags = packet.Buffer[0];
bool isReliable = (flags & Helpers.MSG_RELIABLE) != 0;
if (!isReliable
&& packet.Type != PacketType.PacketAck
&& packet.Type != PacketType.CompletePingCheck)
{
//packet is unreliable and will be dropped
this.TestReportPacketDrop(packet);
packet.DecRef(m_udpServer.ByteBufferPool);
}
else
{
if (_currentOutboundQueueSize < MAX_TOTAL_QUEUE_SIZE * 1.5)
{
this.TestReportPacketShouldDrop(packet);
Interlocked.Add(ref _currentOutboundQueueSize, packet.DataSize);
packet.AddRef();
queue.Enqueue(packet);
}
else
{
//this connection is in a pretty critical state and probably will never catch up.
//drop all packets until we start to catch up. This includes acks which will disconnect
//the client eventually anyways
this.TestReportCriticalPacketDrop(packet);
packet.DecRef(m_udpServer.ByteBufferPool);
}
}
}
else
{
Interlocked.Add(ref _currentOutboundQueueSize, packet.DataSize);
packet.AddRef();
queue.Enqueue(packet);
}
return true;
}
else
{
// We don't have a token bucket for this category, so it will not be queued
return false;
}
}
示例9: Add
/// <summary>
/// Add an unacked packet to the collection
/// </summary>
/// <param name="packet">Packet that is awaiting acknowledgement</param>
/// <returns>True if the packet was successfully added, false if the
/// packet already existed in the collection</returns>
/// <remarks>This does not immediately add the ACK to the collection,
/// it only queues it so it can be added in a thread-safe way later</remarks>
public void Add(OutgoingPacket packet)
{
packet.AddRef();
m_pendingAdds.Enqueue(packet);
}
示例10: EnqueueOutgoing
public bool EnqueueOutgoing(OutgoingPacket packet)
{
int category = (int)packet.Category;
if (category >= 0 && category < m_packetOutboxes.Length)
{
OpenSim.Framework.LocklessQueue<OutgoingPacket> queue = m_packetOutboxes[category];
TokenBucket bucket = m_throttleCategories[category];
if (bucket.RemoveTokens(packet.Buffer.DataLength))
{
// Enough tokens were removed from the bucket, the packet will not be queued
return false;
}
else
{
// Not enough tokens in the bucket, queue this packet
queue.Enqueue(packet);
return true;
}
}
else
{
// We don't have a token bucket for this category, so it will not be queued
return false;
}
}
示例11: Add
/// <summary>
/// Add an unacked packet to the collection
/// </summary>
/// <param name="packet">Packet that is awaiting acknowledgement</param>
/// <returns>True if the packet was successfully added, false if the
/// packet already existed in the collection</returns>
/// <remarks>This does not immediately add the ACK to the collection,
/// it only queues it so it can be added in a thread-safe way later</remarks>
public void Add(OutgoingPacket packet)
{
m_pendingAdds.Enqueue(packet);
Interlocked.Add(ref packet.Client.UnackedBytes, packet.Buffer.DataLength);
}
示例12: Add
/// <summary>
/// Add an unacked packet to the collection
/// </summary>
/// <param name="packet">Packet that is awaiting acknowledgement</param>
/// <returns>True if the packet was successfully added, false if the
/// packet already existed in the collection</returns>
/// <remarks>This does not immediately add the ACK to the collection,
/// it only queues it so it can be added in a thread-safe way later</remarks>
public void Add(OutgoingPacket packet)
{
m_pendingAdds.Enqueue(packet);
}
示例13: SendAckImmediate
private void SendAckImmediate(IPEndPoint remoteEndpoint, uint sequenceNumber)
{
PacketAckPacket ack = new PacketAckPacket();
ack.Header.Reliable = false;
ack.Packets = new PacketAckPacket.PacketsBlock[1];
ack.Packets[0] = new PacketAckPacket.PacketsBlock();
ack.Packets[0].ID = sequenceNumber;
byte[] packetData = ack.ToBytes();
int length = packetData.Length;
OutgoingPacket outgoingPacket = new OutgoingPacket(null, packetData, 0, length,
remoteEndpoint, false, PacketType.PacketAck);
AsyncBeginSend(outgoingPacket);
}
示例14: SendPacketData
public void SendPacketData(LLUDPClient udpClient, byte[] data, Packet packet, ThrottleOutPacketType category, UnackedPacketMethod resendMethod, UnackedPacketMethod finishedMethod)
{
int dataLength = data.Length;
bool doZerocode = (data[0] & Helpers.MSG_ZEROCODED) != 0;
bool doCopy = true;
// Frequency analysis of outgoing packet sizes shows a large clump of packets at each end of the spectrum.
// The vast majority of packets are less than 200 bytes, although due to asset transfers and packet splitting
// there are a decent number of packets in the 1000-1140 byte range. We allocate one of two sizes of data here
// to accomodate for both common scenarios and provide ample room for ACK appending in both
int bufferSize = dataLength * 2;
UDPPacketBuffer buffer = new UDPPacketBuffer(udpClient.RemoteEndPoint, bufferSize);
// Zerocode if needed
if (doZerocode)
{
try
{
dataLength = Helpers.ZeroEncode(data, dataLength, buffer.Data);
doCopy = false;
}
catch (IndexOutOfRangeException)
{
// The packet grew larger than the bufferSize while zerocoding.
// Remove the MSG_ZEROCODED flag and send the unencoded data
// instead
m_log.Info("[LLUDPSERVER]: Packet exceeded buffer size during zerocoding for " + packet.Type + ". DataLength=" + dataLength +
" and BufferLength=" + buffer.Data.Length + ". Removing MSG_ZEROCODED flag");
data[0] = (byte)(data[0] & ~Helpers.MSG_ZEROCODED);
}
}
// If the packet data wasn't already copied during zerocoding, copy it now
if (doCopy)
{
if (dataLength <= buffer.Data.Length)
{
Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
}
else
{
bufferSize = dataLength;
buffer = new UDPPacketBuffer(udpClient.RemoteEndPoint, bufferSize);
// m_log.Error("[LLUDPSERVER]: Packet exceeded buffer size! This could be an indication of packet assembly not obeying the MTU. Type=" +
// type + ", DataLength=" + dataLength + ", BufferLength=" + buffer.Data.Length + ". Dropping packet");
Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
}
}
buffer.DataLength = dataLength;
#region Queue or Send
OutgoingPacket outgoingPacket = new OutgoingPacket(udpClient, buffer, category, resendMethod, finishedMethod, packet);
if (!outgoingPacket.Client.EnqueueOutgoing(outgoingPacket))
SendPacketFinal(outgoingPacket);
#endregion Queue or Send
}
示例15: DequeueOutgoing
/// <summary>
/// Loops through all of the packet queues for this client and tries to send
/// an outgoing packet from each, obeying the throttling bucket limits
/// </summary>
///
/// Packet queues are inspected in ascending numerical order starting from 0. Therefore, queues with a lower
/// ThrottleOutPacketType number will see their packet get sent first (e.g. if both Land and Wind queues have
/// packets, then the packet at the front of the Land queue will be sent before the packet at the front of the
/// wind queue).
///
/// <remarks>This function is only called from a synchronous loop in the
/// UDPServer so we don't need to bother making this thread safe</remarks>
/// <returns>True if any packets were sent, otherwise false</returns>
public bool DequeueOutgoing (int MaxNPacks)
{
OutgoingPacket packet;
bool packetSent = false;
ThrottleOutPacketTypeFlags emptyCategories = 0;
if (m_nextOutPackets != null)
{
OutgoingPacket nextPacket = m_nextOutPackets;
if (m_throttle.RemoveTokens (nextPacket.Buffer.DataLength))
{
// Send the packet
m_udpServer.SendPacketFinal (nextPacket);
m_nextOutPackets = null;
packetSent = true;
this.PacketsSent++;
}
}
else
{
// No dequeued packet waiting to be sent, try to pull one off
// this queue
if (m_outbox.Dequeue (out packet))
{
// A packet was pulled off the queue. See if we have
// enough tokens in the bucket to send it out
if (packet.Category == ThrottleOutPacketType.OutBand || m_throttle.RemoveTokens (packet.Buffer.DataLength))
{
// Send the packet
m_udpServer.SendPacketFinal (packet);
packetSent = true;
if (m_throttle.MaxBurst < TotalRateRequested)
{
float tmp = (float)m_throttle.MaxBurst * 1.005f;
m_throttle.DripRate = (int)tmp;
m_throttle.MaxBurst = (int)tmp;
}
this.PacketsSent++;
}
else
{
m_nextOutPackets = packet;
}
}
else
{
emptyCategories = (ThrottleOutPacketTypeFlags)0xffff;
}
}
if (m_outbox.count < 100)
{
emptyCategories = (ThrottleOutPacketTypeFlags)0xffff;
BeginFireQueueEmpty (emptyCategories);
}
/*
if (emptyCategories != 0)
BeginFireQueueEmpty(emptyCategories);
else
{
int i = MapCatsToPriority[(int)ThrottleOutPacketType.Texture]; // hack to keep textures flowing for now
if (m_outbox.queues[i].Count < 30)
{
emptyCategories |= ThrottleOutPacketTypeFlags.Texture;
}
}
*/
//m_log.Info("[LLUDPCLIENT]: Queues: " + queueDebugOutput); // Serious debug business
return packetSent;
/*
OutgoingPacket packet;
OpenSim.Framework.LocklessQueue<OutgoingPacket> queue;
TokenBucket bucket;
bool packetSent = false;
ThrottleOutPacketTypeFlags emptyCategories = 0;
//string queueDebugOutput = String.Empty; // Serious debug business
int npacksTosent = MaxNPacks;
int i = m_lastthrottleCategoryChecked;
for (int j = 0; j < (int)ThrottleOutPacketType.OutBand; j++) // don't check OutBand
{
//.........这里部分代码省略.........