Skip to content

Commit

Permalink
Fix network
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaioru committed Apr 15, 2024
1 parent bc0345e commit 472e833
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 28 deletions.
5 changes: 0 additions & 5 deletions src/SourceLink.Github.props

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/Edelstein.Application.Server/ProgramHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,37 @@

namespace Edelstein.Common.Network.DotNetty.Transports;

public class NettyTransportAcceptorState : ITransportContext
public class NettyTransportAcceptorState(
IChannel channel,
IEventLoopGroup group0,
IEventLoopGroup group1,
TransportVersion version,
IReadOnlyRepository<string, ISocket> 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<string, ISocket> 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<string, ISocket> Sockets { get; }
public IReadOnlyRepository<string, ISocket> Sockets { get; } = sockets;

public async Task Dispatch(IPacket packet)
=> await Task.WhenAll((await Sockets.RetrieveAll()).Select(s => s.Dispatch(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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 472e833

Please sign in to comment.