Write() public method

public Write ( byte bytes, int numBytes ) : void
bytes byte
numBytes int
return void
        internal bool SendBytes(byte[] bytes, int bytesToSend)
        {
            #if UNITY_EDITOR
            UnityEditor.NetworkDetailStats.IncrementStat(
                UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
                MsgType.HLAPIMsg, "msg", 1);
            #endif
            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;
            }

            // for fragmented channels, m_MaxPacketSize is set to the max size of a fragmented packet, so anything higher than this should fail for any kind of channel.
            if (bytesToSend > m_MaxPacketSize)
            {
                if (LogFilter.logError) { Debug.LogError("Failed to send big message of " + bytesToSend + " bytes. The maximum is " + m_MaxPacketSize + " bytes on this channel."); }
                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;
        }
Beispiel #2
0
 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);
 }
Beispiel #3
0
        internal bool SendBytes(byte[] bytes, int bytesToSend)
        {
            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);
        }