internal RequestContext( uv_req_type requestType, int size, ScheduleRequest target) { Debug.Assert(size >= 0); Debug.Assert(target is object); _handleSize = NativeMethods.GetSize(requestType); int totalSize = _handleSize + size; IntPtr handle = NativeMethods.Allocate(totalSize); GCHandle gcHandle = GCHandle.Alloc(target, GCHandleType.Normal); *(IntPtr *)handle = GCHandle.ToIntPtr(gcHandle); Handle = handle; _requestType = requestType; #if DEBUG if (Log.DebugEnabled) { Log.Debug("{} {} allocated.", requestType, handle); } #endif }
internal RequestContext(uv_req_type requestType, Action <IntPtr> initializer, ScheduleRequest target) { if (initializer != null && target != null) { HandleSize = NativeMethods.GetSize(requestType); IntPtr handle = Marshal.AllocCoTaskMem(HandleSize); try { initializer(handle); } catch { Marshal.FreeCoTaskMem(handle); throw; } GCHandle gcHandle = GCHandle.Alloc(target, GCHandleType.Normal); *(IntPtr *)handle = GCHandle.ToIntPtr(gcHandle); Handle = handle; this.requestType = requestType; //Log.Info($"{requestType} {handle} allocated."); } else { throw new ArgumentException($"initializer {initializer} and target {target} can't be null."); } }
internal RequestContext( uv_req_type requestType, Action <IntPtr> initializer, ScheduleRequest target) { Debug.Assert(initializer is object); Debug.Assert(target is object); _handleSize = NativeMethods.GetSize(requestType); IntPtr handle = NativeMethods.Allocate(_handleSize); try { initializer(handle); } catch { NativeMethods.FreeMemory(handle); throw; } GCHandle gcHandle = GCHandle.Alloc(target, GCHandleType.Normal); *(IntPtr *)handle = GCHandle.ToIntPtr(gcHandle); Handle = handle; _requestType = requestType; #if DEBUG if (Log.DebugEnabled) { Log.Debug("{} {} allocated.", requestType, handle); } #endif }
internal RequestContext( uv_req_type requestType, Action <IntPtr> initializer, ScheduleRequest target) { Contract.Requires(initializer != null); Contract.Requires(target != null); int size = NativeMethods.GetSize(requestType); IntPtr handle = Marshal.AllocHGlobal(size); try { initializer(handle); } catch { Marshal.FreeHGlobal(handle); throw; } GCHandle gcHandle = GCHandle.Alloc(target, GCHandleType.Normal); *(IntPtr *)handle = GCHandle.ToIntPtr(gcHandle); this.Handle = handle; this.requestType = requestType; Log.DebugFormat("{0} {1} allocated.", requestType, handle); }
internal WatcherRequest( uv_req_type requestType, Action <WatcherRequest, Exception> watcherCallback, Action <IntPtr> initializer, bool closeOnCallback = false) // allocate base NativeHandle with size for this request type! : base(NativeMethods.GetSize(requestType)) { if (initializer != null) { this.RequestType = requestType; this.watcherCallback = watcherCallback; this.closeOnCallback = closeOnCallback; try { initializer(Handle); } catch { FreeHandle(ref Handle); throw; } } else { throw new ArgumentException($"Initializer can't be null!"); } }
protected WriteBufferRequest(uv_req_type requestType) : base(requestType) { Contract.Requires( requestType == uv_req_type.UV_WRITE || requestType == uv_req_type.UV_UDP_SEND); this.handle = new RequestContext(requestType, 0, this); this.bufferRef = null; }
protected NativeRequest(uv_req_type requestType, int size) { IntPtr handle = NativeMethods.Allocate(requestType, size); GCHandle gcHandle = GCHandle.Alloc(this, GCHandleType.Normal); *(IntPtr *)handle = GCHandle.ToIntPtr(gcHandle); this.Handle = handle; this.requestType = requestType; }
internal static int GetSize(uv_req_type requestType) { IntPtr value = uv_req_size(requestType); int size = value.ToInt32(); if (size <= 0) { throw new InvalidOperationException($"Request {requestType} size must be greater than zero."); } return(size); }
internal WorkRequest( uv_req_type requestType, Action <WorkRequest> workCallback, Action <IntPtr> initializer) : base(requestType) { Contract.Requires(workCallback != null); Contract.Requires(initializer != null); this.workCallback = workCallback; this.handle = new RequestContext(requestType, initializer, this); }
internal WatcherRequest( uv_req_type requestType, Action <WatcherRequest, Exception> watcherCallback, int size = 0, bool closeOnCallback = false) : base(requestType) { Contract.Requires(size >= 0); this.watcherCallback = watcherCallback; this.closeOnCallback = closeOnCallback; this.handle = new RequestContext(requestType, size, this); }
internal WatcherRequest( uv_req_type requestType, Action <WatcherRequest, Exception> watcherCallback, int size = 0, bool closeOnCallback = false) : base(requestType) { Debug.Assert(size >= 0); _watcherCallback = watcherCallback; _closeOnCallback = closeOnCallback; _handle = new RequestContext(requestType, size, this); }
internal WatcherRequest( uv_req_type requestType, Action <WatcherRequest, Exception> watcherCallback, Action <IntPtr> initializer, bool closeOnCallback = false) : base(requestType) { Debug.Assert(initializer is object); _watcherCallback = watcherCallback; _closeOnCallback = closeOnCallback; _handle = new RequestContext(requestType, initializer, this); }
internal WatcherRequest( uv_req_type requestType, Action <WatcherRequest, Exception> watcherCallback, Action <IntPtr> initializer, bool closeOnCallback = false) : base(requestType) { Contract.Requires(initializer != null); this.watcherCallback = watcherCallback; this.closeOnCallback = closeOnCallback; this.handle = new RequestContext(requestType, initializer, this); }
protected NativeRequest(uv_req_type requestType, int size) { int totalSize = NativeMethods.uv_req_size(requestType).ToInt32(); totalSize += size; IntPtr handle = Marshal.AllocHGlobal(totalSize); GCHandle gcHandle = GCHandle.Alloc(this, GCHandleType.Normal); *(IntPtr *)handle = GCHandle.ToIntPtr(gcHandle); this.Handle = handle; this.RequestType = requestType; }
internal WriteRequest(uv_req_type requestType, ThreadLocalPool.Handle recyclerHandle) : base(requestType) { Debug.Assert(requestType == uv_req_type.UV_WRITE || requestType == uv_req_type.UV_UDP_SEND); _requestContext = new RequestContext(requestType, BufferSize * MaximumLimit, this); _recyclerHandle = recyclerHandle; _handles = new List <GCHandle>(); IntPtr addr = _requestContext.Handle; _bufs = addr + _requestContext.HandleSize; _pin = GCHandle.Alloc(addr, GCHandleType.Pinned); _count = 0; }
private IntPtr Create(uv_req_type reqType, uv_buf_t buffer) { var requestHandle = _loop.Allocs.AllocRequest(reqType); uv_req_t request = new uv_req_t() { type = reqType, data = buffer.data }; Marshal.StructureToPtr(request, requestHandle, false); _writes.Add(requestHandle, buffer); return(requestHandle); }
internal WatcherRequest( uv_req_type requestType, Action <WatcherRequest, Exception> watcherCallback, Action <IntPtr> initializer, bool closeOnCallback = false) : base(requestType) { if (initializer != null) { this.watcherCallback = watcherCallback; this.closeOnCallback = closeOnCallback; handle = new RequestContext(requestType, initializer, this); } else { throw new ArgumentException($"Initializer can't be null!"); } }
internal RequestContext(uv_req_type requestType, int size, ScheduleRequest target) { if (size >= 0 && target != null) { HandleSize = NativeMethods.GetSize(requestType); int totalSize = HandleSize + size; IntPtr handle = Marshal.AllocCoTaskMem(totalSize); GCHandle gcHandle = GCHandle.Alloc(target, GCHandleType.Normal); *(IntPtr *)handle = GCHandle.ToIntPtr(gcHandle); Handle = handle; this.requestType = requestType; } else { throw new ArgumentException($"Size {size} needs to be >=0 and target {target} can't be null."); } }
internal RequestContext( uv_req_type requestType, Action <IntPtr> initializer, ScheduleRequest target) { Contract.Requires(initializer != null); Contract.Requires(target != null); int size = NativeMethods.GetSize(requestType); IntPtr handle = Marshal.AllocHGlobal(size); initializer(handle); GCHandle gcHandle = GCHandle.Alloc(target, GCHandleType.Normal); ((uv_req_t *)handle)->data = GCHandle.ToIntPtr(gcHandle); this.Handle = handle; this.requestType = requestType; Log.Debug($"{requestType} {handle} allocated."); }
internal RequestContext( uv_req_type requestType, int size, ScheduleRequest target) { Contract.Requires(size >= 0); Contract.Requires(target != null); int totalSize = NativeMethods.GetSize(requestType); totalSize += size; IntPtr handle = Marshal.AllocHGlobal(totalSize); GCHandle gcHandle = GCHandle.Alloc(target, GCHandleType.Normal); *(IntPtr *)handle = GCHandle.ToIntPtr(gcHandle); this.Handle = handle; this.requestType = requestType; Log.Debug($"{requestType} {handle} allocated."); }
internal RequestContext( uv_req_type requestType, int size, ScheduleRequest target) { Contract.Requires(size >= 0); Contract.Requires(target != null); int totalSize = NativeMethods.GetSize(requestType); totalSize += size; IntPtr handle = Marshal.AllocCoTaskMem(totalSize); GCHandle gcHandle = GCHandle.Alloc(target, GCHandleType.Normal); *(IntPtr *)handle = GCHandle.ToIntPtr(gcHandle); this.Handle = handle; this.requestType = requestType; if (Log.IsDebugEnabled) { Log.DebugFormat("{0} {1} allocated.", requestType, handle); } }
public static IntPtr Allocate(uv_req_type requestType) { int size = GetSize(requestType); return(Allocate(size)); }
internal static int GetSize(uv_req_type requestType) => RequestSizeTable[(int)requestType - 1];
/// <summary> /// Creates a request that do not need a buffer /// </summary> /// <param name="reqType"></param> /// <returns></returns> internal IntPtr Create(uv_req_type reqType) { return this.Create(reqType, BufferCollection.EmptyBuffer); }
/// <summary> /// Creates a request that needs to allocate a buffer of the specified size /// </summary> /// <param name="reqType"></param> /// <param name="length"></param> /// <returns></returns> internal IntPtr Create(uv_req_type reqType, uint length) { return Create(reqType, _buffer.CreateBuffer(length)); }
/// <summary> /// Creates a request that needs to allocate a buffer and copy data from the specified buffer /// </summary> /// <param name="reqType"></param> /// <param name="data"></param> /// <param name="offset"></param> /// <param name="length"></param> /// <returns></returns> internal IntPtr Create(uv_req_type reqType, byte[] data, int offset, int length) { return Create(reqType, _buffer.CreateBuffer(data, offset, length)); }
public static void ErrorWhilstClosingHandle(this IInternalLogger logger, uv_req_type requestType, IntPtr handle, Exception exception) { logger.Error($"{requestType} {handle} error whilst closing handle.", exception); }
internal static extern int uv_req_size(uv_req_type reqType);
private IntPtr Create(uv_req_type reqType, uv_buf_t buffer) { var requestHandle = _loop.Allocs.AllocRequest(reqType); uv_req_t request = new uv_req_t() { type = reqType, data = buffer.data }; Marshal.StructureToPtr(request, requestHandle, false); _writes.Add(requestHandle, buffer); return requestHandle; }
internal IntPtr AllocRequest(uv_req_type requestType) { return Alloc(Uvi.uv_req_size(requestType)); }
public static int GetSize(uv_req_type reqType) => uv_req_size(reqType).ToInt32();
internal ScheduleRequest(uv_req_type requestType) { RequestType = requestType; }
internal static int GetSize(uv_req_type requestType) => RequestSizeTable[unchecked ((int)requestType - 1)];
static extern IntPtr uv_req_size(uv_req_type reqType);
public WriteRequest(uv_req_type requestType, IntPtr buf, int len) : base(requestType, len) { _buf = new uv_buf_t(buf, len); }