Exemplo n.º 1
0
        private unsafe void AsyncReadPagesCallback(uint errorCode, uint numBytes, object context)
        {
            try
            {
                var result = (PageAsyncReadResult <Empty>)context;

                if (errorCode != 0)
                {
                    Trace.TraceError("AsyncReadPagesCallback error: {0}", errorCode);
                    result.cts?.Cancel();
                }

                if (result.freeBuffer1 != null)
                {
                    if (errorCode == 0)
                    {
                        allocator.PopulatePage(result.freeBuffer1.GetValidPointer(), result.freeBuffer1.required_bytes, result.page);
                    }
                    result.freeBuffer1.Return();
                    result.freeBuffer1 = null;
                }

                if (errorCode == 0)
                {
                    result.handle?.Signal();
                }

                Interlocked.MemoryBarrier();
            }
            catch when(disposed)
            {
            }
        }
        private unsafe void AsyncReadPagesCallback(uint errorCode, uint numBytes, NativeOverlapped *overlap)
        {
            var result = (PageAsyncReadResult <Empty>)Overlapped.Unpack(overlap).AsyncResult;

            if (errorCode != 0)
            {
                Trace.TraceError("OverlappedStream GetQueuedCompletionStatus error: {0}", errorCode);
                result.cts?.Cancel();
            }

            if (result.freeBuffer1 != null)
            {
                if (errorCode == 0)
                {
                    allocator.PopulatePage(result.freeBuffer1.GetValidPointer(), result.freeBuffer1.required_bytes, result.page);
                }
                result.freeBuffer1.Return();
                result.freeBuffer1 = null;
            }

            if (errorCode == 0)
            {
                result.handle?.Signal();
            }

            Interlocked.MemoryBarrier();
            Overlapped.Free(overlap);
        }