Пример #1
0
        /// <summary>
        /// Called when a read or write operation is received.
        /// </summary>
        /// <param name="operation"></param>
        private void OperationQueue_ProcessOperation(ReadWriteOperation operation)
        {
            if (operation.IsRead)
            {
                DoRead(operation);
                if (!operation.Abandon)
                {
                    IncrementBytesRead(operation.BytesRead);
                    if (operation.ReadDelegate != null)
                    {
                        operation.ReadDelegate(this, operation.Buffer, operation.Offset, operation.Length, operation.BytesRead);
                    }
                }
            }
            else
            {
                IncrementWriteQueueBytes(-operation.Length);
                if (DateTime.UtcNow >= operation.StaleThreshold)
                {
                    IncrementStaleBytesDiscarded(operation.Length);
                }
                else
                {
                    DoWrite(operation);
                    if (!operation.Abandon)
                    {
                        IncrementBytesWritten(operation.Length);
                    }
                }
            }

            if (operation.Abandon)
            {
                // The Abandon call will shut down this thread - do not put any code after this point,
                // it will never run.
                Abandon();
            }
        }