mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 03:24:33 +08:00
Fix breaking changes.
This commit is contained in:
@@ -67,7 +67,9 @@ namespace MQTTnet.Core.Client
|
||||
_packetDispatcher.Reset();
|
||||
IsConnected = true;
|
||||
|
||||
Task.Run(() => ReceivePackets(_cancellationTokenSource.Token), _cancellationTokenSource.Token).Forget();
|
||||
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||
Task.Run(() => ReceivePackets(_cancellationTokenSource.Token), _cancellationTokenSource.Token);
|
||||
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||
|
||||
var response = await SendAndReceiveAsync<MqttConnAckPacket>(connectPacket);
|
||||
if (response.ConnectReturnCode != MqttConnectReturnCode.ConnectionAccepted)
|
||||
@@ -77,7 +79,9 @@ namespace MQTTnet.Core.Client
|
||||
|
||||
if (_options.KeepAlivePeriod != TimeSpan.Zero)
|
||||
{
|
||||
Task.Run(() => SendKeepAliveMessagesAsync(_cancellationTokenSource.Token), _cancellationTokenSource.Token).Forget();
|
||||
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||
Task.Run(() => SendKeepAliveMessagesAsync(_cancellationTokenSource.Token), _cancellationTokenSource.Token);
|
||||
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||
}
|
||||
|
||||
Connected?.Invoke(this, EventArgs.Empty);
|
||||
@@ -350,7 +354,9 @@ namespace MQTTnet.Core.Client
|
||||
var mqttPacket = await _adapter.ReceivePacketAsync(TimeSpan.Zero);
|
||||
MqttTrace.Information(nameof(MqttClient), $"Received <<< {mqttPacket}");
|
||||
|
||||
Task.Run(() => ProcessReceivedPacket(mqttPacket), cancellationToken).Forget();
|
||||
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||
Task.Run(() => ProcessReceivedPacket(mqttPacket), cancellationToken);
|
||||
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||
}
|
||||
}
|
||||
catch (MqttCommunicationException exception)
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
|
||||
namespace MQTTnet.Core.Client
|
||||
{
|
||||
public class MqttClientOptions
|
||||
public sealed class MqttClientOptions
|
||||
{
|
||||
public string Server { get; set; }
|
||||
|
||||
public int Port { get; set; } = 1883;
|
||||
public int? Port { get; set; }
|
||||
|
||||
public MqttClientSslOptions SslOptions { get; } = new MqttClientSslOptions();
|
||||
|
||||
public string UserName { get; set; }
|
||||
|
||||
@@ -19,24 +21,5 @@ namespace MQTTnet.Core.Client
|
||||
public TimeSpan KeepAlivePeriod { get; set; } = TimeSpan.FromSeconds(5);
|
||||
|
||||
public TimeSpan DefaultCommunicationTimeout { get; set; } = TimeSpan.FromSeconds(10);
|
||||
|
||||
/// <summary>
|
||||
/// Use SSL to communicate with the MQTT server.
|
||||
/// </summary>
|
||||
/// <remarks>Setting this value to <c>true</c> will also set <see cref="Port"/> to <c>8883</c> if its value was <c>1883</c> (not set).</remarks>
|
||||
public bool UseSSL
|
||||
{
|
||||
get => _useSSL;
|
||||
set
|
||||
{
|
||||
// Automatically set the port to the MQTT SSL port (8883) if it wasn't set already
|
||||
if (value && Port == 1883)
|
||||
Port = 8883;
|
||||
|
||||
_useSSL = value;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _useSSL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace MQTTnet.Core.Client
|
||||
{
|
||||
public static class MqttClientOptionsExtensions
|
||||
{
|
||||
public static int GetPort(this MqttClientOptions options)
|
||||
{
|
||||
if (options == null) throw new ArgumentNullException(nameof(options));
|
||||
|
||||
if (options.Port.HasValue)
|
||||
{
|
||||
return options.Port.Value;
|
||||
}
|
||||
|
||||
return !options.SslOptions.UseSsl ? 1883 : 8883;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MQTTnet.Core.Client
|
||||
{
|
||||
public sealed class MqttClientSslOptions
|
||||
{
|
||||
public bool UseSsl { get; set; }
|
||||
|
||||
public bool CheckCertificateRevocation { get; set; }
|
||||
|
||||
public List<byte[]> Certificates { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user