Additional performance improvements

This commit is contained in:
Christian Kratky
2017-09-09 23:53:42 +02:00
parent 4a6790f0aa
commit 76151deba0
18 changed files with 100 additions and 103 deletions
@@ -62,7 +62,7 @@ namespace MQTTnet.Core.Server
{
try
{
await _gate.WaitOneAsync();
await _gate.WaitOneAsync().ConfigureAwait(false);
if (cancellationToken.IsCancellationRequested)
{
return;
@@ -81,7 +81,7 @@ namespace MQTTnet.Core.Server
foreach (var publishPacket in pendingPublishPackets)
{
await TrySendPendingPublishPacketAsync(publishPacket);
await TrySendPendingPublishPacketAsync(publishPacket).ConfigureAwait(false);
}
}
catch (Exception e)
@@ -105,7 +105,7 @@ namespace MQTTnet.Core.Server
}
publishPacketContext.PublishPacket.Dup = publishPacketContext.SendTries > 0;
await _adapter.SendPacketAsync(publishPacketContext.PublishPacket, _options.DefaultCommunicationTimeout);
await _adapter.SendPacketAsync(publishPacketContext.PublishPacket, _options.DefaultCommunicationTimeout).ConfigureAwait(false);
publishPacketContext.IsSent = true;
}
+2 -2
View File
@@ -54,8 +54,8 @@ namespace MQTTnet.Core.Server
_messageQueue.Start(adapter);
while (!_cancellationTokenSource.IsCancellationRequested)
{
var packet = await adapter.ReceivePacketAsync(TimeSpan.Zero);
await HandleIncomingPacketAsync(packet);
var packet = await adapter.ReceivePacketAsync(TimeSpan.Zero).ConfigureAwait(false);
await HandleIncomingPacketAsync(packet).ConfigureAwait(false);
}
}
catch (MqttCommunicationException)
@@ -28,7 +28,7 @@ namespace MQTTnet.Core.Server
{
try
{
var connectPacket = await eventArgs.ClientAdapter.ReceivePacketAsync(_options.DefaultCommunicationTimeout) as MqttConnectPacket;
var connectPacket = await eventArgs.ClientAdapter.ReceivePacketAsync(_options.DefaultCommunicationTimeout).ConfigureAwait(false) as MqttConnectPacket;
if (connectPacket == null)
{
throw new MqttProtocolViolationException("The first packet from a client must be a 'CONNECT' packet [MQTT-3.1.0-1].");
@@ -43,7 +43,7 @@ namespace MQTTnet.Core.Server
await eventArgs.ClientAdapter.SendPacketAsync(new MqttConnAckPacket
{
ConnectReturnCode = connectReturnCode
}, _options.DefaultCommunicationTimeout);
}, _options.DefaultCommunicationTimeout).ConfigureAwait(false);
return;
}
@@ -54,9 +54,9 @@ namespace MQTTnet.Core.Server
{
ConnectReturnCode = connectReturnCode,
IsSessionPresent = clientSession.IsExistingSession
}, _options.DefaultCommunicationTimeout);
}, _options.DefaultCommunicationTimeout).ConfigureAwait(false);
await clientSession.Session.RunAsync(eventArgs.Identifier, connectPacket.WillMessage, eventArgs.ClientAdapter);
await clientSession.Session.RunAsync(eventArgs.Identifier, connectPacket.WillMessage, eventArgs.ClientAdapter).ConfigureAwait(false);
}
catch (Exception exception)
{
@@ -64,7 +64,7 @@ namespace MQTTnet.Core.Server
}
finally
{
await eventArgs.ClientAdapter.DisconnectAsync();
await eventArgs.ClientAdapter.DisconnectAsync().ConfigureAwait(false);
}
}