From 472e833858395c1e7a5f522efe3a9f92247cbd8b Mon Sep 17 00:00:00 2001 From: Kaioru Date: Mon, 15 Apr 2024 21:01:25 +0800 Subject: [PATCH] Fix network --- src/SourceLink.Github.props | 5 --- .../ProgramHandler.cs | 2 +- .../Transports/NettyTransportAcceptorState.cs | 37 ++++++++----------- .../NettyTransportConnectorState.cs | 2 +- 4 files changed, 18 insertions(+), 28 deletions(-) delete mode 100644 src/SourceLink.Github.props diff --git a/src/SourceLink.Github.props b/src/SourceLink.Github.props deleted file mode 100644 index 77a251340..000000000 --- a/src/SourceLink.Github.props +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/app/Edelstein.Application.Server/ProgramHandler.cs b/src/app/Edelstein.Application.Server/ProgramHandler.cs index 857cf4e06..8078a9294 100644 --- a/src/app/Edelstein.Application.Server/ProgramHandler.cs +++ b/src/app/Edelstein.Application.Server/ProgramHandler.cs @@ -19,7 +19,7 @@ internal static class ProgramHandler public async static Task ExecuteRoot(FileInfo file) { var builder = Host.CreateApplicationBuilder(); - + builder.Services.AddSerilog((_, configuration) => configuration.ReadFrom.Configuration(builder.Configuration)); builder.Services.AddEdelsteinCommonUtilities(); diff --git a/src/common/Edelstein.Common.Network.DotNetty/Transports/NettyTransportAcceptorState.cs b/src/common/Edelstein.Common.Network.DotNetty/Transports/NettyTransportAcceptorState.cs index c3fcd6c58..1ff262948 100644 --- a/src/common/Edelstein.Common.Network.DotNetty/Transports/NettyTransportAcceptorState.cs +++ b/src/common/Edelstein.Common.Network.DotNetty/Transports/NettyTransportAcceptorState.cs @@ -9,25 +9,20 @@ namespace Edelstein.Common.Network.DotNetty.Transports; -public class NettyTransportAcceptorState : ITransportContext +public class NettyTransportAcceptorState( + IChannel channel, + IEventLoopGroup group0, + IEventLoopGroup group1, + TransportVersion version, + IReadOnlyRepository sockets +) + : ITransportContext { - private readonly IChannel _channel; - private readonly IEventLoopGroup _group0; - private readonly IEventLoopGroup _group1; - public NettyTransportAcceptorState(IChannel channel, IEventLoopGroup group0, IEventLoopGroup group1, TransportVersion version, IReadOnlyRepository sockets) - { - _channel = channel; - _group0 = group0; - _group1 = group1; - Version = version; - Sockets = sockets; - } - - public TransportState State => _channel.Active ? TransportState.Opened : TransportState.Closed; - public TransportVersion Version { get; } + public TransportState State => channel.Active ? TransportState.Opened : TransportState.Closed; + public TransportVersion Version { get; } = version; - public IReadOnlyRepository Sockets { get; } + public IReadOnlyRepository Sockets { get; } = sockets; public async Task Dispatch(IPacket packet) => await Task.WhenAll((await Sockets.RetrieveAll()).Select(s => s.Dispatch(packet))); @@ -35,16 +30,16 @@ public async Task Dispatch(IPacket packet) public async Task Close() { await Task.WhenAll((await Sockets.RetrieveAll()).Select(s => s.Close())); - await _channel.CloseAsync(); + await channel.CloseAsync(); #if (DEBUG) - var t0 = _group0.ShutdownGracefullyAsync(TimeSpan.Zero, TimeSpan.Zero); - var t1 = _group1.ShutdownGracefullyAsync(TimeSpan.Zero, TimeSpan.Zero); + var t0 = group0.ShutdownGracefullyAsync(TimeSpan.Zero, TimeSpan.Zero); + var t1 = group1.ShutdownGracefullyAsync(TimeSpan.Zero, TimeSpan.Zero); await Task.WhenAll(t0, t1); #else - var t0 = _group0.ShutdownGracefullyAsync(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10)); - var t1 = _group1.ShutdownGracefullyAsync(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10)); + var t0 = group0.ShutdownGracefullyAsync(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10)); + var t1 = group1.ShutdownGracefullyAsync(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10)); await Task.WhenAll(t0, t1); #endif diff --git a/src/common/Edelstein.Common.Network.DotNetty/Transports/NettyTransportConnectorState.cs b/src/common/Edelstein.Common.Network.DotNetty/Transports/NettyTransportConnectorState.cs index 1900c6ab4..cfe069da7 100644 --- a/src/common/Edelstein.Common.Network.DotNetty/Transports/NettyTransportConnectorState.cs +++ b/src/common/Edelstein.Common.Network.DotNetty/Transports/NettyTransportConnectorState.cs @@ -34,7 +34,7 @@ public async Task Close() #if (DEBUG) await group0.ShutdownGracefullyAsync(TimeSpan.Zero, TimeSpan.Zero); #else - await _group0.ShutdownGracefullyAsync(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(5)); + await group0.ShutdownGracefullyAsync(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(5)); #endif } }