protected override void OnReceiveCore( ReceivingContext context, ResponseMessage response, RpcErrorMessage error )
 {
     base.OnReceiveCore( context, response, error );
     this._connectionPool.Return( context.SocketContext );
     context.SessionContext.Dispose();
     // FIXME: Return to buffer pool.
 }
 protected virtual ChunkBuffer ReallocateReceivingBufferCore( ChunkBuffer oldBuffer, long requestedLength, ReceivingContext context )
 {
     return ChunkBuffer.CreateDefault( context.SessionContext.Options.BufferSegmentCount ?? 1, context.SessionContext.Options.BufferSegmentSize ?? ChunkBuffer.DefaultSegmentSize );
 }
        protected virtual void OnReceiveCore( ReceivingContext context, ResponseMessage response, RpcErrorMessage error )
        {
            IResponseHandler handler;
            bool removed;
            try { }
            finally
            {
                removed = this._sessionTable.TryRemove( response.MessageId, out handler );
                this._sessionTableLatch.Signal();
            }

            if ( removed )
            {
                if ( error.IsSuccess )
                {
                    handler.HandleResponse( response, false );
                }
                else
                {
                    handler.HandleError( error, false );
                }
            }
            else
            {
                // TODO: trace unrecognized receive message.
            }
        }
 ChunkBuffer ITransportReceiveHandler.ReallocateReceivingBuffer( ChunkBuffer oldBuffer, long requestedLength, ReceivingContext context )
 {
     return this.ReallocateReceivingBufferCore( oldBuffer, requestedLength, context );
 }
 void ITransportReceiveHandler.OnReceive( ReceivingContext context )
 {
     ResponseMessage result;
     // FIXME: Feeding deserliaztion.
     //	If data is not enough, Deserialize return null.
     //  So this method return false, caller(EventLoop) retrieve more data.
     //  Feeding callback is NOT straight forward.
     var error = this._responseSerializer.Deserialize( context.ReceivingBuffer, out result );
     this.OnReceiveCore( context, result, error );
 }
 protected override sealed void ReceiveFromCore( ReceivingContext context )
 {
     if ( !context.SocketContext.ReceiveFromAsync() )
     {
         context.SocketContext.OnReceived( true );
     }
 }
 protected override sealed void OnReceived( ReceivingContext context, bool completedSynchronously )
 {
     if ( context.SessionContext.IsInContinuousRetrieval )
     {
         // Eventually continue blocked unpacking process.
         context.SessionContext.RetrievalWaitHandle.Set();
         return;
     }
     else
     {
         // Eventually invoke callback from ITransportReceiveHandler
         base.OnReceived( context, completedSynchronously );
     }
 }
 public ChunkBuffer ReallocateReceivingBuffer( ChunkBuffer oldBuffer, long requestedLength, ReceivingContext context )
 {
     return ChunkBuffer.CreateDefault();
 }
            public void OnReceive( ReceivingContext context )
            {
                context.SocketContext.UserToken = context;

                var handler = this.Received;
                if ( handler != null )
                {
                    handler( context );
                }
            }