public void Destroy()
 {
     if (networkMessage != null)
     {
         networkMessage.Destroy();
     }
     networkMessage = null;
     Recycler <ReliableMessageSendTracking <T> > .ReleaseObject(this);
 }
        public void Destroy()
        {
            int usageLeft = Interlocked.Decrement(ref usageCount);

            if (usageLeft == 0)
            {
                if (data != null)
                {
                    ByteRecycler.ReleaseObject(data);
                }
                Recycler <NetworkMessage> .ReleaseObject(this);
            }
        }
 public void FireCallbacks()
 {
     if (!useMessagePump)
     {
         return;
     }
     lock (messages)
     {
         foreach (QueuedMessage <T> qm in messages)
         {
             HandleReal(qm.networkMessage, qm.connection);
             Recycler <QueuedMessage <T> > .ReleaseObject(qm);
         }
         messages.Clear();
     }
 }
Example #4
0
 public void Destroy()
 {
     networkMessage = null;
     Recycler <ReliableMessageReceiveTracking> .ReleaseObject(this);
 }
Example #5
0
        private void SendLoop()
        {
            while (running)
            {
                sendEvent.WaitOne(50);
                bool sending = true;
                while (sending)
                {
                    sending = false;
                    lock (sendHighPriorityMessages)
                    {
                        while (sendHighPriorityMessages.Count > 0)
                        {
                            QueuedMessage <T> qm = sendHighPriorityMessages.Dequeue();
                            if (qm.networkMessage.data != null)
                            {
                                qm.connection.queuedOut -= qm.networkMessage.data.Length;
                            }
                            ActualSendMessage(qm.networkMessage, qm.connection);
                            Recycler <QueuedMessage <T> > .ReleaseObject(qm);

                            sending = true;
                        }
                    }
                    lock (sendMessages)
                    {
                        foreach (KeyValuePair <Connection <T>, Queue <NetworkMessage> > kvp in sendMessages)
                        {
                            Connection <T>         connection = kvp.Key;
                            Queue <NetworkMessage> sendQueue  = kvp.Value;
                            while (sendQueue.Count > 0)
                            {
                                if (sendHighPriorityMessages.Count > 0)
                                {
                                    break;
                                }
                                NetworkMessage peekMessage = sendQueue.Peek();
                                //Reliable messages are broken up and do not create actual sends.
                                if (peekMessage.IsReliable())
                                {
                                    NetworkMessage reliableMessage = sendQueue.Dequeue();
                                    if (reliableMessage.data != null)
                                    {
                                        connection.queuedOut -= reliableMessage.data.Length;
                                    }
                                    connection.reliableMessageHandler.Queue(reliableMessage);
                                    connection.reliableMessageHandler.Send();
                                    continue;
                                }
                                else
                                {
                                    if (peekMessage.data != null)
                                    {
                                        if (peekMessage.data.Length > connection.tokens)
                                        {
                                            //Not enough tokens to send
                                            break;
                                        }
                                    }
                                    NetworkMessage sendMessage = sendQueue.Dequeue();
                                    if (sendMessage.data != null)
                                    {
                                        connection.queuedOut -= sendMessage.data.Length;
                                    }
                                    ActualSendMessage(sendMessage, connection);
                                    sending = true;
                                }
                            }
                            if (sendHighPriorityMessages.Count > 0)
                            {
                                break;
                            }
                        }
                    }
                }
                handler.SendHeartbeat();
            }
        }