소스 검색

Merge pull request #266 from VladimirAkopyan/master

Limiting the growth of PendingMessagesQueue to a configurable Value
release/3.x.x
Christian 6 년 전
committed by GitHub
부모
커밋
910c123887
No known key found for this signature in database GPG 키 ID: 4AEE18F83AFDEB23
5개의 변경된 파일25개의 추가작업 그리고 1개의 파일을 삭제
  1. +2
    -0
      Frameworks/MQTTnet.NetStandard/Server/IMqttServerOptions.cs
  2. +11
    -0
      Frameworks/MQTTnet.NetStandard/Server/MqttClientPendingMessagesQueue.cs
  3. +4
    -1
      Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs
  4. +2
    -0
      Frameworks/MQTTnet.NetStandard/Server/MqttServerOptions.cs
  5. +6
    -0
      Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsBuilder.cs

+ 2
- 0
Frameworks/MQTTnet.NetStandard/Server/IMqttServerOptions.cs 파일 보기

@@ -5,6 +5,8 @@ namespace MQTTnet.Server
public interface IMqttServerOptions
{
int ConnectionBacklog { get; }
int MaxPendingMessagesPerClient { get; }

TimeSpan DefaultCommunicationTimeout { get; }

Action<MqttConnectionValidatorContext> ConnectionValidator { get; }


+ 11
- 0
Frameworks/MQTTnet.NetStandard/Server/MqttClientPendingMessagesQueue.cs 파일 보기

@@ -50,6 +50,17 @@ namespace MQTTnet.Server
}
}

public async Task DropPacket()
{
MqttBasePacket packet = null;
await _queueWaitSemaphore.WaitAsync().ConfigureAwait(false);
if (!_queue.TryDequeue(out packet))
{
throw new InvalidOperationException(); // should not happen
}
_queueWaitSemaphore.Release();
}

public void Enqueue(MqttBasePacket packet)
{
if (packet == null) throw new ArgumentNullException(nameof(packet));


+ 4
- 1
Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs 파일 보기

@@ -147,7 +147,10 @@ namespace MQTTnet.Server
{
publishPacket.PacketIdentifier = _packetIdentifierProvider.GetNewPacketIdentifier();
}

if (_options.MaxPendingMessagesPerClient <= PendingMessagesQueue.Count)
{
await PendingMessagesQueue.DropPacket();
}
PendingMessagesQueue.Enqueue(publishPacket);
}



+ 2
- 0
Frameworks/MQTTnet.NetStandard/Server/MqttServerOptions.cs 파일 보기

@@ -9,6 +9,8 @@ namespace MQTTnet.Server
public MqttServerTlsEndpointOptions TlsEndpointOptions { get; } = new MqttServerTlsEndpointOptions();

public int ConnectionBacklog { get; set; } = 10;

public int MaxPendingMessagesPerClient { get; set; } = 250;
public TimeSpan DefaultCommunicationTimeout { get; set; } = TimeSpan.FromSeconds(15);



+ 6
- 0
Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsBuilder.cs 파일 보기

@@ -13,6 +13,12 @@ namespace MQTTnet.Server
return this;
}

public MqttServerOptionsBuilder WithMaxPendingMessagesPerClient(int value)
{
_options.MaxPendingMessagesPerClient = value;
return this;
}

public MqttServerOptionsBuilder WithDefaultCommunicationTimeout(TimeSpan value)
{
_options.DefaultCommunicationTimeout = value;


불러오는 중...
취소
저장