Esempio n. 1
0
        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
        }
Esempio n. 2
0
        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.");
            }
        }
Esempio n. 3
0
        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
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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!");
            }
        }
Esempio n. 6
0
        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;
        }
Esempio n. 7
0
        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;
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        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;
        }
Esempio n. 15
0
        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;
        }
Esempio n. 16
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);
        }
Esempio n. 17
0
 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!");
     }
 }
Esempio n. 18
0
        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.");
            }
        }
Esempio n. 19
0
        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.");
        }
Esempio n. 20
0
        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.");
        }
Esempio n. 21
0
        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);
            }
        }
Esempio n. 22
0
        public static IntPtr Allocate(uv_req_type requestType)
        {
            int size = GetSize(requestType);

            return(Allocate(size));
        }
Esempio n. 23
0
 internal static int GetSize(uv_req_type requestType) => RequestSizeTable[(int)requestType - 1];
Esempio n. 24
0
 /// <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);
 }
Esempio n. 25
0
 /// <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));
 }
Esempio n. 26
0
 /// <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));
 }
Esempio n. 27
0
 public static void ErrorWhilstClosingHandle(this IInternalLogger logger, uv_req_type requestType, IntPtr handle, Exception exception)
 {
     logger.Error($"{requestType} {handle} error whilst closing handle.", exception);
 }
Esempio n. 28
0
 internal static extern int uv_req_size(uv_req_type reqType);
Esempio n. 29
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;
        }
Esempio n. 30
0
 internal IntPtr AllocRequest(uv_req_type requestType)
 {
     return Alloc(Uvi.uv_req_size(requestType));
 }
Esempio n. 31
0
 internal static extern int uv_req_size(uv_req_type reqType);
Esempio n. 32
0
 public static int GetSize(uv_req_type reqType) => uv_req_size(reqType).ToInt32();
Esempio n. 33
0
 internal ScheduleRequest(uv_req_type requestType)
 {
     RequestType = requestType;
 }
Esempio n. 34
0
 internal static int GetSize(uv_req_type requestType) => RequestSizeTable[unchecked ((int)requestType - 1)];
Esempio n. 35
0
 static extern IntPtr uv_req_size(uv_req_type reqType);
Esempio n. 36
0
 public WriteRequest(uv_req_type requestType, IntPtr buf, int len) : base(requestType, len)
 {
     _buf = new uv_buf_t(buf, len);
 }