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; } }
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; }
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(); } }
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 } }
public void Dispose() { GC.SuppressFinalize(this); groupA.ShutdownGracefullyAsync(); groupB.ShutdownGracefullyAsync(); Task.WaitAll(groupA.TerminationCompletion, groupB.TerminationCompletion); }
private static void Exit() { Log.Information("Closing..."); s_apiHost.CloseAsync().WaitEx(); s_apiEventLoopGroup.ShutdownGracefullyAsync().WaitEx(); AuthServer.Instance.Dispose(); }
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(); } }
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"); }
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(); }
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(); } }
public void TearDown() { CloseChannel(_clientChannel); CloseChannel(_serverChannel); Task.WaitAll(ClientGroup.ShutdownGracefullyAsync(), ServerGroup.ShutdownGracefullyAsync(), WorkerGroup.ShutdownGracefullyAsync()); }
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(); } }
public async Task StopAsync() { await Channel.CloseAsync(); await _eventLoopGroup.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)); WebSocketState = WebSocketState.Closed; }
/// <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)); }
public void Dispose() { _disposed = true; _group.ShutdownGracefullyAsync(); _bootstrap = null; _group = null; _channel = null; }
private async Task DoStop() { await ServerChannel.CloseAsync(); await MainServerWorkers.ShutdownGracefullyAsync(); await ChildServerWorkers.ShutdownGracefullyAsync(); }
public async Task Stop() { await _group.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)); // RecvQueue.Clear(); SendQueue.Clear(); }
/// <summary> /// 断开连接 /// </summary> /// <returns></returns> public async Task DisconnectAsync() { await _clientChannel.CloseAsync(); await _group.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)); OnDisconnected?.Invoke(); }
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); }
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))); }
/// <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)); }
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(); }
/// <summary> /// 断开连接 /// </summary> /// <returns></returns> public async Task DisconnectAsync() { if (channel != null) { await channel.CloseAsync(); } await eventLoop.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)); }
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))); }
public void Dispose() { Task.Run(async() => { await eventLoopGroup.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)); }) .Wait(); }
private async Task FinallyStopAsync() { PacketHandlerRegistry.StopTicking(); if (BootstrapType == BootstrapTypeEnum.Server) { await _workerGroup.ShutdownGracefullyAsync(); } await _bossGroup.ShutdownGracefullyAsync(); }
public bool Stop() { if (Boss != null && Work != null && SocketChannel != null) { Task.WaitAll(SocketChannel.CloseAsync(), Boss.ShutdownGracefullyAsync(), Work.ShutdownGracefullyAsync()); return(true); } return(false); }
public async Task StopAsync(CancellationToken cancellationToken) { if (_boundChannel != null) { await _boundChannel.CloseAsync(); } await _workerGroup.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)); }
/// <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"); }
public void Dispose() { if (_disposed) { return; } _disposed = true; _eventLoopGroup?.ShutdownGracefullyAsync(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(10)).WaitEx(); }