SendToTransport() public method

public SendToTransport ( NetworkConnection conn, int channelId ) : bool
conn NetworkConnection
channelId int
return bool
コード例 #1
0
        public bool SendInternalBuffer()
        {
            #if UNITY_EDITOR
            UnityEditor.NetworkDetailStats.IncrementStat(
                UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
                MsgType.LLAPIMsg, "msg", 1);
            #endif
            if (m_IsReliable && m_PendingPackets.Count > 0)
            {
                // send until transport can take no more
                while (m_PendingPackets.Count > 0)
                {
                    var packet = m_PendingPackets.Dequeue();
                    if (!packet.SendToTransport(m_Connection, m_ChannelId))
                    {
                        m_PendingPackets.Enqueue(packet);
                        break;
                    }
                    pendingPacketCount -= 1;
                    FreePacket(packet);

                    if (m_IsBroken && m_PendingPackets.Count < (m_MaxPendingPacketCount / 2))
                    {
                        if (LogFilter.logWarn) { Debug.LogWarning("ChannelBuffer recovered from overflow but data was lost."); }
                        m_IsBroken = false;
                    }
                }
                return true;
            }
            return m_CurrentPacket.SendToTransport(m_Connection, m_ChannelId);
        }
コード例 #2
0
ファイル: ChannelBuffer.cs プロジェクト: Hengle/JellyTerain
 public bool SendInternalBuffer()
 {
     if (m_IsReliable && m_PendingPackets.Count > 0)
     {
         while (m_PendingPackets.Count > 0)
         {
             ChannelPacket channelPacket = m_PendingPackets.Dequeue();
             if (!channelPacket.SendToTransport(m_Connection, m_ChannelId))
             {
                 m_PendingPackets.Enqueue(channelPacket);
                 break;
             }
             pendingPacketCount--;
             FreePacket(channelPacket);
             if (m_IsBroken && m_PendingPackets.Count < m_MaxPendingPacketCount / 2)
             {
                 if (LogFilter.logWarn)
                 {
                     Debug.LogWarning("ChannelBuffer recovered from overflow but data was lost.");
                 }
                 m_IsBroken = false;
             }
         }
         return(true);
     }
     return(m_CurrentPacket.SendToTransport(m_Connection, m_ChannelId));
 }
コード例 #3
0
 public bool SendInternalBuffer()
 {
     NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, (short)29, "msg", 1);
     if (!this.m_IsReliable || this.m_PendingPackets.Count <= 0)
     {
         return(this.m_CurrentPacket.SendToTransport(this.m_Connection, (int)this.m_ChannelId));
     }
     while (this.m_PendingPackets.Count > 0)
     {
         ChannelPacket packet = this.m_PendingPackets.Dequeue();
         if (!packet.SendToTransport(this.m_Connection, (int)this.m_ChannelId))
         {
             this.m_PendingPackets.Enqueue(packet);
             break;
         }
         --ChannelBuffer.pendingPacketCount;
         ChannelBuffer.FreePacket(packet);
         if (this.m_IsBroken && this.m_PendingPackets.Count < this.m_MaxPendingPacketCount / 2)
         {
             if (LogFilter.logWarn)
             {
                 Debug.LogWarning((object)"ChannelBuffer recovered from overflow but data was lost.");
             }
             this.m_IsBroken = false;
         }
     }
     return(true);
 }
コード例 #4
0
 public bool SendInternalBuffer()
 {
     NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, 0x1d, "msg", 1);
     if (!this.m_IsReliable || (this.m_PendingPackets.Count <= 0))
     {
         return(this.m_CurrentPacket.SendToTransport(this.m_Connection, this.m_ChannelId));
     }
     while (this.m_PendingPackets.Count > 0)
     {
         ChannelPacket packet = this.m_PendingPackets[0];
         if (!packet.SendToTransport(this.m_Connection, this.m_ChannelId))
         {
             break;
         }
         pendingPacketCount--;
         this.m_PendingPackets.RemoveAt(0);
         FreePacket(packet);
         if (this.m_IsBroken && (this.m_PendingPackets.Count < (this.m_MaxPendingPacketCount / 2)))
         {
             if (LogFilter.logWarn)
             {
                 Debug.LogWarning("ChannelBuffer recovered from overflow but data was lost.");
             }
             this.m_IsBroken = false;
         }
     }
     return(true);
 }
コード例 #5
0
        public bool SendInternalBuffer()
        {
            bool result;

            if (this.m_IsReliable && this.m_PendingPackets.Count > 0)
            {
                while (this.m_PendingPackets.Count > 0)
                {
                    ChannelPacket channelPacket = this.m_PendingPackets.Dequeue();
                    if (!channelPacket.SendToTransport(this.m_Connection, (int)this.m_ChannelId))
                    {
                        this.m_PendingPackets.Enqueue(channelPacket);
                        break;
                    }
                    ChannelBuffer.pendingPacketCount--;
                    ChannelBuffer.FreePacket(channelPacket);
                    if (this.m_IsBroken && this.m_PendingPackets.Count < this.m_MaxPendingPacketCount / 2)
                    {
                        if (LogFilter.logWarn)
                        {
                            Debug.LogWarning("ChannelBuffer recovered from overflow but data was lost.");
                        }
                        this.m_IsBroken = false;
                    }
                }
                result = true;
            }
            else
            {
                result = this.m_CurrentPacket.SendToTransport(this.m_Connection, (int)this.m_ChannelId);
            }
            return(result);
        }
コード例 #6
0
 public bool SendInternalBuffer()
 {
     if (this.m_IsReliable && this.m_PendingPackets.Count > 0)
     {
         while (this.m_PendingPackets.Count > 0)
         {
             ChannelPacket packet = this.m_PendingPackets[0];
             if (!packet.SendToTransport(this.m_Connection, (int)this.m_ChannelId))
             {
                 break;
             }
             ChannelBuffer.pendingPacketCount--;
             this.m_PendingPackets.RemoveAt(0);
             ChannelBuffer.FreePacket(packet);
             if (this.m_IsBroken && this.m_PendingPackets.Count < this.m_MaxPendingPacketCount / 2)
             {
                 if (LogFilter.logWarn)
                 {
                     Debug.LogWarning("ChannelBuffer recovered from overflow but data was lost.");
                 }
                 this.m_IsBroken = false;
             }
         }
         return(true);
     }
     return(this.m_CurrentPacket.SendToTransport(this.m_Connection, (int)this.m_ChannelId));
 }
コード例 #7
0
ファイル: ChannelBuffer.cs プロジェクト: Hengle/JellyTerain
 internal bool SendBytes(byte[] bytes, int bytesToSend)
 {
     if (bytesToSend >= 65535)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("ChannelBuffer:SendBytes cannot send packet larger than " + ushort.MaxValue + " bytes");
         }
         return(false);
     }
     if (bytesToSend <= 0)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("ChannelBuffer:SendBytes cannot send zero bytes");
         }
         return(false);
     }
     if (bytesToSend > m_MaxPacketSize)
     {
         if (m_AllowFragmentation)
         {
             return(SendFragmentBytes(bytes, bytesToSend));
         }
         if (LogFilter.logError)
         {
             Debug.LogError("Failed to send big message of " + bytesToSend + " bytes. The maximum is " + m_MaxPacketSize + " bytes on channel:" + m_ChannelId);
         }
         return(false);
     }
     if (!m_CurrentPacket.HasSpace(bytesToSend))
     {
         if (m_IsReliable)
         {
             if (m_PendingPackets.Count == 0)
             {
                 if (!m_CurrentPacket.SendToTransport(m_Connection, m_ChannelId))
                 {
                     QueuePacket();
                 }
                 m_CurrentPacket.Write(bytes, bytesToSend);
                 return(true);
             }
             if (m_PendingPackets.Count >= m_MaxPendingPacketCount)
             {
                 if (!m_IsBroken && LogFilter.logError)
                 {
                     Debug.LogError("ChannelBuffer buffer limit of " + m_PendingPackets.Count + " packets reached.");
                 }
                 m_IsBroken = true;
                 return(false);
             }
             QueuePacket();
             m_CurrentPacket.Write(bytes, bytesToSend);
             return(true);
         }
         if (!m_CurrentPacket.SendToTransport(m_Connection, m_ChannelId))
         {
             if (LogFilter.logError)
             {
                 Debug.Log("ChannelBuffer SendBytes no space on unreliable channel " + m_ChannelId);
             }
             return(false);
         }
         m_CurrentPacket.Write(bytes, bytesToSend);
         return(true);
     }
     m_CurrentPacket.Write(bytes, bytesToSend);
     if (maxDelay == 0f)
     {
         return(SendInternalBuffer());
     }
     return(true);
 }
コード例 #8
0
        internal bool SendBytes(byte[] bytes, int bytesToSend)
        {
#if UNITY_EDITOR
            UnityEditor.NetworkDetailStats.IncrementStat(
                UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
                MsgType.HLAPIMsg, "msg", 1);
#endif
            if (bytesToSend >= UInt16.MaxValue)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("ChannelBuffer:SendBytes cannot send packet larger than " + UInt16.MaxValue + " bytes");
                }
                return(false);
            }

            if (bytesToSend <= 0)
            {
                // zero length packets getting into the packet queues are bad.
                if (LogFilter.logError)
                {
                    Debug.LogError("ChannelBuffer:SendBytes cannot send zero bytes");
                }
                return(false);
            }

            if (bytesToSend > m_MaxPacketSize)
            {
                if (m_AllowFragmentation)
                {
                    return(SendFragmentBytes(bytes, bytesToSend));
                }
                else
                {
                    // cannot do HLAPI fragmentation on this channel
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Failed to send big message of " + bytesToSend + " bytes. The maximum is " + m_MaxPacketSize + " bytes on channel:" + m_ChannelId);
                    }
                    return(false);
                }
            }

            if (!m_CurrentPacket.HasSpace(bytesToSend))
            {
                if (m_IsReliable)
                {
                    if (m_PendingPackets.Count == 0)
                    {
                        // nothing in the pending queue yet, just flush and write
                        if (!m_CurrentPacket.SendToTransport(m_Connection, m_ChannelId))
                        {
                            QueuePacket();
                        }
                        m_CurrentPacket.Write(bytes, bytesToSend);
                        return(true);
                    }

                    if (m_PendingPackets.Count >= m_MaxPendingPacketCount)
                    {
                        if (!m_IsBroken)
                        {
                            // only log this once, or it will spam the log constantly
                            if (LogFilter.logError)
                            {
                                Debug.LogError("ChannelBuffer buffer limit of " + m_PendingPackets.Count + " packets reached.");
                            }
                        }
                        m_IsBroken = true;
                        return(false);
                    }

                    // calling SendToTransport here would write out-of-order data to the stream. just queue
                    QueuePacket();
                    m_CurrentPacket.Write(bytes, bytesToSend);
                    return(true);
                }

                if (!m_CurrentPacket.SendToTransport(m_Connection, m_ChannelId))
                {
                    if (LogFilter.logError)
                    {
                        Debug.Log("ChannelBuffer SendBytes no space on unreliable channel " + m_ChannelId);
                    }
                    return(false);
                }

                m_CurrentPacket.Write(bytes, bytesToSend);
                return(true);
            }

            m_CurrentPacket.Write(bytes, bytesToSend);
            if (maxDelay == 0.0f)
            {
                return(SendInternalBuffer());
            }
            return(true);
        }