コード例 #1
0
        internal static void Start(uv_handle_type handleType, IntPtr handle)
        {
            Debug.Assert(handle != IntPtr.Zero);

            int result;

            switch (handleType)
            {
            case uv_handle_type.UV_PREPARE:
                result = uv_prepare_start(handle, WorkHandle.WorkCallback);
                break;

            case uv_handle_type.UV_CHECK:
                result = uv_check_start(handle, WorkHandle.WorkCallback);
                break;

            case uv_handle_type.UV_IDLE:
                result = uv_idle_start(handle, WorkHandle.WorkCallback);
                break;

            default:
                throw new NotSupportedException($"Handle type to start {handleType} not supported");
            }
            ThrowIfError(result);
        }
コード例 #2
0
ファイル: ServerStream.cs プロジェクト: PlumpMath/NetUV
 internal ServerStream(
     LoopContext loop,
     uv_handle_type handleType,
     params object[] args)
     : base(loop, handleType, args)
 {
 }
コード例 #3
0
 internal StreamHandle(
     LoopContext loop,
     uv_handle_type handleType)
     : base(loop, handleType)
 {
     this.Pipeline = new Pipeline(this);
 }
コード例 #4
0
ファイル: TcpStream.cs プロジェクト: dstoffels/Theia
        // constructor /////////////////////////////////////////////////////////
        public TcpStream(Loop loop)
        {
            // make sure loop can be used
            loop.Validate();

            // converting OnFramingCallback to Action allocates.
            // lets do it only once, instead of every ReadCallback.
            FramingCallback = OnFramingCallback;

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

            if (initialHandle != null)
            {
                handle     = initialHandle;
                HandleType = uv_handle_type.UV_TCP;

                // note: setting send/recv buffer sizes gives EBADF when trying it
                // here. instead we call ConfigureSendReceiveBufferSize after
                // successful connects.
            }
            else
            {
                throw new ArgumentException($"{nameof(TcpStream)} Initialize failed for handle: {loop.Handle}");
            }
        }
コード例 #5
0
ファイル: NativeHandles.cs プロジェクト: ihaiucom/NetworkCore
        internal static void Stop(uv_handle_type handleType, IntPtr handle)
        {
            switch (handleType)
            {
            case uv_handle_type.UV_TIMER:
                Invoke(uv_timer_stop, handle);
                break;

            case uv_handle_type.UV_PREPARE:
                InvokeAction(uv_prepare_stop, handle);
                break;

            case uv_handle_type.UV_CHECK:
                InvokeFunction(uv_check_stop, handle);
                break;

            case uv_handle_type.UV_IDLE:
                InvokeFunction(uv_idle_stop, handle);
                break;

            default:
                throw new NotSupportedException($"Handle type to stop {handleType} not supported");
            }

            Log.Debug($"{handleType} {handle} stopped.");
        }
コード例 #6
0
        public unsafe StreamHandle CreatePendingType()
        {
            this.Validate();

            StreamHandle handle = null;

            int count = this.PendingCount();

            if (count > 0)
            {
                IntPtr         loopHandle = ((uv_stream_t *)this.InternalHandle)->loop;
                var            loop       = HandleContext.GetTarget <LoopContext>(loopHandle);
                uv_handle_type handleType = NativeMethods.PipePendingType(this.InternalHandle);

                if (handleType == uv_handle_type.UV_TCP)
                {
                    handle = new Tcp(loop);
                }
                else if (handleType == uv_handle_type.UV_NAMED_PIPE)
                {
                    handle = new Pipe(loop);
                }
                else
                {
                    throw new InvalidOperationException($"{handleType} not supported or IPC over Pipe is disabled.");
                }

                NativeMethods.StreamAccept(this.InternalHandle, handle.InternalHandle);
            }

            return(handle);
        }
コード例 #7
0
ファイル: LoopAllocs.cs プロジェクト: PlumpMath/sharpuv
        internal IntPtr AllocHandle(uv_handle_type handleType)
        {
            var ret = Alloc(Uvi.uv_handle_size(handleType));

            _allocatedHandles++;
            return(ret);
        }
コード例 #8
0
        protected internal override unsafe StreamHandle NewStream()
        {
            IntPtr         loopHandle = ((uv_stream_t *)this.InternalHandle)->loop;
            var            loop       = HandleContext.GetTarget <LoopContext>(loopHandle);
            uv_handle_type type       = ((uv_stream_t *)this.InternalHandle)->type;

            StreamHandle client;

            if (type == uv_handle_type.UV_NAMED_PIPE)
            {
                client = new Pipe(loop, this.ipc);
            }
            else if (type == uv_handle_type.UV_TCP)
            {
                client = new Tcp(loop);
            }
            else
            {
                throw new InvalidOperationException($"Pipe IPC handle {type} not supported");
            }

            NativeMethods.StreamAccept(this.InternalHandle, client.InternalHandle);
            if (!this.ipc)
            {
                client.ReadStart();
            }

            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("{0} {1} client {2} accepted. (IPC : {3})", this.HandleType, this.InternalHandle, client.InternalHandle, this.ipc);
            }

            return(client);
        }
コード例 #9
0
        public unsafe StreamHandle CreatePendingType()
        {
            Validate();

            StreamHandle handle = null;
            int          count  = PendingCount();

            if (count > 0)
            {
                IntPtr         loopHandle = ((uv_stream_t *)InternalHandle)->loop;
                var            loop       = HandleContext.GetTarget <LoopContext>(loopHandle);
                uv_handle_type handleType = NativeMethods.PipePendingType(InternalHandle);

                switch (handleType)
                {
                case uv_handle_type.UV_TCP:
                    handle = new Tcp(loop);
                    break;

                case uv_handle_type.UV_NAMED_PIPE:
                    handle = new Pipe(loop);
                    break;

                default:
                    throw ThrowHelper.GetInvalidOperationException_uv_handle_type_not_supported_or_IPC_over_Pipe_is_disabled(handleType);
                }

                NativeMethods.StreamAccept(InternalHandle, handle.InternalHandle);
                handle.ReadStart();
            }

            return(handle);
        }
コード例 #10
0
 internal WorkHandle(
     LoopContext loop,
     uv_handle_type handleType,
     params object[] args)
     : base(loop, handleType, args)
 {
 }
コード例 #11
0
        internal static void Start(uv_handle_type handleType, IntPtr handle)
        {
            Contract.Requires(handle != IntPtr.Zero);

            int result;

            switch (handleType)
            {
            case uv_handle_type.UV_PREPARE:
                result = uv_prepare_start(handle, WorkHandle.WorkCallback);
                break;

            case uv_handle_type.UV_CHECK:
                result = uv_check_start(handle, WorkHandle.WorkCallback);
                break;

            case uv_handle_type.UV_IDLE:
                result = uv_idle_start(handle, WorkHandle.WorkCallback);
                break;

            default:
                throw new NotSupportedException($"Handle type to start {handleType} not supported");
            }

            if (result < 0)
            {
                throw CreateError((uv_err_code)result);
            }
        }
コード例 #12
0
        internal HandleContext(
            uv_handle_type handleType,
            Func <IntPtr, IntPtr, int> initializer,
            IntPtr loopHandle,
            TcpStream target)
        {
            if (loopHandle != IntPtr.Zero && initializer != null && target != null)
            {
                int    size   = NativeMethods.GetSize(handleType);
                IntPtr handle = Marshal.AllocCoTaskMem(size);

                try
                {
                    int result = initializer(loopHandle, handle);
                    NativeMethods.ThrowIfError(result);
                }
                catch (Exception)
                {
                    Marshal.FreeCoTaskMem(handle);
                    throw;
                }

                GCHandle gcHandle = GCHandle.Alloc(target, GCHandleType.Normal);
                ((uv_handle_t *)handle)->data = GCHandle.ToIntPtr(gcHandle);

                Handle          = handle;
                this.handleType = handleType;
                //Logger.Log($"{handleType} {handle} allocated");
            }
            else
            {
                throw new ArgumentException($"loopHandle {loopHandle}, initializer {initializer}, target {target} can't be null!");
            }
        }
コード例 #13
0
ファイル: StreamHandle.cs プロジェクト: PlumpMath/NetUV
 internal StreamHandle(
     LoopContext loop,
     uv_handle_type handleType,
     params object[] args)
     : base(loop, handleType, args)
 {
     this.pipeline = new Pipeline(this);
 }
コード例 #14
0
ファイル: NativeHandles.cs プロジェクト: ihaiucom/NetworkCore
        internal static int GetSize(uv_handle_type handleType)
        {
            IntPtr value = uv_handle_size(handleType);
            int    size  = value.ToInt32();

            if (size <= 0)
            {
                throw new InvalidOperationException($"Handle {handleType} size must be greater than zero.");
            }

            return(size);
        }
コード例 #15
0
ファイル: ScheduleHandle.cs プロジェクト: heng83/NetUV
        internal ScheduleHandle(
            LoopContext loop,
            uv_handle_type handleType,
            object[] args = null)
        {
            Contract.Requires(loop != null);

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

            Debug.Assert(initialHandle != null);

            this.handle     = initialHandle;
            this.HandleType = handleType;
        }
コード例 #16
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;
        }
コード例 #17
0
        internal static HandleContext Initialize(IntPtr loopHandle, uv_handle_type handleType, ScheduleHandle target, object[] args)
        {
            Debug.Assert(loopHandle != IntPtr.Zero);
            Debug.Assert(target != null);

            switch (handleType)
            {
            case uv_handle_type.UV_TIMER:
                return(new HandleContext(handleType, InitializeTimer, loopHandle, target, args));

            case uv_handle_type.UV_PREPARE:
                return(new HandleContext(handleType, InitializePrepare, loopHandle, target, args));

            case uv_handle_type.UV_CHECK:
                return(new HandleContext(handleType, InitializeCheck, loopHandle, target, args));

            case uv_handle_type.UV_IDLE:
                return(new HandleContext(handleType, InitializeIdle, loopHandle, target, args));

            case uv_handle_type.UV_ASYNC:
                return(new HandleContext(handleType, InitializeAsync, loopHandle, target, args));

            case uv_handle_type.UV_POLL:
                return(new HandleContext(handleType, InitializePoll, loopHandle, target, args));

            case uv_handle_type.UV_SIGNAL:
                return(new HandleContext(handleType, InitializeSignal, loopHandle, target, args));

            case uv_handle_type.UV_TCP:
                return(new HandleContext(handleType, InitializeTcp, loopHandle, target, args));

            case uv_handle_type.UV_NAMED_PIPE:
                return(new HandleContext(handleType, InitializePipe, loopHandle, target, args));

            case uv_handle_type.UV_TTY:
                return(new HandleContext(handleType, InitializeTty, loopHandle, target, args));

            case uv_handle_type.UV_UDP:
                return(new HandleContext(handleType, InitializeUdp, loopHandle, target, args));

            case uv_handle_type.UV_FS_EVENT:
                return(new HandleContext(handleType, InitializeFSEvent, loopHandle, target, args));

            case uv_handle_type.UV_FS_POLL:
                return(new HandleContext(handleType, InitializeFSPoll, loopHandle, target, args));

            default:
                throw new NotSupportedException($"Handle type to initialize {handleType} not supported");
            }
        }
コード例 #18
0
ファイル: ScheduleHandle.cs プロジェクト: yyjdelete/SpanNetty
        internal ScheduleHandle(
            LoopContext loop,
            uv_handle_type handleType,
            object[] args = null)
        {
            if (loop is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.loop);
            }

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

            Debug.Assert(initialHandle is object);

            _handle    = initialHandle;
            HandleType = handleType;
        }
コード例 #19
0
        internal static void Stop(uv_handle_type handleType, IntPtr handle)
        {
            Contract.Requires(handle != IntPtr.Zero);

            switch (handleType)
            {
            case uv_handle_type.UV_TIMER:
                int result = uv_timer_stop(handle);
                if (result < 0)
                {
                    throw CreateError((uv_err_code)result);
                }
                break;

            case uv_handle_type.UV_PREPARE:
                uv_prepare_stop(handle);
                break;

            case uv_handle_type.UV_CHECK:
                uv_check_stop(handle);
                break;

            case uv_handle_type.UV_IDLE:
                uv_idle_stop(handle);
                break;

            case uv_handle_type.UV_POLL:
                uv_poll_stop(handle);
                break;

            case uv_handle_type.UV_SIGNAL:
                uv_signal_stop(handle);
                break;

            case uv_handle_type.UV_FS_EVENT:
                uv_fs_event_stop(handle);
                break;

            case uv_handle_type.UV_FS_POLL:
                uv_fs_poll_stop(handle);
                break;

            default:
                throw new NotSupportedException($"Handle type to stop {handleType} not supported");
            }
        }
コード例 #20
0
ファイル: NativeHandles.cs プロジェクト: dstoffels/Theia
        internal static HandleContext Initialize(IntPtr loopHandle, uv_handle_type handleType, TcpStream target)
        {
            if (loopHandle != IntPtr.Zero && target != null)
            {
                switch (handleType)
                {
                case uv_handle_type.UV_TCP:
                    return(new HandleContext(handleType, InitializeTcp, loopHandle, target));

                default:
                    throw new NotSupportedException($"Handle type to initialize {handleType} not supported");
                }
            }
            else
            {
                throw new ArgumentException($"loopHandle {loopHandle} and target {target} can't be null!");
            }
        }
コード例 #21
0
ファイル: HandleContext.cs プロジェクト: heng83/NetUV
        internal HandleContext(
            uv_handle_type handleType,
            Func <IntPtr, IntPtr, object[], int> initializer,
            IntPtr loopHandle,
            ScheduleHandle target,
            params object[] args)
        {
            Contract.Requires(loopHandle != IntPtr.Zero);
            Contract.Requires(initializer != null);
            Contract.Requires(target != null);

            int    size   = NativeMethods.GetSize(handleType);
            IntPtr handle = Marshal.AllocHGlobal(size);

            int result;

            try
            {
                result = initializer(loopHandle, handle, args);
            }
            catch (Exception)
            {
                Marshal.FreeHGlobal(handle);
                throw;
            }
            if (result < 0)
            {
                Marshal.FreeHGlobal(handle);
                throw NativeMethods.CreateError((uv_err_code)result);
            }

            GCHandle gcHandle = GCHandle.Alloc(target, GCHandleType.Normal);

            ((uv_handle_t *)handle)->data = GCHandle.ToIntPtr(gcHandle);

            this.Handle     = handle;
            this.handleType = handleType;

            if (Log.IsInfoEnabled)
            {
                Log.InfoFormat("{0} {1} allocated.", handleType, handle);
            }
        }
コード例 #22
0
        internal static void Stop(uv_handle_type handleType, IntPtr handle)
        {
            Debug.Assert(handle != IntPtr.Zero);

            switch (handleType)
            {
            case uv_handle_type.UV_TIMER:
                int result = uv_timer_stop(handle);
                ThrowIfError(result);
                break;

            case uv_handle_type.UV_PREPARE:
                uv_prepare_stop(handle);
                break;

            case uv_handle_type.UV_CHECK:
                uv_check_stop(handle);
                break;

            case uv_handle_type.UV_IDLE:
                uv_idle_stop(handle);
                break;

            case uv_handle_type.UV_POLL:
                uv_poll_stop(handle);
                break;

            case uv_handle_type.UV_SIGNAL:
                uv_signal_stop(handle);
                break;

            case uv_handle_type.UV_FS_EVENT:
                uv_fs_event_stop(handle);
                break;

            case uv_handle_type.UV_FS_POLL:
                uv_fs_poll_stop(handle);
                break;

            default:
                throw new NotSupportedException($"Handle type to stop {handleType} not supported");
            }
        }
コード例 #23
0
        internal HandleContext(
            uv_handle_type handleType,
            Action <IntPtr> initializer,
            ScheduleHandle target)
        {
            Contract.Requires(initializer != null);
            Contract.Requires(target != null);

            int    size   = NativeMethods.GetSize(handleType);
            IntPtr handle = Marshal.AllocHGlobal(size);

            initializer(handle);

            GCHandle gcHandle = GCHandle.Alloc(target, GCHandleType.Normal);

            ((uv_handle_t *)handle)->data = GCHandle.ToIntPtr(gcHandle);

            this.Handle     = handle;
            this.handleType = handleType;

            Log.Info($"{handleType} {handle} allocated.");
        }
コード例 #24
0
ファイル: NativeHandles.cs プロジェクト: ihaiucom/NetworkCore
        internal static void Start(uv_handle_type handleType, IntPtr handle, uv_work_cb callback)
        {
            switch (handleType)
            {
            case uv_handle_type.UV_PREPARE:
                Invoke(uv_prepare_start, handle, callback);
                break;

            case uv_handle_type.UV_CHECK:
                Invoke(uv_check_start, handle, callback);
                break;

            case uv_handle_type.UV_IDLE:
                Invoke(uv_idle_start, handle, callback);
                break;

            default:
                throw new NotSupportedException($"Handle type to start {handleType} not supported");
            }

            Log.Debug($"{handleType} {handle} started.");
        }
コード例 #25
0
        protected internal override unsafe StreamHandle NewStream()
        {
            IntPtr         loopHandle = ((uv_stream_t *)InternalHandle)->loop;
            var            loop       = HandleContext.GetTarget <LoopContext>(loopHandle);
            uv_handle_type type       = ((uv_stream_t *)InternalHandle)->type;

            StreamHandle client;

            switch (type)
            {
            case uv_handle_type.UV_NAMED_PIPE:
                client = new Pipe(loop, _ipc);
                break;

            case uv_handle_type.UV_TCP:
                client = new Tcp(loop);
                break;

            default:
                throw ThrowHelper.GetInvalidOperationException_Pipe_IPC_handle_not_supported(type);
            }

            NativeMethods.StreamAccept(InternalHandle, client.InternalHandle);
            if (!_ipc)
            {
                client.ReadStart();
            }

#if DEBUG
            if (Log.DebugEnabled)
            {
                Log.Debug("{} {1} client {} accepted. (IPC : {})", HandleType, InternalHandle, client.InternalHandle, _ipc);
            }
#endif

            return(client);
        }
コード例 #26
0
ファイル: NativeHandles.cs プロジェクト: ihaiucom/NetworkCore
        internal static HandleContext Initialize(IntPtr loopHandle, uv_handle_type handleType, ScheduleHandle target)
        {
            Action <IntPtr> action;

            switch (handleType)
            {
            case uv_handle_type.UV_TIMER:
                action = handle => Invoke(uv_timer_init, loopHandle, handle);
                break;

            case uv_handle_type.UV_PREPARE:
                action = handle => Invoke(uv_prepare_init, loopHandle, handle);
                break;

            case uv_handle_type.UV_CHECK:
                action = handle => Invoke(uv_check_init, loopHandle, handle);
                break;

            case uv_handle_type.UV_IDLE:
                action = handle => Invoke(uv_idle_init, loopHandle, handle);
                break;

            case uv_handle_type.UV_ASYNC:
                action = handle => Invoke(uv_async_init, loopHandle, handle,
                                          WorkHandle.WorkCallback);
                break;

            case uv_handle_type.UV_TCP:
                action = handle => Invoke(uv_tcp_init, loopHandle, handle);
                break;

            default:
                throw new NotSupportedException($"Handle type to initialize {handleType} not supported");
            }

            return(new HandleContext(handleType, action, target));
        }
コード例 #27
0
        internal HandleContext(
            uv_handle_type handleType,
            Func <IntPtr, IntPtr, object[], int> initializer,
            IntPtr loopHandle,
            ScheduleHandle target,
            params object[] args)
        {
            Debug.Assert(loopHandle != IntPtr.Zero);
            Debug.Assert(initializer is object);
            Debug.Assert(target is object);

            int    size   = NativeMethods.GetSize(handleType);
            IntPtr handle = NativeMethods.Allocate(size);

            try
            {
                int result = initializer(loopHandle, handle, args);
                NativeMethods.ThrowIfError(result);
            }
            catch (Exception)
            {
                NativeMethods.FreeMemory(handle);
                throw;
            }

            GCHandle gcHandle = GCHandle.Alloc(target, GCHandleType.Normal);

            ((uv_handle_t *)handle)->data = GCHandle.ToIntPtr(gcHandle);

            Handle      = handle;
            _handleType = handleType;

            if (Log.InfoEnabled)
            {
                Log.HandleAllocated(handleType, handle);
            }
        }
コード例 #28
0
ファイル: UvHandle.cs プロジェクト: gigi81/sharpuv
 internal UvHandle(Loop loop, uv_handle_type handleType)
     : this(loop)
 {
     _handle = loop.Allocs.AllocHandle(handleType);
 }
コード例 #29
0
ファイル: UvStream.cs プロジェクト: gigi81/sharpuv
 internal UvStream(Loop loop, uv_handle_type handleType)
     : base(loop, handleType)
 {
 }
コード例 #30
0
 internal UvHandle(Loop loop, uv_handle_type handleType)
     : this(loop)
 {
     _handle = loop.Allocs.AllocHandle(handleType);
 }
コード例 #31
0
 public static void CallbackRrror(this IInternalLogger logger, uv_handle_type handleType, IntPtr handle, Exception exception)
 {
     logger.Error($"{handleType} {handle} callback error.", exception);
 }
コード例 #32
0
ファイル: Imports.cs プロジェクト: gigi81/sharpuv
 internal static extern int uv_handle_size(uv_handle_type handleType);
コード例 #33
0
ファイル: Libuv.cs プロジェクト: richygithub/GameServer
        public static IntPtr Allocate(uv_handle_type handleType)
        {
            int size = GetSize(handleType);

            return(Allocate(size));
        }
コード例 #34
0
 internal IntPtr Alloc(uv_handle_type handleType)
 {
     return Alloc(Uvi.uv_handle_size(handleType));
 }
コード例 #35
0
 internal UvHandle(Loop loop, uv_handle_type handleType)
 {
     this.Loop = loop;
     this.Handle = this.Alloc(handleType);
     this.Status = HandleStatus.Open;
 }
コード例 #36
0
ファイル: LoopAllocs.cs プロジェクト: gigi81/sharpuv
 internal IntPtr AllocHandle(uv_handle_type handleType)
 {
     var ret = Alloc(Uvi.uv_handle_size(handleType));
     _allocatedHandles++;
     return ret;
 }