Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed Jun 28, 2019
2 parents f66da92 + 8916df8 commit 1847af1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Build/MQTTnet.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker) and supports v3.1.0, v3.1.1 and v5.0.0 of the MQTT protocol.</description>
<releaseNotes>
* [Core] Fixed wrong versions in nuget packages.
* [Server] The TCP address is now reused when starting which should prevent "port in used" error when restarting.
* [Server] Moved new socket options to TCP options to avoid incompatibility with Linux hosts.
</releaseNotes>
<copyright>Copyright Christian Kratky 2016-2019</copyright>
<tags>MQTT Message Queue Telemetry Transport MQTTClient MQTTServer Server MQTTBroker Broker NETStandard IoT InternetOfThings Messaging Hardware Arduino Sensor Actuator M2M ESP Smart Home Cities Automation Xamarin</tags>
Expand Down
13 changes: 11 additions & 2 deletions Source/MQTTnet/Implementations/MqttTcpServerListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,17 @@ public bool Start(bool treatErrorsAsWarning, CancellationToken cancellationToken
_logger.Info($"Starting TCP listener for {_localEndPoint} TLS={_tlsCertificate != null}.");

_socket = new Socket(_addressFamily, SocketType.Stream, ProtocolType.Tcp);
_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true);

if (_options.ReuseAddress)
{
_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
}

if (_options.NoDelay)
{
_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true);
}

_socket.Bind(_localEndPoint);
_socket.Listen(_options.ConnectionBacklog);

Expand Down
5 changes: 5 additions & 0 deletions Source/MQTTnet/Server/MqttServerTcpEndpointBaseOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ public abstract class MqttServerTcpEndpointBaseOptions
public IPAddress BoundInterNetworkAddress { get; set; } = IPAddress.Any;

public IPAddress BoundInterNetworkV6Address { get; set; } = IPAddress.IPv6Any;

/// <summary>
/// This requires admin permissions on Linux.
/// </summary>
public bool ReuseAddress { get; set; }
}
}

0 comments on commit 1847af1

Please sign in to comment.