public unsafe ThreadPoolBoundHandleOverlapped(IOCompletionCallback callback, object state, object pinData, PreAllocatedOverlapped preAllocated)
        {
            _userCallback = callback;
            _userState = state;
            _preAllocated = preAllocated;

            _nativeOverlapped = Pack(CompletionCallback, pinData);
            _nativeOverlapped->OffsetLow = 0;        // CLR reuses NativeOverlapped instances and does not reset these
            _nativeOverlapped->OffsetHigh = 0;
        }
예제 #2
0
 internal OverlappedValueTaskSource(SafeFileHandle fileHandle)
 {
     _fileHandle = fileHandle;
     _source.RunContinuationsAsynchronously = true;
     _preallocatedOverlapped = PreAllocatedOverlapped.UnsafeCreate(s_ioCallback, this, null);
 }
예제 #3
0
    public unsafe void MultipleOperationsOverMultipleHandles()
    {
        const int DATA_SIZE = 2;

        SafeHandle            handle1      = HandleFactory.CreateAsyncFileHandleForWrite(@"MultipleOperationsOverMultipleHandle1.tmp");
        SafeHandle            handle2      = HandleFactory.CreateAsyncFileHandleForWrite(@"MultipleOperationsOverMultipleHandle2.tmp");
        ThreadPoolBoundHandle boundHandle1 = ThreadPoolBoundHandle.BindHandle(handle1);
        ThreadPoolBoundHandle boundHandle2 = ThreadPoolBoundHandle.BindHandle(handle2);

        OverlappedContext result1 = new OverlappedContext();
        OverlappedContext result2 = new OverlappedContext();

        byte[] data1 = new byte[DATA_SIZE];
        data1[0] = (byte)'A';
        data1[1] = (byte)'B';


        byte[] data2 = new byte[DATA_SIZE];
        data2[0] = (byte)'C';
        data2[1] = (byte)'D';

        PreAllocatedOverlapped preAlloc1 = new PreAllocatedOverlapped(OnOverlappedOperationCompleted, result1, data1);
        PreAllocatedOverlapped preAlloc2 = new PreAllocatedOverlapped(OnOverlappedOperationCompleted, result2, data2);

        for (int i = 0; i < 10; i++)
        {
            NativeOverlapped *overlapped1 = boundHandle1.AllocateNativeOverlapped(preAlloc1);
            NativeOverlapped *overlapped2 = boundHandle2.AllocateNativeOverlapped(preAlloc2);

            fixed(byte *p1 = data1, p2 = data2)
            {
                int retval = DllImport.WriteFile(boundHandle1.Handle, p1, DATA_SIZE, IntPtr.Zero, overlapped1);

                if (retval == 0)
                {
                    Assert.Equal(DllImport.ERROR_IO_PENDING, Marshal.GetLastWin32Error());
                }


                retval = DllImport.WriteFile(boundHandle2.Handle, p2, DATA_SIZE, IntPtr.Zero, overlapped2);

                if (retval == 0)
                {
                    Assert.Equal(DllImport.ERROR_IO_PENDING, Marshal.GetLastWin32Error());
                }

                // Wait for overlapped operations to complete
                WaitHandle.WaitAll(new WaitHandle[] { result1.Event, result2.Event });
            }

            boundHandle1.FreeNativeOverlapped(overlapped1);
            boundHandle2.FreeNativeOverlapped(overlapped2);

            result1.Event.Reset();
            result2.Event.Reset();

            Assert.Equal(0, result1.ErrorCode);
            Assert.Equal(0, result2.ErrorCode);
            Assert.Equal(DATA_SIZE, result1.BytesWritten);
            Assert.Equal(DATA_SIZE, result2.BytesWritten);
        }

        boundHandle1.Dispose();
        boundHandle2.Dispose();
        preAlloc1.Dispose();
        preAlloc2.Dispose();
        handle1.Dispose();
        handle2.Dispose();
    }
        public unsafe ThreadPoolBoundHandleOverlapped(IOCompletionCallback callback, object state, object pinData, PreAllocatedOverlapped preAllocated)
        {
            _userCallback = callback;
            _userState    = state;
            _preAllocated = preAllocated;

            _nativeOverlapped             = Pack(s_completionCallback, pinData);
            _nativeOverlapped->OffsetLow  = 0;       // CLR reuses NativeOverlapped instances and does not reset these
            _nativeOverlapped->OffsetHigh = 0;
        }
 public unsafe NativeOverlapped* AllocateNativeOverlapped(PreAllocatedOverlapped preAllocated);
예제 #6
0
 internal ValueTaskSource(AsyncWindowsFileStreamStrategy strategy)
 {
     _strategy = strategy;
     _source.RunContinuationsAsynchronously = true;
     _preallocatedOverlapped = PreAllocatedOverlapped.UnsafeCreate(s_ioCallback, this, null);
 }
 public unsafe void PreAllocatedOverlapped_EmptyArrayAsPinData_DoesNotThrow()
 {
     using (new PreAllocatedOverlapped((_, __, ___) => { }, new object(), new byte[0])) { }
     using (PreAllocatedOverlapped.UnsafeCreate((_, __, ___) => { }, new object(), new byte[0])) { }
 }
 public unsafe void PreAllocatedOverlapped_NullAsPinData_DoesNotThrow()
 {
     using (new PreAllocatedOverlapped((_, __, ___) => { }, new object(), (byte[])null)) { }
     using (PreAllocatedOverlapped.UnsafeCreate((_, __, ___) => { }, new object(), (byte[])null)) { }
 }
 public unsafe void PreAllocatedOverlapped_NullAsContext_DoesNotThrow()
 {
     using (new PreAllocatedOverlapped((_, __, ___) => { }, (object)null, new byte[256])) { }
     using (PreAllocatedOverlapped.UnsafeCreate((_, __, ___) => { }, (object)null, new byte[256])) { }
 }
 public unsafe void PreAllocatedOverlapped_ReturnedNativeOverlapped_OffsetLowAndOffsetHighSetToZero()
 {
     using (new PreAllocatedOverlapped((_, __, ___) => { }, new object(), new byte[256])) { }
     using (PreAllocatedOverlapped.UnsafeCreate((_, __, ___) => { }, new object(), new byte[256])) { }
 }
예제 #11
0
 protected PipeValueTaskSource(PipeStream pipeStream)
 {
     _pipeStream = pipeStream;
     _source.RunContinuationsAsynchronously = true;
     _preallocatedOverlapped = new PreAllocatedOverlapped(s_ioCallback, this, null);
 }