public void TestClearBuffers()
        {
            var target = new ClientResponseContext();

            MakeBufferDirty(target);

            var length = target.UnpackingBuffer.Length;

            target.UnpackingBuffer.Position++;
            target.ClearBuffers();

            Assert.That(target.BoundTransport, Is.Not.Null);
            Assert.That(target.CurrentReceivingBuffer, Is.Not.Null);
            Assert.That(target.CurrentReceivingBufferOffset, Is.Not.EqualTo(0));
            Assert.That(target.ErrorBuffer, Is.Null);
            Assert.That(target.ErrorStartAt, Is.EqualTo(-1));
            Assert.That(target.HeaderUnpacker, Is.Null);
            Assert.That(target.MessageId, Is.Not.Null);
            Assert.That(target.NextProcess, Is.Not.Null);
            Assert.That(target.ReceivedData, Is.Not.Null);
            Assert.That(target.ResultBuffer, Is.Null);
            Assert.That(target.ResultStartAt, Is.EqualTo(-1));
            Assert.That(target.RootUnpacker, Is.Null);
            Assert.That(target.SessionId, Is.Not.EqualTo(0));
            Assert.That(target.SessionStartedAt, Is.Not.EqualTo(default(DateTimeOffset)));
            Assert.That(target.UnpackingBuffer, Is.Not.Null);
            Assert.That(target.UnpackingBuffer.Length, Is.LessThan(length));
        }
Пример #2
0
        /// <summary>
        ///		Dispatch response message.
        /// </summary>
        /// <param name="context">Context information.</param>
        /// <returns>
        ///		<c>true</c>, if the pipeline is finished;
        ///		<c>false</c>, the pipeline is interruppted because extra data is needed.
        /// </returns>
        private bool Dispatch(ClientResponseContext context)
        {
            Contract.Assert(context.MessageId != null);

            try
            {
                Action <ClientResponseContext, Exception, bool> handler = null;
                try
                {
                    this._pendingRequestTable.TryRemove(context.MessageId.Value, out handler);
                }
                finally
                {
                    // Best effort to rescue from ThreadAbortException...
                    if (handler != null)
                    {
                        handler(context, null, context.CompletedSynchronously);
                    }
                    else
                    {
                        this.HandleOrphan(context);
                    }
                }
            }
            finally
            {
                context.ClearBuffers();
                this.OnProcessFinished();
            }

            if (context.UnpackingBuffer.Length > 0)
            {
                // Subsequent request is already arrived.
                context.NextProcess = this.UnpackResponseHeader;
                return(context.NextProcess(context));
            }
            else
            {
                // Try receive subsequent.
                return(true);
            }
        }
		/// <summary>
		///		Dispatch response message.
		/// </summary>
		/// <param name="context">Context information.</param>
		/// <returns>
		///		<c>true</c>, if the pipeline is finished;
		///		<c>false</c>, the pipeline is interruppted because extra data is needed.
		/// </returns>
		private bool Dispatch( ClientResponseContext context )
		{
			Contract.Assert( context.MessageId != null );

			try
			{
				Action<ClientResponseContext, Exception, bool> handler = null;
				try
				{
					this._pendingRequestTable.TryRemove( context.MessageId.Value, out handler );
				}
				finally
				{
					// Best effort to rescue from ThreadAbortException...
					if ( handler != null )
					{
						handler( context, null, context.CompletedSynchronously );
					}
					else
					{
						this.HandleOrphan( context );
					}
				}
			}
			finally
			{
				context.ClearBuffers();
				this.OnProcessFinished();
			}

			if ( context.UnpackingBuffer.Length > 0 )
			{
				// Subsequent request is already arrived.
				context.NextProcess = this.UnpackResponseHeader;
				return context.NextProcess( context );
			}
			else
			{
				// Try receive subsequent.
				return true;
			}
		}