示例#1
0
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!m_Disposed)
            {
                if (disposing)
                {
                    if (m_PendingPackets != null)
                    {
                        while (m_PendingPackets.Count > 0)
                        {
                            pendingPacketCount -= 1;

                            ChannelPacket packet = m_PendingPackets.Dequeue();
                            if (s_FreePackets.Count < k_MaxFreePacketCount)
                            {
                                s_FreePackets.Add(packet);
                            }
                        }
                        m_PendingPackets.Clear();
                    }
                }
            }
            m_Disposed = true;
        }
示例#2
0
        static void FreePacket(ChannelPacket packet)
        {
#if UNITY_EDITOR
            //UnityEditor.NetworkDetailStats.SetStat(
            //    UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
            //    MsgType.HLAPIPending, "msg", pendingPacketCount);
#endif
            if (s_FreePackets.Count >= k_MaxFreePacketCount)
            {
                // just discard this packet, already tracking too many free packets
                return;
            }
            s_FreePackets.Add(packet);
        }
示例#3
0
        public ChannelBuffer(NetworkConnection conn, int bufferSize, byte cid, bool isReliable, bool isSequenced)
        {
            m_Connection    = conn;
            m_MaxPacketSize = bufferSize - k_PacketHeaderReserveSize;
            m_CurrentPacket = new ChannelPacket(m_MaxPacketSize, isReliable);

            m_ChannelId             = cid;
            m_MaxPendingPacketCount = MaxBufferedPackets;
            m_IsReliable            = isReliable;
            m_AllowFragmentation    = (isReliable && isSequenced);
            if (isReliable)
            {
                m_PendingPackets = new Queue <ChannelPacket>();
                if (s_FreePackets == null)
                {
                    s_FreePackets = new List <ChannelPacket>();
                }
            }
        }
示例#4
0
 void QueuePacket()
 {
     pendingPacketCount += 1;
     m_PendingPackets.Enqueue(m_CurrentPacket);
     m_CurrentPacket = AllocPacket();
 }
示例#5
0
        public bool SetOption(ChannelOption option, int value)
        {
            switch (option)
            {
            case ChannelOption.MaxPendingBuffers:
            {
                if (!m_IsReliable)
                {
                    // not an error
                    //if (LogFilter.logError) { Debug.LogError("Cannot set MaxPendingBuffers on unreliable channel " + m_ChannelId); }
                    return(false);
                }
                if (value < 0 || value >= MaxBufferedPackets)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Invalid MaxPendingBuffers for channel " + m_ChannelId + ". Must be greater than zero and less than " + MaxBufferedPackets);
                    }
                    return(false);
                }
                m_MaxPendingPacketCount = value;
                return(true);
            }

            case ChannelOption.AllowFragmentation:
            {
                m_AllowFragmentation = (value != 0);
                return(true);
            }

            case ChannelOption.MaxPacketSize:
            {
                if (!m_CurrentPacket.IsEmpty() || m_PendingPackets.Count > 0)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Cannot set MaxPacketSize after sending data.");
                    }
                    return(false);
                }

                if (value <= 0)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Cannot set MaxPacketSize less than one.");
                    }
                    return(false);
                }

                if (value > m_MaxPacketSize)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Cannot set MaxPacketSize to greater than the existing maximum (" + m_MaxPacketSize + ").");
                    }
                    return(false);
                }
                // rebuild the packet with the new size. the packets doesn't store a size variable, just has the size of the internal buffer
                m_CurrentPacket = new ChannelPacket(value, m_IsReliable);
                m_MaxPacketSize = value;
                return(true);
            }
            }
            return(false);
        }