ByteStreamBufferedMessageData.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.ServiceModel.Channels / System / ServiceModel / Channels / ByteStreamBufferedMessageData.cs / 1305376 / ByteStreamBufferedMessageData.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------

namespace System.ServiceModel.Channels 
{
    using System; 
    using System.Runtime; 

    class ByteStreamBufferedMessageData 
    {
        byte[] buffer;
        BufferManager bufferManager;
        int count; 
        int refCount;
 
        public ByteStreamBufferedMessageData(byte[] buffer, int count) 
        {
            this.buffer = buffer; 
            this.count = count;
            this.refCount = 0;
        }
 
        public ByteStreamBufferedMessageData(BufferManager bufferManager, int count)
        { 
            Fx.Assert(bufferManager != null, "bufferManager should not be null using this constructor"); 
            this.buffer = bufferManager.TakeBuffer(count);
            this.bufferManager = bufferManager; 
            this.count = count;
            this.refCount = 0;
        }
 
        public byte[] Buffer
        { 
            get { return this.buffer; } 
        }
 
        public int Count
        {
            get { return this.count; }
        } 

        public void Open() 
        { 
            if (this.buffer != null)
            { 
                this.refCount++;
            }
        }
 
        public void Close()
        { 
            if (this.buffer != null) 
            {
                if (--this.refCount <= 0) 
                {
                    if (this.bufferManager != null)
                    {
                        this.bufferManager.ReturnBuffer(this.buffer); 
                    }
                    this.bufferManager = null; 
                    this.buffer = null; 
                }
            } 
        }
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK