コード例 #1
0
        static void OnFlushComplete(IAsyncEventArgs state)
        {
            BufferedOutputAsyncStream thisPtr    = (BufferedOutputAsyncStream)state.AsyncState;
            WriteFlushAsyncEventArgs  flushState = (WriteFlushAsyncEventArgs)state;
            ByteBuffer byteBuffer = flushState.Result;

            thisPtr.buffers.Enqueue(byteBuffer);
        }
コード例 #2
0
 internal ByteBuffer(BufferedOutputAsyncStream parent, int bufferSize, Stream stream)
 {
     this.waiting      = false;
     this.writePending = false;
     this.position     = 0;
     this.bytes        = DiagnosticUtility.Utility.AllocateByteArray(bufferSize);
     this.stream       = stream;
     this.parent       = parent;
 }
コード例 #3
0
        static void OnWriteCallback(IAsyncEventArgs state)
        {
            BufferedOutputAsyncStream thisPtr = (BufferedOutputAsyncStream)state.AsyncState;
            IAsyncResult  returnResult        = thisPtr.writeState.PendingAsyncResult;
            AsyncCallback callback            = thisPtr.writeState.Arguments.Callback;

            thisPtr.writeState.Arguments.Callback = null;
            if (callback != null)
            {
                callback(returnResult);
            }
        }
コード例 #4
0
        static void OnAsyncFlushComplete(IAsyncEventArgs state)
        {
            BufferedOutputAsyncStream thisPtr = (BufferedOutputAsyncStream)state.AsyncState;
            Exception completionException     = null;
            bool      completeSelf            = false;

            try
            {
                OnFlushComplete(state);

                if (thisPtr.buffers.TryAcquireLock())
                {
                    WriteFlushAsyncEventArgs flushState = (WriteFlushAsyncEventArgs)state;
                    if (flushState.Exception != null)
                    {
                        completeSelf        = true;
                        completionException = flushState.Exception;
                    }
                    else
                    {
                        if (thisPtr.WriteAsync(thisPtr.writeState) == AsyncCompletionResult.Completed)
                        {
                            completeSelf = true;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }

                if (completionException == null)
                {
                    completionException = exception;
                }

                completeSelf = true;
            }

            if (completeSelf)
            {
                thisPtr.writeState.Complete(false, completionException);
            }
        }