Skip to content

Commit

Permalink
Restore old properties to avoid breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed May 19, 2024
1 parent 1d1a4c7 commit 7fad14c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
13 changes: 1 addition & 12 deletions Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,20 +376,9 @@ public MqttClientOptionsBuilder WithTcpServer(string host, int? port = null, Add

_tcpOptions = new MqttClientTcpOptions();

_port = port;

// The value 0 will be updated when building the options.
// This a backward compatibility feature.

if (IPAddress.TryParse(host, out var ipAddress))
{
_remoteEndPoint = new IPEndPoint(ipAddress, port ?? 0);
}
else
{
_remoteEndPoint = new DnsEndPoint(host, port ?? 0, addressFamily);
}

_remoteEndPoint = new DnsEndPoint(host, port ?? 0, addressFamily);
_port = port;

return this;
Expand Down
7 changes: 7 additions & 0 deletions Source/MQTTnet/Client/Options/MqttClientTcpOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Net;
using System.Net.Sockets;

Expand All @@ -20,6 +21,12 @@ public sealed class MqttClientTcpOptions : IMqttClientChannelOptions
/// </summary>
public bool? DualMode { get; set; }

[Obsolete("Use RemoteEndpoint or MqttClientOptionsBuilder instead.")]
public int? Port { get; set; }

[Obsolete("Use RemoteEndpoint or MqttClientOptionsBuilder instead.")]
public string Server { get; set; }

public LingerOption LingerState { get; set; } = new LingerOption(true, 0);

/// <summary>
Expand Down
24 changes: 24 additions & 0 deletions Source/MQTTnet/Implementations/MqttTcpChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using MQTTnet.Client;
using MQTTnet.Exceptions;
using MQTTnet.Internal;
using MQTTnet.Protocol;

namespace MQTTnet.Implementations
{
Expand Down Expand Up @@ -98,6 +99,29 @@ public async Task ConnectAsync(CancellationToken cancellationToken)
socket.DualMode = _tcpOptions.DualMode.Value;
}

// This block is only for backward compatibility.
if (_tcpOptions.RemoteEndpoint == null && !string.IsNullOrEmpty(_tcpOptions.Server))

Check warning on line 103 in Source/MQTTnet/Implementations/MqttTcpChannel.cs

View workflow job for this annotation

GitHub Actions / build

'MqttClientTcpOptions.Server' is obsolete: 'Use RemoteEndpoint or MqttClientOptionsBuilder instead.'

Check warning on line 103 in Source/MQTTnet/Implementations/MqttTcpChannel.cs

View workflow job for this annotation

GitHub Actions / build

'MqttClientTcpOptions.Server' is obsolete: 'Use RemoteEndpoint or MqttClientOptionsBuilder instead.'

Check warning on line 103 in Source/MQTTnet/Implementations/MqttTcpChannel.cs

View workflow job for this annotation

GitHub Actions / build

'MqttClientTcpOptions.Server' is obsolete: 'Use RemoteEndpoint or MqttClientOptionsBuilder instead.'

Check warning on line 103 in Source/MQTTnet/Implementations/MqttTcpChannel.cs

View workflow job for this annotation

GitHub Actions / build

'MqttClientTcpOptions.Server' is obsolete: 'Use RemoteEndpoint or MqttClientOptionsBuilder instead.'
{
int port;
if (_tcpOptions.Port.HasValue)

Check warning on line 106 in Source/MQTTnet/Implementations/MqttTcpChannel.cs

View workflow job for this annotation

GitHub Actions / build

'MqttClientTcpOptions.Port' is obsolete: 'Use RemoteEndpoint or MqttClientOptionsBuilder instead.'

Check warning on line 106 in Source/MQTTnet/Implementations/MqttTcpChannel.cs

View workflow job for this annotation

GitHub Actions / build

'MqttClientTcpOptions.Port' is obsolete: 'Use RemoteEndpoint or MqttClientOptionsBuilder instead.'

Check warning on line 106 in Source/MQTTnet/Implementations/MqttTcpChannel.cs

View workflow job for this annotation

GitHub Actions / build

'MqttClientTcpOptions.Port' is obsolete: 'Use RemoteEndpoint or MqttClientOptionsBuilder instead.'

Check warning on line 106 in Source/MQTTnet/Implementations/MqttTcpChannel.cs

View workflow job for this annotation

GitHub Actions / build

'MqttClientTcpOptions.Port' is obsolete: 'Use RemoteEndpoint or MqttClientOptionsBuilder instead.'
{
port = _tcpOptions.Port.Value;

Check warning on line 108 in Source/MQTTnet/Implementations/MqttTcpChannel.cs

View workflow job for this annotation

GitHub Actions / build

'MqttClientTcpOptions.Port' is obsolete: 'Use RemoteEndpoint or MqttClientOptionsBuilder instead.'

Check warning on line 108 in Source/MQTTnet/Implementations/MqttTcpChannel.cs

View workflow job for this annotation

GitHub Actions / build

'MqttClientTcpOptions.Port' is obsolete: 'Use RemoteEndpoint or MqttClientOptionsBuilder instead.'

Check warning on line 108 in Source/MQTTnet/Implementations/MqttTcpChannel.cs

View workflow job for this annotation

GitHub Actions / build

'MqttClientTcpOptions.Port' is obsolete: 'Use RemoteEndpoint or MqttClientOptionsBuilder instead.'

Check warning on line 108 in Source/MQTTnet/Implementations/MqttTcpChannel.cs

View workflow job for this annotation

GitHub Actions / build

'MqttClientTcpOptions.Port' is obsolete: 'Use RemoteEndpoint or MqttClientOptionsBuilder instead.'
}
else
{
if (_tcpOptions.TlsOptions?.UseTls == true)
{
port = MqttPorts.Secure;
}
else
{
port = MqttPorts.Default;
}
}

_tcpOptions.RemoteEndpoint = new DnsEndPoint(_tcpOptions.Server, port, AddressFamily.Unspecified);

Check warning on line 122 in Source/MQTTnet/Implementations/MqttTcpChannel.cs

View workflow job for this annotation

GitHub Actions / build

'MqttClientTcpOptions.Server' is obsolete: 'Use RemoteEndpoint or MqttClientOptionsBuilder instead.'

Check warning on line 122 in Source/MQTTnet/Implementations/MqttTcpChannel.cs

View workflow job for this annotation

GitHub Actions / build

'MqttClientTcpOptions.Server' is obsolete: 'Use RemoteEndpoint or MqttClientOptionsBuilder instead.'

Check warning on line 122 in Source/MQTTnet/Implementations/MqttTcpChannel.cs

View workflow job for this annotation

GitHub Actions / build

'MqttClientTcpOptions.Server' is obsolete: 'Use RemoteEndpoint or MqttClientOptionsBuilder instead.'

Check warning on line 122 in Source/MQTTnet/Implementations/MqttTcpChannel.cs

View workflow job for this annotation

GitHub Actions / build

'MqttClientTcpOptions.Server' is obsolete: 'Use RemoteEndpoint or MqttClientOptionsBuilder instead.'
}

await socket.ConnectAsync(_tcpOptions.RemoteEndpoint, cancellationToken).ConfigureAwait(false);

cancellationToken.ThrowIfCancellationRequested();
Expand Down

0 comments on commit 7fad14c

Please sign in to comment.