public unsafe PreAllocatedOverlapped(IOCompletionCallback callback, object state, object pinData) { if (callback == null) throw new ArgumentNullException("callback"); _overlapped = new ThreadPoolBoundHandleOverlapped(callback, state, pinData, this); }
internal unsafe NativeOverlapped* Pack(IOCompletionCallback iocb, object userData) { if (!this.m_pinSelf.IsNull()) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_Overlapped_Pack")); } StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller; if (iocb != null) { this.m_iocbHelper = new _IOCompletionCallback(iocb, ref lookForMyCaller); this.m_iocb = iocb; } else { this.m_iocbHelper = null; this.m_iocb = null; } this.m_userObject = userData; if (this.m_userObject != null) { if (this.m_userObject.GetType() == typeof(object[])) { this.m_isArray = 1; } else { this.m_isArray = 0; } } return this.AllocateNativeOverlapped(); }
internal unsafe OverlappedCache(Overlapped overlapped, object pinnedObjects, IOCompletionCallback callback, bool alreadyTriedCast) { this.m_Overlapped = overlapped; this.m_PinnedObjects = pinnedObjects; this.m_PinnedObjectsArray = (alreadyTriedCast ? null : new object[0]); this.m_NativeOverlapped = new SafeNativeOverlapped((IntPtr)((void*)overlapped.UnsafePack(callback, pinnedObjects))); }
public unsafe PreAllocatedOverlapped(IOCompletionCallback callback, object state, object pinData) { if (callback == null) throw new ArgumentNullException(nameof(callback)); _overlapped = Win32ThreadPoolNativeOverlapped.Allocate(callback, state, pinData, this); }
public OverlappedContext() { if (OverlappedContext.completeCallback == null) { OverlappedContext.completeCallback = Fx.ThunkCallback(new IOCompletionCallback(CompleteCallback)); } if (OverlappedContext.eventCallback == null) { OverlappedContext.eventCallback = Fx.ThunkCallback(new WaitOrTimerCallback(EventCallback)); } if (OverlappedContext.cleanupCallback == null) { OverlappedContext.cleanupCallback = Fx.ThunkCallback(new WaitOrTimerCallback(CleanupCallback)); } this.bufferHolder = new object[] { OverlappedContext.dummyBuffer }; this.overlapped = new Overlapped(); this.nativeOverlapped = this.overlapped.UnsafePack(OverlappedContext.completeCallback, this.bufferHolder); // When replacing the buffer, we need to provoke the CLR to fix up the handle of the pin. this.pinnedHandle = GCHandle.FromIntPtr(*((IntPtr*)nativeOverlapped + (IntPtr.Size == 4 ? HandleOffsetFromOverlapped32 : HandleOffsetFromOverlapped64))); this.pinnedTarget = this.pinnedHandle.Target; // Create the permanently rooted holder and put it in the Overlapped. this.rootedHolder = new RootedHolder(); this.overlapped.AsyncResult = rootedHolder; }
internal unsafe OverlappedCache(Overlapped overlapped, object[] pinnedObjectsArray, IOCompletionCallback callback) { this.m_Overlapped = overlapped; this.m_PinnedObjects = pinnedObjectsArray; this.m_PinnedObjectsArray = pinnedObjectsArray; this.m_NativeOverlapped = new SafeNativeOverlapped((IntPtr)((void*)overlapped.UnsafePack(callback, pinnedObjectsArray))); }
internal OverlappedCache(System.Threading.Overlapped overlapped, object pinnedObjects, IOCompletionCallback callback, bool alreadyTriedCast) { this.m_Overlapped = overlapped; this.m_PinnedObjects = pinnedObjects; this.m_PinnedObjectsArray = alreadyTriedCast ? null : NclConstants.EmptyObjectArray; this.m_NativeOverlapped = new SafeNativeOverlapped(overlapped.UnsafePack(callback, pinnedObjects)); }
internal OverlappedCache(System.Threading.Overlapped overlapped, object[] pinnedObjectsArray, IOCompletionCallback callback) { this.m_Overlapped = overlapped; this.m_PinnedObjects = pinnedObjectsArray; this.m_PinnedObjectsArray = pinnedObjectsArray; this.m_NativeOverlapped = new SafeNativeOverlapped(overlapped.UnsafePack(callback, pinnedObjectsArray)); }
internal _IOCompletionCallback(IOCompletionCallback ioCompletionCallback, ref StackCrawlMark stackMark) { _ioCompletionCallback = ioCompletionCallback; // clone the exection context _executionContext = ExecutionContext.Capture(ref stackMark); ExecutionContext.ClearSyncContext(_executionContext); }
internal _IOCompletionCallback(IOCompletionCallback ioCompletionCallback, ref StackCrawlMark stackMark) { _ioCompletionCallback = ioCompletionCallback; // clone the exection context _executionContext = ExecutionContext.Capture( ref stackMark, ExecutionContext.CaptureOptions.IgnoreSyncCtx | ExecutionContext.CaptureOptions.OptimizeDefaultCase); }
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; }
internal unsafe static Win32ThreadPoolNativeOverlapped* Allocate(IOCompletionCallback callback, object state, object pinData, PreAllocatedOverlapped preAllocated) { Win32ThreadPoolNativeOverlapped* overlapped = AllocateNew(); try { overlapped->SetData(callback, state, pinData, preAllocated); } catch { Free(overlapped); throw; } return overlapped; }
internal void ReInitialize() { this.m_asyncResult = null; this.m_iocb = null; this.m_iocbHelper = null; this.m_overlapped = null; this.m_userObject = null; this.m_pinSelf = IntPtr.Zero; this.m_userObjectInternal = IntPtr.Zero; this.m_AppDomainId = 0; this.m_nativeOverlapped.EventHandle = IntPtr.Zero; this.m_isArray = 0; this.m_nativeOverlapped.InternalHigh = IntPtr.Zero; }
static unsafe PipeServiceListener() { pipeStreamType = typeof(System.IO.Pipes.PipeStream); FieldInfo ioCallbackField = pipeStreamType.GetField("IOCallback", BindingFlags.GetField | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.IgnoreReturn); pipeStreamAsyncPSCallback = (IOCompletionCallback)ioCallbackField.GetValue(null); ioCallbackField.SetValue(null, new IOCompletionCallback(pipeStreamAsyncPSCallbackWrapper)); // 修正 WaitForConnection 的回调函数中的异常 pipeServerStreamType = typeof(System.IO.Pipes.NamedPipeServerStream); ioCallbackField = pipeServerStreamType.GetField("WaitForConnectionCallback", BindingFlags.GetField | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.IgnoreReturn); pSSAsyncWaitForConnectionCallback = (IOCompletionCallback)ioCallbackField.GetValue(null); ioCallbackField.SetValue(null, new IOCompletionCallback(pSSAsyncWaitForConnectionCallbackWrapper)); }
internal void Reset() { Debug.Assert(_boundHandle == null); //not in use if (_pinnedData != null) { for (int i = 0; i < _pinnedData.Length; i++) { if (_pinnedData[i].IsAllocated && _pinnedData[i].Target != null) _pinnedData[i].Target = null; } } _callback = null; _state = null; _executionContext = null; _completed = false; _preAllocated = null; }
public unsafe NativeOverlapped* AllocateNativeOverlapped(IOCompletionCallback callback, object state, object pinData) { if (callback == null) throw new ArgumentNullException("callback"); AddRef(); try { Win32ThreadPoolNativeOverlapped* overlapped = Win32ThreadPoolNativeOverlapped.Allocate(callback, state, pinData, preAllocated: null); overlapped->Data._boundHandle = this; Interop.mincore.StartThreadpoolIo(_threadPoolHandle); return Win32ThreadPoolNativeOverlapped.ToNativeOverlapped(overlapped); } catch { Release(); throw; } }
public unsafe OverlappedContext() { if (completeCallback == null) { completeCallback = Fx.ThunkCallback(new IOCompletionCallback(OverlappedContext.CompleteCallback)); } if (eventCallback == null) { eventCallback = Fx.ThunkCallback(new WaitOrTimerCallback(OverlappedContext.EventCallback)); } if (cleanupCallback == null) { cleanupCallback = Fx.ThunkCallback(new WaitOrTimerCallback(OverlappedContext.CleanupCallback)); } this.bufferHolder = new object[] { dummyBuffer }; this.overlapped = new Overlapped(); this.nativeOverlapped = this.overlapped.UnsafePack(completeCallback, this.bufferHolder); this.pinnedHandle = GCHandle.FromIntPtr(*((IntPtr*) (this.nativeOverlapped + (((IntPtr.Size == 4) ? -4 : -3) * sizeof(IntPtr))))); this.pinnedTarget = this.pinnedHandle.Target; this.rootedHolder = new RootedHolder(); this.overlapped.AsyncResult = this.rootedHolder; }
internal _IOCompletionCallback(IOCompletionCallback ioCompletionCallback) { _ioCompletionCallback = ioCompletionCallback; // clone the exection context _executionContext = ExecutionContext.Capture(); }
/// <summary> /// <see cref="IDevice.WriteAsync(IntPtr, int, ulong, uint, IOCompletionCallback, IAsyncResult)"/> /// </summary> /// <param name="sourceAddress"></param> /// <param name="segmentId"></param> /// <param name="destinationAddress"></param> /// <param name="numBytesToWrite"></param> /// <param name="callback"></param> /// <param name="asyncResult"></param> public unsafe override void WriteAsync(IntPtr sourceAddress, int segmentId, ulong destinationAddress, uint numBytesToWrite, IOCompletionCallback callback, IAsyncResult asyncResult) { // Starts off in one, in order to prevent some issued writes calling the callback before all parallel writes are issued. var countdown = new CountdownEvent(1); long currentWriteStart = (long)destinationAddress; long writeEnd = currentWriteStart + (long)numBytesToWrite; uint aggregateErrorCode = 0; while (currentWriteStart < writeEnd) { long newStart = partitions.MapRange(currentWriteStart, writeEnd, out int shard, out long shardStartAddress, out long shardEndAddress); ulong writeOffset = (ulong)currentWriteStart - destinationAddress; // Indicate that there is one more task to wait for countdown.AddCount(); // Because more than one device can return with an error, it is important that we remember the most recent error code we saw. (It is okay to only // report one error out of many. It will be as if we failed on that error and cancelled all other reads, even though we issue reads in parallel and // wait until all of them are complete in the implementation) // Can there be races on async result as we issue writes or reads in parallel? partitions.Devices[shard].WriteAsync(IntPtr.Add(sourceAddress, (int)writeOffset), segmentId, (ulong)shardStartAddress, (uint)(shardEndAddress - shardStartAddress), (e, n, o) => { // TODO: Check if it is incorrect to ignore o if (e != 0) { aggregateErrorCode = e; } if (countdown.Signal()) { callback(aggregateErrorCode, n, o); countdown.Dispose(); } else { Overlapped.Free(o); } }, asyncResult); currentWriteStart = newStart; } // TODO: Check if overlapped wrapper is handled correctly if (countdown.Signal()) { Overlapped ov = new Overlapped(0, 0, IntPtr.Zero, asyncResult); NativeOverlapped *ovNative = ov.UnsafePack(callback, IntPtr.Zero); callback(aggregateErrorCode, numBytesToWrite, ovNative); countdown.Dispose(); } }
internal void ReInitialize() { m_asyncResult = null; m_iocb = null; m_iocbHelper = null; m_overlapped = null; m_userObject = null; Debug.Assert(m_pinSelf.IsNull(), "OverlappedData has not been freed: m_pinSelf"); m_pinSelf = (IntPtr)0; m_userObjectInternal = (IntPtr)0; Debug.Assert(m_AppDomainId == 0 || m_AppDomainId == AppDomain.CurrentDomain.Id, "OverlappedData is not in the current domain"); m_AppDomainId = 0; m_nativeOverlapped.EventHandle = (IntPtr)0; m_isArray = 0; m_nativeOverlapped.InternalLow = (IntPtr)0; m_nativeOverlapped.InternalHigh = (IntPtr)0; }
unsafe public NativeOverlapped* UnsafePack(IOCompletionCallback iocb) { return UnsafePack (iocb, null); }
internal static extern int ReadFileEx( IntPtr hFile, [MarshalAs(UnmanagedType.LPArray)] byte[] lpBuffer, int nNumberOfBytesToRead, [In] ref System.Threading.NativeOverlapped lpOverlapped, [MarshalAs(UnmanagedType.FunctionPtr)] IOCompletionCallback callback);
public NativeOverlapped Pack (IOCompletionCallback iocb) { return default(NativeOverlapped); }
public IOCompletionThunk(IOCompletionCallback callback) { _callback = callback; }
public static PreAllocatedOverlapped UnsafeCreate(IOCompletionCallback callback, object?state, object?pinData) => new PreAllocatedOverlapped(callback, state, pinData, flowExecutionContext : false);
/// <summary> /// /// </summary> /// <param name="alignedSourceAddress"></param> /// <param name="alignedDestinationAddress"></param> /// <param name="numBytesToWrite"></param> /// <param name="callback"></param> /// <param name="asyncResult"></param> public void WriteAsync(IntPtr alignedSourceAddress, ulong alignedDestinationAddress, uint numBytesToWrite, IOCompletionCallback callback, IAsyncResult asyncResult) { int segment = (int)(segmentSizeBits < 64 ? alignedDestinationAddress >> segmentSizeBits : 0); // If the device has bounded space, and we are writing a new segment, need to check whether an existing segment needs to be evicted. if (Capacity != Devices.CAPACITY_UNSPECIFIED && Utility.MonotonicUpdate(ref endSegment, segment, out int oldEnd)) { // Attempt to update the stored range until there are enough space on the tier to accomodate the current logTail int newStartSegment = endSegment - (int)(Capacity >> segmentSizeBits); // Assuming that we still have enough physical capacity to write another segment, even if delete does not immediately free up space. TruncateUntilSegmentAsync(newStartSegment, r => { }, null); } WriteAsync( alignedSourceAddress, segment, alignedDestinationAddress & segmentSizeMask, numBytesToWrite, callback, asyncResult); }
unsafe public NativeOverlapped *UnsafePack (IOCompletionCallback iocb) { // no need to propagate the call stack in the unsafe version return Pack (iocb); }
public unsafe NativeOverlapped *UnsafeAllocateNativeOverlapped(IOCompletionCallback callback, object?state, object?pinData) => AllocateNativeOverlapped(callback, state, pinData, flowExecutionContext: false);
private static unsafe void WriteToBlobAsync(CloudPageBlob blob, IntPtr sourceAddress, ulong destinationAddress, uint numBytesToWrite, IOCompletionCallback callback, IAsyncResult asyncResult) { // Even though Azure Page Blob does not make use of Overlapped, we populate one to conform to the callback API Overlapped ov = new Overlapped(0, 0, IntPtr.Zero, asyncResult); NativeOverlapped * ovNative = ov.UnsafePack(callback, IntPtr.Zero); UnmanagedMemoryStream stream = new UnmanagedMemoryStream((byte *)sourceAddress, numBytesToWrite); blob.BeginWritePages(stream, (long)destinationAddress, null, ar => { try { blob.EndWritePages(ar); } // I don't think I can be more specific in catch here because no documentation on exception behavior is provided catch (Exception e) { Trace.TraceError(e.Message); // Is there any documentation on the meaning of error codes here? The handler suggests that any non-zero value is an error // but does not distinguish between them. callback(1, numBytesToWrite, ovNative); } callback(0, numBytesToWrite, ovNative); }, asyncResult); }
/// <summary> /// <see cref="IDevice.WriteAsync(IntPtr, int, ulong, uint, IOCompletionCallback, IAsyncResult)">Inherited</see> /// </summary> public override void WriteAsync(IntPtr sourceAddress, int segmentId, ulong destinationAddress, uint numBytesToWrite, IOCompletionCallback callback, IAsyncResult asyncResult) { if (!blobs.TryGetValue(segmentId, out BlobEntry blobEntry)) { BlobEntry entry = new BlobEntry(); if (blobs.TryAdd(segmentId, entry)) { CloudPageBlob pageBlob = container.GetPageBlobReference(blobName + segmentId); // If segment size is -1, which denotes absence, we request the largest possible blob. This is okay because // page blobs are not backed by real pages on creation, and the given size is only a the physical limit of // how large it can grow to. var size = segmentSize == -1 ? MAX_BLOB_SIZE : segmentSize; // If no blob exists for the segment, we must first create the segment asynchronouly. (Create call takes ~70 ms by measurement) // After creation is done, we can call write. entry.CreateAsync(size, pageBlob); } // Otherwise, some other thread beat us to it. Okay to use their blobs. blobEntry = blobs[segmentId]; } TryWriteAsync(blobEntry, sourceAddress, destinationAddress, numBytesToWrite, callback, asyncResult); }
internal _IOCompletionCallback(IOCompletionCallback ioCompletionCallback, ref StackCrawlMark stackMark) { this._ioCompletionCallback = ioCompletionCallback; this._executionContext = ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.OptimizeDefaultCase | ExecutionContext.CaptureOptions.IgnoreSyncCtx); }
/// <summary> /// <see cref="IDevice.ReadAsync(int, ulong, IntPtr, uint, IOCompletionCallback, IAsyncResult)"/> /// </summary> /// <param name="segmentId"></param> /// <param name="sourceAddress"></param> /// <param name="destinationAddress"></param> /// <param name="readLength"></param> /// <param name="callback"></param> /// <param name="asyncResult"></param> public unsafe override void ReadAsync(int segmentId, ulong sourceAddress, IntPtr destinationAddress, uint readLength, IOCompletionCallback callback, IAsyncResult asyncResult) { // Starts off in one, in order to prevent some issued writes calling the callback before all parallel writes are issued. var countdown = new CountdownEvent(1); long currentReadStart = (long)sourceAddress; long readEnd = currentReadStart + readLength; uint aggregateErrorCode = 0; while (currentReadStart < readEnd) { long newStart = partitions.MapRange(currentReadStart, readEnd, out int shard, out long shardStartAddress, out long shardEndAddress); ulong writeOffset = (ulong)currentReadStart - sourceAddress; // Because more than one device can return with an error, it is important that we remember the most recent error code we saw. (It is okay to only // report one error out of many. It will be as if we failed on that error and cancelled all other reads, even though we issue reads in parallel and // wait until all of them are complete in the implementation) countdown.AddCount(); partitions.Devices[shard].ReadAsync(segmentId, (ulong)shardStartAddress, IntPtr.Add(destinationAddress, (int)writeOffset), (uint)(shardEndAddress - shardStartAddress), (e, n, o) => { // TODO: this is incorrect if returned "bytes" written is allowed to be less than requested like POSIX. if (e != 0) { aggregateErrorCode = e; } if (countdown.Signal()) { callback(aggregateErrorCode, n, o); countdown.Dispose(); } else { Overlapped.Free(o); } }, asyncResult); currentReadStart = newStart; } // TODO: Check handling of overlapped wrapper if (countdown.Signal()) { Overlapped ov = new Overlapped(0, 0, IntPtr.Zero, asyncResult); NativeOverlapped *ovNative = ov.UnsafePack(callback, IntPtr.Zero); callback(aggregateErrorCode, readLength, ovNative); countdown.Dispose(); } }
private void TryWriteAsync(BlobEntry blobEntry, IntPtr sourceAddress, ulong destinationAddress, uint numBytesToWrite, IOCompletionCallback callback, IAsyncResult asyncResult) { CloudPageBlob pageBlob = blobEntry.GetPageBlob(); // If pageBlob is null, it is being created. Attempt to queue the write for the creator to complete after it is done if (pageBlob == null && blobEntry.TryQueueAction(p => WriteToBlobAsync(p, sourceAddress, destinationAddress, numBytesToWrite, callback, asyncResult))) { return; } // Otherwise, invoke directly. WriteToBlobAsync(pageBlob, sourceAddress, destinationAddress, numBytesToWrite, callback, asyncResult); }
public unsafe NativeOverlapped *UnsafeAllocateNativeOverlapped(IOCompletionCallback callback, object?state, object?pinData) => AllocateNativeOverlapped(callback, state, pinData);
/// <summary> /// <see cref="IDevice.ReadAsync(int, ulong, IntPtr, uint, IOCompletionCallback, IAsyncResult)">Inherited</see> /// </summary> public override unsafe void ReadAsync(int segmentId, ulong sourceAddress, IntPtr destinationAddress, uint readLength, IOCompletionCallback callback, IAsyncResult asyncResult) { // It is up to the allocator to make sure no reads are issued to segments before they are written if (!blobs.TryGetValue(segmentId, out BlobEntry blobEntry)) { throw new InvalidOperationException("Attempting to read non-existent segments"); } // Even though Azure Page Blob does not make use of Overlapped, we populate one to conform to the callback API Overlapped ov = new Overlapped(0, 0, IntPtr.Zero, asyncResult); NativeOverlapped *ovNative = ov.UnsafePack(callback, IntPtr.Zero); UnmanagedMemoryStream stream = new UnmanagedMemoryStream((byte *)destinationAddress, readLength, readLength, FileAccess.Write); CloudPageBlob pageBlob = blobEntry.GetPageBlob(); pageBlob.BeginDownloadRangeToStream(stream, (Int64)sourceAddress, readLength, ar => { try { pageBlob.EndDownloadRangeToStream(ar); } // I don't think I can be more specific in catch here because no documentation on exception behavior is provided catch (Exception e) { Trace.TraceError(e.Message); // Is there any documentation on the meaning of error codes here? The handler suggests that any non-zero value is an error // but does not distinguish between them. callback(2, readLength, ovNative); } callback(0, readLength, ovNative); }, asyncResult); }
internal _IOCompletionCallback(IOCompletionCallback ioCompletionCallback, ExecutionContext executionContext) { _ioCompletionCallback = ioCompletionCallback; _executionContext = executionContext; }
unsafe public NativeOverlapped *Pack (IOCompletionCallback iocb, object userData) { NativeOverlapped *result = (NativeOverlapped *) Marshal.AllocHGlobal (Marshal.SizeOf(typeof(NativeOverlapped))); result->OffsetLow = offsetL; result->OffsetHigh = offsetH; result->EventHandle = evt_ptr; return(result); }
public unsafe NativeOverlapped *UnsafePack(IOCompletionCallback iocb) { return(this.UnsafePack(iocb, (object)null)); }
unsafe public NativeOverlapped *Pack (IOCompletionCallback iocb) { NativeOverlapped *result = (NativeOverlapped *) Marshal.AllocHGlobal (Marshal.SizeOf (typeof (NativeOverlapped))); result->OffsetLow = offsetL; result->OffsetHigh = offsetH; result->EventHandle = (IntPtr)evt; return result; }
public unsafe NativeOverlapped *UnsafePack(IOCompletionCallback iocb, object userData) { return(this.m_overlappedData.UnsafePack(iocb, userData)); }
public static IOCompletionCallback ThunkCallback(IOCompletionCallback callback) { return(new IOCompletionThunk(callback).ThunkFrame); }
private PreAllocatedOverlapped(IOCompletionCallback callback, object?state, object?pinData, bool flowExecutionContext) { ArgumentNullException.ThrowIfNull(callback); _overlapped = new ThreadPoolBoundHandleOverlapped(callback, state, pinData, this, flowExecutionContext); }
public PreAllocatedOverlapped(IOCompletionCallback callback, object?state, object?pinData) : this(callback, state, pinData, flowExecutionContext : true) { }
/// <summary> /// Invoked by users to obtain a record from disk. It uses sector aligned memory to read /// the record efficiently into memory. /// </summary> /// <param name="fromLogical"></param> /// <param name="numBytes"></param> /// <param name="callback"></param> /// <param name="context"></param> /// <param name="result"></param> protected override void AsyncReadRecordObjectsToMemory(long fromLogical, int numBytes, IOCompletionCallback callback, AsyncIOContext <Key, Value> context, SectorAlignedMemory result = default(SectorAlignedMemory)) { throw new InvalidOperationException("AsyncReadRecordObjectsToMemory invalid for BlittableAllocator"); }
/// <summary> /// /// </summary> /// <param name="alignedSourceAddress"></param> /// <param name="alignedDestinationAddress"></param> /// <param name="aligned_read_length"></param> /// <param name="callback"></param> /// <param name="asyncResult"></param> public void ReadAsync(ulong alignedSourceAddress, IntPtr alignedDestinationAddress, uint aligned_read_length, IOCompletionCallback callback, IAsyncResult asyncResult) { var segment = segmentSizeBits < 64 ? alignedSourceAddress >> segmentSizeBits : 0; ReadAsync( (int)segment, alignedSourceAddress & segmentSizeMask, alignedDestinationAddress, aligned_read_length, callback, asyncResult); }
unsafe public NativeOverlapped *UnsafePack(IOCompletionCallback iocb, Object userData) { return(m_overlappedData.UnsafePack(iocb, userData)); }
unsafe public NativeOverlapped *UnsafePack(IOCompletionCallback iocb) { return(UnsafePack(iocb, null)); }
/// <summary> /// /// </summary> /// <param name="sourceAddress"></param> /// <param name="segmentId"></param> /// <param name="destinationAddress"></param> /// <param name="numBytesToWrite"></param> /// <param name="callback"></param> /// <param name="asyncResult"></param> public abstract void WriteAsync(IntPtr sourceAddress, int segmentId, ulong destinationAddress, uint numBytesToWrite, IOCompletionCallback callback, IAsyncResult asyncResult);
public unsafe NativeOverlapped *Pack(IOCompletionCallback iocb) { return(Pack(iocb, null)); }
/// <summary> /// /// </summary> /// <param name="segmentId"></param> /// <param name="sourceAddress"></param> /// <param name="destinationAddress"></param> /// <param name="readLength"></param> /// <param name="callback"></param> /// <param name="asyncResult"></param> public abstract void ReadAsync(int segmentId, ulong sourceAddress, IntPtr destinationAddress, uint readLength, IOCompletionCallback callback, IAsyncResult asyncResult);
public static extern bool BindIoCompletionCallback( SafeCloseSocket socketHandle, IOCompletionCallback function, Int32 flags );
/// <summary> /// /// </summary> /// <param name="alignedSourceAddress"></param> /// <param name="alignedDestinationAddress"></param> /// <param name="numBytesToWrite"></param> /// <param name="callback"></param> /// <param name="asyncResult"></param> public void WriteAsync(IntPtr alignedSourceAddress, ulong alignedDestinationAddress, uint numBytesToWrite, IOCompletionCallback callback, IAsyncResult asyncResult) { var segment = segmentSizeBits < 64 ? alignedDestinationAddress >> segmentSizeBits : 0; WriteAsync( alignedSourceAddress, (int)segment, alignedDestinationAddress & segmentSizeMask, numBytesToWrite, callback, asyncResult); }
unsafe internal NativeOverlapped* UnsafePack(IOCompletionCallback iocb, Object userData) { if (!m_pinSelf.IsNull()) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_Overlapped_Pack")); } m_userObject = userData; if (m_userObject != null) { if (m_userObject.GetType() == typeof(Object[])) { m_isArray = 1; } else { m_isArray = 0; } } m_iocb = iocb; m_iocbHelper = null; return AllocateNativeOverlapped(); }
public static IOCompletionCallback ThunkCallback(IOCompletionCallback callback) { Assert(callback != null, "Trying to create a ThunkCallback with a null callback method"); return((new IOCompletionThunk(callback)).ThunkFrame); }
unsafe public NativeOverlapped* UnsafePack(IOCompletionCallback iocb, Object userData) { return m_overlappedData.UnsafePack(iocb, userData); }
public IOCompletionThunk(IOCompletionCallback callback, ExceptionCallback exceptionCallback) { if (callback == null) throw new ArgumentNullException("callback"); if (exceptionCallback == null) throw new ArgumentNullException("exceptionCallback"); this.callback = callback; this.exceptionCallback = exceptionCallback; }
private void SetData(IOCompletionCallback callback, object state, object pinData, PreAllocatedOverlapped preAllocated) { Debug.Assert(callback != null); OverlappedData data = Data; data._callback = callback; data._state = state; data._executionContext = ExecutionContext.Capture(); data._preAllocated = preAllocated; // // pinData can be any blittable type to be pinned, *or* an instance of object[] each element of which refers to // an instance of a blittable type to be pinned. // if (pinData != null) { object[] objArray = pinData as object[]; if (objArray != null && objArray.GetType() == typeof(object[])) { if (data._pinnedData == null || data._pinnedData.Length < objArray.Length) Array.Resize(ref data._pinnedData, objArray.Length); for (int i = 0; i < objArray.Length; i++) { if (!data._pinnedData[i].IsAllocated) data._pinnedData[i] = GCHandle.Alloc(objArray[i], GCHandleType.Pinned); else data._pinnedData[i].Target = objArray[i]; } } else { if (data._pinnedData == null) data._pinnedData = new GCHandle[1]; if (!data._pinnedData[0].IsAllocated) data._pinnedData[0] = GCHandle.Alloc(pinData, GCHandleType.Pinned); else data._pinnedData[0].Target = pinData; } } }
/// <summary> /// /// </summary> /// <param name="alignedSourceAddress"></param> /// <param name="segmentId"></param> /// <param name="alignedDestinationAddress"></param> /// <param name="numBytesToWrite"></param> /// <param name="callback"></param> /// <param name="asyncResult"></param> public override unsafe void WriteAsync(IntPtr alignedSourceAddress, int segmentId, ulong alignedDestinationAddress, uint numBytesToWrite, IOCompletionCallback callback, IAsyncResult asyncResult) { alignedDestinationAddress = ((ulong)segmentId << 30) | alignedDestinationAddress; Overlapped ov = new Overlapped(0, 0, IntPtr.Zero, asyncResult); NativeOverlapped *ov_native = ov.UnsafePack(callback, IntPtr.Zero); ov_native->OffsetLow = unchecked ((int)(alignedDestinationAddress & 0xFFFFFFFF)); ov_native->OffsetHigh = unchecked ((int)((alignedDestinationAddress >> 32) & 0xFFFFFFFF)); callback(0, numBytesToWrite, ov_native); }
public DummyAsyncResult(IOCompletionCallback iocb) { m_iocb = iocb; }
internal _IOCompletionCallback(IOCompletionCallback ioCompletionCallback) { _ioCompletionCallback = ioCompletionCallback; _executionContext = ExecutionContext.Capture(); }