Exemplo n.º 1
0
        public void Dispose()
        {
            if (null != _kcp)
            {
                _kcp.Release();
            }
            _kcp = null;

            int messageCount = revQueue.Count;

            for (int i = 0; i < messageCount; i++)
            {
                RawMessage message = null;
                if (revQueue.TryDequeue(out message))
                {
                    RawMessage.Clear(message);
                }
            }
            revQueue.Clear();
        }
Exemplo n.º 2
0
        private void ProcessReceive(UInt32 current)
        {
            while (revQueue.Count > 0)
            {
                _lastRecvTime = current;

                RawMessage data = null;
                if (!revQueue.TryDequeue(out data))
                {
                    continue;
                }

                int r = _kcp.Input(data.buffer, 0, data.size);
                RawMessage.Clear(data);

                if (r < 0)
                {
                    continue;
                }

                _needUpdate = true;
                while (true)
                {
                    var size = _kcp.PeekSize();
                    if (size > 0)
                    {
                        r = _kcp.Recv(kcpRcvBuf, 0, kcpRcvBuf.Length);
                        if (r <= 0)
                        {
                            break;
                        }
                        receiveHandle.SafeInvoke(kcpRcvBuf, 0, size, remote);
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }