Ejemplo n.º 1
0
 public void ProcessReceive(RUdpBuffer buffer)
 {
     receiveQueue.Enqueue(buffer);
     if (!isReceive)
     {
         isReceive = true;
         Task.Factory.StartNew(() => { ProcessReceiveQueue(); });//启用独立线程处理接收到的数据
     }
 }
Ejemplo n.º 2
0
        public bool Receive(SocketAsyncEventArgs e)
        {
            var receiveBuffer = e.Buffer;
            int offset        = e.Offset;
            int count         = e.BytesTransferred;

            if (count == uIntByteLength)
            {
                if (BitConverter.ToUInt32(receiveBuffer, offset) == SendId)
                {
                    isSendSucess = true;
                }
                return(true);
            }
            else if (count > dbUIntByteLength)
            {
                uint length = BitConverter.ToUInt32(receiveBuffer, offset);
                offset += uIntByteLength;
                count  -= uIntByteLength;
                if (length == count)
                {
                    uint packageId = BitConverter.ToUInt32(receiveBuffer, offset);
                    offset += uIntByteLength;
                    count  -= uIntByteLength;
                    lock (receiveLock)
                    {
                        if (packageId > prePackageId || prePackageId - packageId > 983040000)
                        {
                            Session.CommonSendAsync(BitConverter.GetBytes(packageId));//发送接收成功通知
                            RUdpBuffer receiveBufferObj = new RUdpBuffer();
                            receiveBufferObj.FixedBuffer = e.UserToken as IFixedBuffer;
                            receiveBufferObj.Offset      = offset;
                            receiveBufferObj.Count       = count;
                            ProcessReceive(receiveBufferObj);
                            var buffer = Session.Pool.RUdpServer.BufferPool.Pop();
                            e.SetBuffer(buffer.Buffer, 0, buffer.Buffer.Length);
                            e.UserToken  = buffer;
                            prePackageId = packageId;
                        }
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }