Корректная работа с сокетом
parent
1f987c6982
commit
0c59ba8d64
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue