Exemplo n.º 1
0
        public int ProcessDeserializeQueue(bool isMultiThread = false)
        {
            int count = 0;

            while (_deserializeQueue.Count > 0 && count < MaxLoopCount)
            {
                if (isMultiThread)
                {
                    count++;
                }
                IPacket p = (IPacket)_deserializeQueue.Dequeue();
                try
                {
                    if (IsConnected)
                    {
                        if (p is VNetPacket)
                        {
                            _receiveMemoryStream.Capacity = Math.Max(_receiveMemoryStream.Capacity, p.Length);
                            _receiveMemoryStream.SetLength(p.Length);
                            _receiveMemoryStream.Seek(0, SeekOrigin.Begin);
                            p.CopyTo(_receiveMemoryStream.GetBuffer(), 0, p.Length, 0);
                            DoReceived(_receiveMemoryStream);
                        }
                        else if (p is VNetPacketMemSteam)
                        {
                            var memoryStream = ((VNetPacketMemSteam)p).Stream;
                            if (memoryStream != null)
                            {
                                DoReceived(memoryStream);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _logger.ErrorFormat("error while do send {0} {1}", IdInfo(), e);
                }
                finally
                {
                    if (p != null)
                    {
                        p.ReleaseReference();
                    }
                }
            }

            return(count);
        }