Пример #1
0
        private void ReceiveEntity(byte[] buffer, int offset, int count)
        {
            // Set len
            mSurplusLen -= count;

            ReceivePacket packet = mReceivePacket;

            if (packet != null)
            {
                packet.Write(buffer, offset, count);


                // Notity progress
                float len      = packet.GetLength();
                float progress = (len - mSurplusLen) / len;

                // Post Callback
                ReceiveDelivery delivery = mReceiveDelivery;

                if (IsNotifyProgress(progress))
                {
                    // Notify
                    if (delivery != null)
                    {
                        delivery.PostReceiveProgress(packet, mProgress);
                    }
                }

                if (mSurplusLen <= 0)
                {
                    // End
                    packet.EndPacket();

                    // Notify
                    if (delivery != null)
                    {
                        delivery.PostReceiveEnd(packet, mStatus);
                    }

                    // Set Null
                    mReceivePacket = null;
                }
            }

            // Receive next entity
            ReceiveAsync(mSurplusLen);
        }