Ejemplo n.º 1
0
 public override IAsyncResult BeginWrite(
     byte[] array,
     int offset,
     int count,
     AsyncCallback asyncCallback,
     object asyncState)
 {
     this.EnsureCompressionMode();
     if ((uint)this.asyncOperations > 0U)
     {
         throw new InvalidOperationException(SR.GetString("Invalid begin call"));
     }
     this.ValidateParameters(array, offset, count);
     this.EnsureNotDisposed();
     Interlocked.Increment(ref this.asyncOperations);
     try
     {
         DeflateStreamAsyncResult streamAsyncResult = new DeflateStreamAsyncResult((object)this, asyncState, asyncCallback, array, offset, count);
         streamAsyncResult.isWrite = true;
         this.m_AsyncWriterDelegate.BeginInvoke(array, offset, count, true, this.m_CallBack, (object)streamAsyncResult);
         streamAsyncResult.m_CompletedSynchronously &= streamAsyncResult.IsCompleted;
         return((IAsyncResult)streamAsyncResult);
     }
     catch
     {
         Interlocked.Decrement(ref this.asyncOperations);
         throw;
     }
 }
Ejemplo n.º 2
0
        private void ReadCallback(IAsyncResult baseStreamResult)
        {
            DeflateStreamAsyncResult asyncState = (DeflateStreamAsyncResult)baseStreamResult.AsyncState;

            asyncState.m_CompletedSynchronously &= baseStreamResult.CompletedSynchronously;
            try
            {
                this.EnsureNotDisposed();
                int length = this._stream.EndRead(baseStreamResult);
                if (length <= 0)
                {
                    asyncState.InvokeCallback((object)0);
                }
                else
                {
                    this.inflater.SetInput(this.buffer, 0, length);
                    int num = this.inflater.Inflate(asyncState.buffer, asyncState.offset, asyncState.count);
                    if (num == 0 && !this.inflater.Finished())
                    {
                        this._stream.BeginRead(this.buffer, 0, this.buffer.Length, this.m_CallBack, (object)asyncState);
                    }
                    else
                    {
                        asyncState.InvokeCallback((object)num);
                    }
                }
            }
            catch (Exception ex)
            {
                asyncState.InvokeCallback((object)ex);
            }
        }
Ejemplo n.º 3
0
        public override void EndWrite(IAsyncResult asyncResult)
        {
            this.EnsureCompressionMode();
            this.CheckEndXxxxLegalStateAndParams(asyncResult);
            DeflateStreamAsyncResult asyncResult1 = (DeflateStreamAsyncResult)asyncResult;

            this.AwaitAsyncResultCompletion(asyncResult1);
            Exception result = asyncResult1.Result as Exception;

            if (result != null)
            {
                throw result;
            }
        }
Ejemplo n.º 4
0
        public override int EndRead(IAsyncResult asyncResult)
        {
            this.EnsureDecompressionMode();
            this.CheckEndXxxxLegalStateAndParams(asyncResult);
            DeflateStreamAsyncResult asyncResult1 = (DeflateStreamAsyncResult)asyncResult;

            this.AwaitAsyncResultCompletion(asyncResult1);
            Exception result = asyncResult1.Result as Exception;

            if (result != null)
            {
                throw result;
            }
            return((int)asyncResult1.Result);
        }
Ejemplo n.º 5
0
 private void AwaitAsyncResultCompletion(DeflateStreamAsyncResult asyncResult)
 {
     try
     {
         if (asyncResult.IsCompleted)
         {
             return;
         }
         asyncResult.AsyncWaitHandle.WaitOne();
     }
     finally
     {
         Interlocked.Decrement(ref this.asyncOperations);
         asyncResult.Close();
     }
 }
Ejemplo n.º 6
0
        private void WriteCallback(IAsyncResult asyncResult)
        {
            DeflateStreamAsyncResult asyncState = (DeflateStreamAsyncResult)asyncResult.AsyncState;

            asyncState.m_CompletedSynchronously &= asyncResult.CompletedSynchronously;
            try
            {
                this.m_AsyncWriterDelegate.EndInvoke(asyncResult);
            }
            catch (Exception ex)
            {
                asyncState.InvokeCallback((object)ex);
                return;
            }
            asyncState.InvokeCallback((object)null);
        }
Ejemplo n.º 7
0
 public override IAsyncResult BeginRead(
     byte[] array,
     int offset,
     int count,
     AsyncCallback asyncCallback,
     object asyncState)
 {
     this.EnsureDecompressionMode();
     if ((uint)this.asyncOperations > 0U)
     {
         throw new InvalidOperationException(SR.GetString("Invalid begin call"));
     }
     this.ValidateParameters(array, offset, count);
     this.EnsureNotDisposed();
     Interlocked.Increment(ref this.asyncOperations);
     try
     {
         DeflateStreamAsyncResult streamAsyncResult = new DeflateStreamAsyncResult((object)this, asyncState, asyncCallback, array, offset, count);
         streamAsyncResult.isWrite = false;
         int num = this.inflater.Inflate(array, offset, count);
         if ((uint)num > 0U)
         {
             streamAsyncResult.InvokeCallback(true, (object)num);
             return((IAsyncResult)streamAsyncResult);
         }
         if (this.inflater.Finished())
         {
             streamAsyncResult.InvokeCallback(true, (object)0);
             return((IAsyncResult)streamAsyncResult);
         }
         this._stream.BeginRead(this.buffer, 0, this.buffer.Length, this.m_CallBack, (object)streamAsyncResult);
         streamAsyncResult.m_CompletedSynchronously &= streamAsyncResult.IsCompleted;
         return((IAsyncResult)streamAsyncResult);
     }
     catch
     {
         Interlocked.Decrement(ref this.asyncOperations);
         throw;
     }
 }