コード例 #1
0
ファイル: RpcServer.cs プロジェクト: jykgod/SimCivilClient
        public async Task Run()
        {
            IEventLoopGroup bossGroup = new MultithreadEventLoopGroup();

            try
            {
                var bootstrap = new ServerBootstrap();
                bootstrap
                .Group(bossGroup, _workerGroup)
                .Channel <TcpServerSocketChannel>()
                .Option(ChannelOption.SoBacklog, 100)
                .ChildOption(ChannelOption.TcpNodelay, true)
                .ChildOption(ChannelOption.SoKeepalive, true)
                .ChildHandler(
                    new ActionChannelInitializer <IChannel>(
                        ChildChannelInit));

                IChannel serverChannel = await bootstrap.BindAsync(EndPoint);

                ServerChannel = serverChannel;
            }
            catch (Exception ex)
            {
                Task.WaitAll(bossGroup.ShutdownGracefullyAsync(), _workerGroup.ShutdownGracefullyAsync());

                throw;
            }
        }
コード例 #2
0
 public static void stop()
 {
     boundChannel.CloseAsync();
     bossGroup.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
     workerGroup.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
     SERVER_STARTING = false;
 }
コード例 #3
0
        public void Listen(IPEndPoint endPoint, IEventLoopGroup eventLoopGroup)
        {
            ThrowIfDisposed();

            _eventLoopGroup = eventLoopGroup != null
                ? null
                : new MultithreadEventLoopGroup();
            try
            {
                Channel = new Bootstrap()
                          .Group(_eventLoopGroup ?? eventLoopGroup)
                          .Channel <SocketDatagramChannel>()
                          .Handler(new ActionChannelInitializer <IChannel>(ch =>
                {
                    ch.Pipeline
                    .AddLast(new UdpFrameDecoder((int)_owner.Configuration.MessageMaxLength))
                    .AddLast(new UdpFrameEncoder())
                    .AddLast(new UdpHandler(this, _owner));
                }))
                          .BindAsync(endPoint).WaitEx();
            }
            catch (Exception ex)
            {
                _eventLoopGroup?.ShutdownGracefullyAsync();
                _eventLoopGroup = null;
                Channel         = null;
                ex.Rethrow();
            }
        }
コード例 #4
0
        public override async Task <bool> Shutdown()
        {
            try
            {
                var tasks = new List <Task>();
                foreach (var channel in ConnectionGroup)
                {
                    tasks.Add(channel.CloseAsync());
                }
                var   all = Task.WhenAll(tasks);
                await all;

                var   server = ServerChannel?.CloseAsync() ?? TaskEx.Completed;
                await server;

                return(all.IsCompleted && server.IsCompleted);
            }
            finally
            {
                // free all of the connection objects we were holding onto
                ConnectionGroup.Clear();
#pragma warning disable 4014 // shutting down the worker groups can take up to 10 seconds each. Let that happen asnychronously.
                _clientEventLoopGroup.ShutdownGracefullyAsync();
                _serverEventLoopGroup.ShutdownGracefullyAsync();
#pragma warning restore 4014
            }
        }
コード例 #5
0
 public void Dispose()
 {
     GC.SuppressFinalize(this);
     groupA.ShutdownGracefullyAsync();
     groupB.ShutdownGracefullyAsync();
     Task.WaitAll(groupA.TerminationCompletion, groupB.TerminationCompletion);
 }
コード例 #6
0
 private static void Exit()
 {
     Log.Information("Closing...");
     s_apiHost.CloseAsync().WaitEx();
     s_apiEventLoopGroup.ShutdownGracefullyAsync().WaitEx();
     AuthServer.Instance.Dispose();
 }
コード例 #7
0
        public async Task StartAsync <TChannelHandler>(TChannelHandler channelHandler,
                                                       Action <IChannel> configureProcess)
            where TChannelHandler : IChannelHandler
        {
            IEventLoopGroup group = null;

            try
            {
                var channel = await WrapperFactory
                              .CreateUdp(out group)
                              .Configure(bootstrap =>
                {
                    bootstrap
                    .Option(ChannelOption.SoBroadcast, true)
                    .Handler(new LoggingHandler("SRV-LSTN"));
                })
                              .AddQuoteOfTheMomentHandler(channelHandler)
                              .BindAsync(_serverOptions.Port).ConfigureAwait();

                configureProcess.Invoke(channel);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, ex.AsInnerMessage());
            }
            finally
            {
                await group.ShutdownGracefullyAsync(_serverOptions.QuietPeriod, _serverOptions.TimeOut).ConfigureAwait();
            }
        }
コード例 #8
0
        public async Task Shutdown()
        {
            var key = _perfService.StartPerfCalc();
//            InternalLoggerFactory.DefaultFactory.AddProvider(new ConsoleLoggerProvider((s, level) => true, false));

            await _bootstrapChannel.CloseAsync().ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    _logger.Error($"{nameof(Shutdown)} failed", t.Exception);
                }
            });

            _logger.Debug("Closed _bootstrapChannel");

            var nettyCloseTimeout = TimeSpan.FromMilliseconds(100);
            var closingTask       = Task.WhenAll(_bossGroup.ShutdownGracefullyAsync(nettyCloseTimeout, nettyCloseTimeout),
                                                 _workerGroup.ShutdownGracefullyAsync(nettyCloseTimeout, nettyCloseTimeout));

            //we need to add additional timeout on our side as netty is not executing internal timeout properly, often it just hangs forever on closing
            if (await Task.WhenAny(closingTask, Task.Delay(Timeouts.TcpClose)) != closingTask)
            {
                _logger.Warn($"Could not close rlpx connection in {Timeouts.TcpClose.TotalSeconds} seconds");
            }

            _logger.Debug("Closed _bossGroup and _workerGroup");

            _perfService.EndPerfCalc(key, "Close: Rlpx");
        }
コード例 #9
0
ファイル: BootstrapTest.cs プロジェクト: dora-BYR/Fenix
 public void Dispose()
 {
     _groupA.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(5)).GetAwaiter().GetResult();
     _groupB.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(5)).GetAwaiter().GetResult();
     _groupA.TerminationCompletion.GetAwaiter().GetResult();
     _groupB.TerminationCompletion.GetAwaiter().GetResult();
 }
コード例 #10
0
ファイル: NettyServer.cs プロジェクト: wutao0315/zooland
        public override async Task DoDispose()
        {
            try
            {
                foreach (var channel in ConnectionGroup)
                {
                    await channel.CloseAsync();
                }
                await ServerChannel?.CloseAsync();

                //var tasks = new List<Task>();
                //foreach (var channel in ConnectionGroup)
                //{
                //    tasks.Add(channel.CloseAsync());
                //}
                //var all = Task.WhenAll(tasks);
                //all.ConfigureAwait(false).GetAwaiter().GetResult();

                //var server = ServerChannel?.CloseAsync() ?? Task.CompletedTask;
                //server.ConfigureAwait(false).GetAwaiter().GetResult();
            }
            finally
            {
                // free all of the connection objects we were holding onto
                ConnectionGroup.Clear();
                // shutting down the worker groups can take up to 10 seconds each. Let that happen asnychronously.
                await _serverEventLoopGroup.ShutdownGracefullyAsync();
            }
        }
コード例 #11
0
 public void TearDown()
 {
     CloseChannel(_clientChannel);
     CloseChannel(_serverChannel);
     Task.WaitAll(ClientGroup.ShutdownGracefullyAsync(), ServerGroup.ShutdownGracefullyAsync(),
                  WorkerGroup.ShutdownGracefullyAsync());
 }
コード例 #12
0
        public void Listen(IPEndPoint endPoint, IEventLoopGroup eventLoopGroup)
        {
            ThrowIfDisposed();

            if (eventLoopGroup == null)
            {
                throw new ArgumentNullException(nameof(eventLoopGroup));
            }

            _eventLoopGroup = eventLoopGroup;

            try
            {
                Channel = new Bootstrap()
                          .Group(_eventLoopGroup ?? eventLoopGroup)
                          .Channel <SocketDatagramChannel>()
                          .Handler(new ActionChannelInitializer <IChannel>(ch =>
                {
                    ch.Pipeline
                    .AddLast(new UdpFrameDecoder((int)_owner.Configuration.MessageMaxLength))
                    .AddLast(new UdpFrameEncoder())
                    .AddLast(new UdpHandler(this, _owner))
                    .AddLast(new ErrorHandler(_owner));
                }))
                          .BindAsync(endPoint).WaitEx();
            }
            catch (Exception ex)
            {
                _eventLoopGroup?.ShutdownGracefullyAsync(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(10)).WaitEx();
                _eventLoopGroup = null;
                Channel         = null;
                ex.Rethrow();
            }
        }
コード例 #13
0
        public async Task StopAsync()
        {
            await Channel.CloseAsync();

            await _eventLoopGroup.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));

            WebSocketState = WebSocketState.Closed;
        }
コード例 #14
0
ファイル: RpcServerProvider.cs プロジェクト: wbz-hot/Oxygen
        /// <summary>
        /// 关闭tcp服务
        /// </summary>
        /// <returns></returns>
        public async Task CloseServer()
        {
            await boundChannel.CloseAsync();

            await _bossGroup.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));

            await _workerGroup.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
        }
コード例 #15
0
 public void Dispose()
 {
     _disposed = true;
     _group.ShutdownGracefullyAsync();
     _bootstrap = null;
     _group     = null;
     _channel   = null;
 }
コード例 #16
0
ファイル: ConnectionManager.cs プロジェクト: fuding/yupi
        private async Task DoStop()
        {
            await ServerChannel.CloseAsync();

            await MainServerWorkers.ShutdownGracefullyAsync();

            await ChildServerWorkers.ShutdownGracefullyAsync();
        }
コード例 #17
0
        public async Task Stop()
        {
            await _group.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));

            //
            RecvQueue.Clear();
            SendQueue.Clear();
        }
コード例 #18
0
        /// <summary>
        /// 断开连接
        /// </summary>
        /// <returns></returns>
        public async Task DisconnectAsync()
        {
            await _clientChannel.CloseAsync();

            await _group.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));

            OnDisconnected?.Invoke();
        }
コード例 #19
0
 public void Dispose()
 {
     Task.WaitAll(
         _groupA.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(5)),
         _groupB.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(5))
         );
     Task.WaitAll(_groupA.TerminationCompletion, _groupB.TerminationCompletion);
 }
コード例 #20
0
        public void ShutdownBeforeStart()
        {
            IEventLoopGroup group = NewEventLoopGroup();

            Assert.False(group.TerminationCompletion.Wait(TimeSpan.FromMilliseconds(2)));
            group.ShutdownGracefullyAsync(TimeSpan.Zero, TimeSpan.Zero);
            Assert.True(group.TerminationCompletion.Wait(TimeSpan.FromMilliseconds(200)));
        }
コード例 #21
0
        /// <summary>
        /// 断开连接
        /// </summary>
        /// <returns></returns>
        public async Task DisconnectAsync()
        {
            await _clientChannel.CloseAsync();

            await _eventLoopGroup.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));

            Disconnected?.Invoke(this, new MqttClientDisconnectedEventArgs(_options.ClientId));
        }
コード例 #22
0
ファイル: TcpSocketServer.cs プロジェクト: wxlonstar/Fenix
        public async void Shutdown()
        {
            await Task.WhenAll(
                bossGroup?.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)),
                workerGroup?.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)));

            await boundChannel.CloseAsync();
        }
コード例 #23
0
 /// <summary>
 /// 断开连接
 /// </summary>
 /// <returns></returns>
 public async Task DisconnectAsync()
 {
     if (channel != null)
     {
         await channel.CloseAsync();
     }
     await eventLoop.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
 }
コード例 #24
0
        private async Task StopAsync()
        {
            await _boundChannel.CloseAsync();

            await Task.WhenAll(
                _bossGroup.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)),
                _workerGroup.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)));
        }
コード例 #25
0
 public void Dispose()
 {
     Task.Run(async() =>
     {
         await eventLoopGroup.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
     })
     .Wait();
 }
コード例 #26
0
 private async Task FinallyStopAsync()
 {
     PacketHandlerRegistry.StopTicking();
     if (BootstrapType == BootstrapTypeEnum.Server)
     {
         await _workerGroup.ShutdownGracefullyAsync();
     }
     await _bossGroup.ShutdownGracefullyAsync();
 }
コード例 #27
0
 public bool Stop()
 {
     if (Boss != null && Work != null && SocketChannel != null)
     {
         Task.WaitAll(SocketChannel.CloseAsync(), Boss.ShutdownGracefullyAsync(), Work.ShutdownGracefullyAsync());
         return(true);
     }
     return(false);
 }
コード例 #28
0
        public async Task StopAsync(CancellationToken cancellationToken)
        {
            if (_boundChannel != null)
            {
                await _boundChannel.CloseAsync();
            }

            await _workerGroup.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
        }
コード例 #29
0
ファイル: TcpServer.cs プロジェクト: johnson2heng/GeekServer
        /// <summary>
        /// 停止
        /// </summary>
        public static async Task Stop()
        {
            await Task.WhenAll(
                bootstrapChannel.CloseAsync(),
                bossGroup.ShutdownGracefullyAsync(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2)),
                workerGroup.ShutdownGracefullyAsync(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2)));

            LOGGER.Info("tcp server stoped");
        }
コード例 #30
0
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;
            _eventLoopGroup?.ShutdownGracefullyAsync(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(10)).WaitEx();
        }