From 0c59ba8d64c94e61bcb8a62c9d2bc767b6133097 Mon Sep 17 00:00:00 2001 From: vlad zverzhkhovskiy Date: Thu, 7 Aug 2025 10:14:18 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20?= =?UTF-8?q?=D1=81=20=D1=81=D0=BE=D0=BA=D0=B5=D1=82=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/TestController.cs | 1 - .../Broker/Services/ConnectionsReciever.cs | 7 ++++--- .../Broker/Services/MessagesProcessor.cs | 12 +++--------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/development/Sphagnum.DebugClient/Controllers/TestController.cs b/development/Sphagnum.DebugClient/Controllers/TestController.cs index 2146fe0..cbe0141 100644 --- a/development/Sphagnum.DebugClient/Controllers/TestController.cs +++ b/development/Sphagnum.DebugClient/Controllers/TestController.cs @@ -1,7 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Sphagnum.Client; using Sphagnum.Common.Messaging.Contracts; -using Sphagnum.Common.Messaging.Contracts.Messages; namespace Sphagnum.DebugClient.Controllers { diff --git a/src/Sphagnum.Server/Broker/Services/ConnectionsReciever.cs b/src/Sphagnum.Server/Broker/Services/ConnectionsReciever.cs index f34d97b..e659d05 100644 --- a/src/Sphagnum.Server/Broker/Services/ConnectionsReciever.cs +++ b/src/Sphagnum.Server/Broker/Services/ConnectionsReciever.cs @@ -7,6 +7,7 @@ namespace Sphagnum.Server.Broker.Services { public class ConnectionsReciever : IHostedService { + private readonly int _port; private readonly CancellationTokenSource _cts = new(); private Task _acceptationTask; private readonly IConnection _connection; @@ -14,10 +15,9 @@ namespace Sphagnum.Server.Broker.Services private readonly MessagesProcessor _processor; public ConnectionsReciever(ConnectionFactory connectionFactory, ConnectionsManager manager, MessagesProcessor processor) { + _port = connectionFactory.Port; _manager = manager; _connection = connectionFactory.CreateConnection(false).Result; - _connection.Listen(connectionFactory.Port); - _acceptationTask = AcceptationWorker(); _processor = processor; } @@ -41,8 +41,9 @@ namespace Sphagnum.Server.Broker.Services public Task StartAsync(CancellationToken cancellationToken) { + _connection.Bind(new IPEndPoint(IPAddress.Any, _port)); _connection?.Listen(1000); //todo разобраться что делает этот параметр. - //_acceptationTask = AcceptationWorker(_cts.Token); + _acceptationTask = AcceptationWorker(); return Task.CompletedTask; } diff --git a/src/Sphagnum.Server/Broker/Services/MessagesProcessor.cs b/src/Sphagnum.Server/Broker/Services/MessagesProcessor.cs index c829495..7ca2c77 100644 --- a/src/Sphagnum.Server/Broker/Services/MessagesProcessor.cs +++ b/src/Sphagnum.Server/Broker/Services/MessagesProcessor.cs @@ -1,13 +1,7 @@ using Sphagnum.Common.Infrastructure.Contracts; -using Sphagnum.Common.Messaging.Contracts.Messages; -using Sphagnum.Common.Messaging.Utils; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Sphagnum.Common.Messaging.Extensions; +using Sphagnum.Common.Messaging.Utils; +using System.Collections.Concurrent; namespace Sphagnum.Server.Broker.Services { @@ -24,7 +18,7 @@ namespace Sphagnum.Server.Broker.Services } internal static async Task ProcessMessages(IConnection connection) - { + { while (!connection.CancellationTokenSource.IsCancellationRequested) { var data = await connection.ReceiveAsync(connection.CancellationTokenSource.Token);