Exemple #1
0
 internal static void ValidateBufferBounds(byte[] buffer, int offset, int size)
 {
     if (buffer == null)
     {
         throw Fx.Exception.ArgumentNull("buffer");
     }
     ConnectionUtilities.ValidateBufferBounds((int)buffer.Length, offset, size);
 }
        public override int Read(byte[] buffer, int offset, int size, TimeSpan timeout)
        {
            ConnectionUtilities.ValidateBufferBounds(buffer, offset, size);
            if (this.preReadCount <= 0)
            {
                return(base.Read(buffer, offset, size, timeout));
            }
            int num = Math.Min(size, this.preReadCount);

            Buffer.BlockCopy(this.preReadData, this.preReadOffset, buffer, offset, num);
            PreReadConnection preReadConnection = this;

            preReadConnection.preReadOffset = preReadConnection.preReadOffset + num;
            PreReadConnection preReadConnection1 = this;

            preReadConnection1.preReadCount = preReadConnection1.preReadCount - num;
            return(num);
        }
        public override AsyncReadResult BeginRead(int offset, int size, TimeSpan timeout, WaitCallback callback, object state)
        {
            ConnectionUtilities.ValidateBufferBounds(this.AsyncReadBufferSize, offset, size);
            if (this.preReadCount <= 0)
            {
                return(base.BeginRead(offset, size, timeout, callback, state));
            }
            int num = Math.Min(size, this.preReadCount);

            Buffer.BlockCopy(this.preReadData, this.preReadOffset, this.AsyncReadBuffer, offset, num);
            PreReadConnection preReadConnection = this;

            preReadConnection.preReadOffset = preReadConnection.preReadOffset + num;
            PreReadConnection preReadConnection1 = this;

            preReadConnection1.preReadCount = preReadConnection1.preReadCount - num;
            this.asyncBytesRead             = num;
            return(AsyncReadResult.Completed);
        }