Beispiel #1
0
 private static void FreePacket(QChannelPacket packet)
 {
     if (_freePackets.Count < 512)
     {
         _freePackets.Add(packet);
     }
 }
Beispiel #2
0
        public bool SetOption(ChannelOption option, int value)
        {
            bool result;

            if (option != ChannelOption.MaxPendingBuffers)
            {
                if (option != ChannelOption.AllowFragmentation)
                {
                    if (option != ChannelOption.MaxPacketSize)
                    {
                        result = false;
                    }
                    else if (!_currentPacket.IsEmpty() || _pendingPackets.Count > 0)
                    {
                        Debug.LogError("Cannot set MaxPacketSize after sending data.");
                        result = false;
                    }
                    else if (value <= 0)
                    {
                        Debug.LogError("Cannot set MaxPacketSize less than one.");
                        result = false;
                    }
                    else if (value > _maxPacketSize)
                    {
                        Debug.LogError(
                            $"Cannot set MaxPacketSize to greater than the existing maximum ({_maxPacketSize}).");
                        result = false;
                    }
                    else
                    {
                        _currentPacket = new QChannelPacket(value, _isReliable);
                        _maxPacketSize = value;
                        result         = true;
                    }
                }
                else
                {
                    _allowFragmentation = value != 0;
                    result = true;
                }
            }
            else if (!_isReliable)
            {
                result = false;
            }
            else if (value < 0 || value >= 512)
            {
                Debug.LogError(
                    $"Invalid MaxPendingBuffers for channel {_channelId}. Must be greater than zero and less than {512}");
                result = false;
            }
            else
            {
                _maxPendingPacketCount = value;
                result = true;
            }
            return(result);
        }
Beispiel #3
0
        private QChannelPacket AllocPacket()
        {
            QChannelPacket result;

            if (_freePackets.Count == 0)
            {
                result = new QChannelPacket(_maxPacketSize, _isReliable);
            }
            else
            {
                var channelPacket = _freePackets[_freePackets.Count - 1];
                _freePackets.RemoveAt(_freePackets.Count - 1);
                channelPacket.Reset();
                result = channelPacket;
            }
            return(result);
        }
Beispiel #4
0
 public QChannelBuffer(QNetworkConnection conn, int bufferSize, byte cid, bool isReliable, bool isSequenced)
 {
     _connection            = conn;
     _maxPacketSize         = bufferSize - 100;
     _currentPacket         = new QChannelPacket(_maxPacketSize, isReliable);
     _channelId             = cid;
     _maxPendingPacketCount = 16;
     _isReliable            = isReliable;
     _allowFragmentation    = isReliable && isSequenced;
     if (isReliable)
     {
         _pendingPackets = new Queue <QChannelPacket>();
         if (_freePackets == null)
         {
             _freePackets = new List <QChannelPacket>();
         }
     }
 }
Beispiel #5
0
 private void QueuePacket()
 {
     _pendingPacketCount++;
     _pendingPackets.Enqueue(_currentPacket);
     _currentPacket = AllocPacket();
 }