Пример #1
0
        public unsafe bool TryGetLoop(out Loop loop)
        {
            loop = null;
            try
            {
                IntPtr nativeHandle = this.InternalHandle;
                if (nativeHandle == IntPtr.Zero)
                {
                    return(false);
                }

                IntPtr loopHandle = ((uv_handle_t *)nativeHandle)->loop;
                if (loopHandle != IntPtr.Zero)
                {
                    loop = HandleContext.GetTarget <Loop>(loopHandle);
                }

                return(loop != null);
            }
            catch (Exception exception)
            {
                Log.Warn($"{this.HandleType} Failed to get loop.", exception);
                return(false);
            }
        }
Пример #2
0
        protected override unsafe StreamHandle NewStream()
        {
            IntPtr loopHandle = ((uv_stream_t *)this.InternalHandle)->loop;
            var    loop       = HandleContext.GetTarget <LoopContext>(loopHandle);

            return(new Tcp(loop));
        }
Пример #3
0
        static void OnWorkCallback(IntPtr handle)
        {
            if (handle == IntPtr.Zero)
            {
                return;
            }

            var workHandle = HandleContext.GetTarget <WorkHandle>(handle);

            workHandle?.OnWorkCallback();
        }
Пример #4
0
        internal ScheduleHandle(LoopContext loop, uv_handle_type handleType)
        {
            Contract.Requires(loop != null);

            HandleContext initialHandle = NativeMethods.Initialize(loop.Handle, handleType, this);

            if (initialHandle == null)
            {
                throw new InvalidOperationException($"Initialize {handleType} for loop {loop.Handle} failed.");
            }

            this.handle     = initialHandle;
            this.HandleType = handleType;
        }
Пример #5
0
        static void OnWalkCallback(IntPtr handle, IntPtr loopHandle)
        {
            if (handle == IntPtr.Zero)
            {
                return;
            }

            try
            {
                var target = HandleContext.GetTarget <IDisposable>(handle);
                target?.Dispose();
                Log.Info($"Loop {loopHandle} walk callback disposed {handle} {target?.GetType()}");
            }
            catch (Exception exception)
            {
                Log.Warn($"Loop {loopHandle} Walk callback attempt to close handle {handle} failed. {exception}");
            }
        }
Пример #6
0
        static void OnAllocateCallback(IntPtr handle, IntPtr suggestedSize, out uv_buf_t buf)
        {
            var stream = HandleContext.GetTarget <StreamHandle>(handle);

            stream.OnAllocateCallback(out buf);
        }
Пример #7
0
        static void OnReadCallback(IntPtr handle, IntPtr nread, ref uv_buf_t buf)
        {
            var stream = HandleContext.GetTarget <StreamHandle>(handle);

            stream.OnReadCallback(ref buf, (int)nread.ToInt64());
        }