mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 11:45:43 +08:00
Refactor server socket management for Linux support.
This commit is contained in:
@@ -4,8 +4,6 @@ namespace MQTTnet.Server
|
||||
{
|
||||
public interface IMqttServerOptions
|
||||
{
|
||||
int ConnectionBacklog { get; }
|
||||
|
||||
bool EnablePersistentSessions { get; }
|
||||
|
||||
int MaxPendingMessagesPerClient { get; }
|
||||
@@ -18,8 +16,8 @@ namespace MQTTnet.Server
|
||||
Action<MqttApplicationMessageInterceptorContext> ApplicationMessageInterceptor { get; }
|
||||
Action<MqttClientMessageQueueInterceptorContext> ClientMessageQueueInterceptor { get; set; }
|
||||
|
||||
MqttServerDefaultEndpointOptions DefaultEndpointOptions { get; }
|
||||
MqttServerTlsEndpointOptions TlsEndpointOptions { get; }
|
||||
MqttServerTcpEndpointOptions DefaultEndpointOptions { get; }
|
||||
MqttServerTlsTcpEndpointOptions TlsEndpointOptions { get; }
|
||||
|
||||
IMqttServerStorage Storage { get; }
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
using System.Net;
|
||||
|
||||
namespace MQTTnet.Server
|
||||
{
|
||||
public class MqttServerDefaultEndpointOptions
|
||||
{
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
|
||||
public int? Port { get; set; }
|
||||
|
||||
public IPAddress BoundIPAddress { get; set; } = IPAddress.Any;
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,12 @@ namespace MQTTnet.Server
|
||||
{
|
||||
public class MqttServerOptions : IMqttServerOptions
|
||||
{
|
||||
public MqttServerDefaultEndpointOptions DefaultEndpointOptions { get; } = new MqttServerDefaultEndpointOptions();
|
||||
public MqttServerTcpEndpointOptions DefaultEndpointOptions { get; } = new MqttServerTcpEndpointOptions();
|
||||
|
||||
public MqttServerTlsEndpointOptions TlsEndpointOptions { get; } = new MqttServerTlsEndpointOptions();
|
||||
public MqttServerTlsTcpEndpointOptions TlsEndpointOptions { get; } = new MqttServerTlsTcpEndpointOptions();
|
||||
|
||||
public bool EnablePersistentSessions { get; set; }
|
||||
|
||||
public int ConnectionBacklog { get; set; } = 10;
|
||||
|
||||
public int MaxPendingMessagesPerClient { get; set; } = 250;
|
||||
public MqttPendingMessagesOverflowStrategy PendingMessagesOverflowStrategy { get; set; } = MqttPendingMessagesOverflowStrategy.DropOldestQueuedMessage;
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ namespace MQTTnet.Server
|
||||
|
||||
public MqttServerOptionsBuilder WithConnectionBacklog(int value)
|
||||
{
|
||||
_options.ConnectionBacklog = value;
|
||||
_options.DefaultEndpointOptions.ConnectionBacklog = value;
|
||||
_options.TlsEndpointOptions.ConnectionBacklog = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -31,7 +32,7 @@ namespace MQTTnet.Server
|
||||
return this;
|
||||
}
|
||||
|
||||
public MqttServerOptionsBuilder WithDefaultEndpointPort(int? value)
|
||||
public MqttServerOptionsBuilder WithDefaultEndpointPort(int value)
|
||||
{
|
||||
_options.DefaultEndpointOptions.Port = value;
|
||||
return this;
|
||||
@@ -39,10 +40,16 @@ namespace MQTTnet.Server
|
||||
|
||||
public MqttServerOptionsBuilder WithDefaultEndpointBoundIPAddress(IPAddress value)
|
||||
{
|
||||
_options.DefaultEndpointOptions.BoundIPAddress = value ?? IPAddress.Any;
|
||||
_options.DefaultEndpointOptions.BoundInterNetworkAddress = value ?? IPAddress.Any;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public MqttServerOptionsBuilder WithDefaultEndpointBoundIPV6Address(IPAddress value)
|
||||
{
|
||||
_options.DefaultEndpointOptions.BoundInterNetworkV6Address = value ?? IPAddress.Any;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MqttServerOptionsBuilder WithoutDefaultEndpoint()
|
||||
{
|
||||
_options.DefaultEndpointOptions.IsEnabled = false;
|
||||
@@ -55,7 +62,7 @@ namespace MQTTnet.Server
|
||||
return this;
|
||||
}
|
||||
|
||||
public MqttServerOptionsBuilder WithEncryptedEndpointPort(int? value)
|
||||
public MqttServerOptionsBuilder WithEncryptedEndpointPort(int value)
|
||||
{
|
||||
_options.TlsEndpointOptions.Port = value;
|
||||
return this;
|
||||
@@ -63,7 +70,7 @@ namespace MQTTnet.Server
|
||||
|
||||
public MqttServerOptionsBuilder WithEncryptedEndpointBoundIPAddress(IPAddress value)
|
||||
{
|
||||
_options.TlsEndpointOptions.BoundIPAddress = value;
|
||||
_options.TlsEndpointOptions.BoundInterNetworkAddress = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace MQTTnet.Server
|
||||
{
|
||||
public static class MqttServerOptionsExtensions
|
||||
{
|
||||
public static int GetTlsEndpointPort(this IMqttServerOptions options)
|
||||
{
|
||||
if (options == null) throw new ArgumentNullException(nameof(options));
|
||||
|
||||
if (!options.TlsEndpointOptions.Port.HasValue)
|
||||
{
|
||||
return 8883;
|
||||
}
|
||||
|
||||
return options.TlsEndpointOptions.Port.Value;
|
||||
}
|
||||
|
||||
public static int GetDefaultEndpointPort(this IMqttServerOptions options)
|
||||
{
|
||||
if (options == null) throw new ArgumentNullException(nameof(options));
|
||||
|
||||
if (!options.DefaultEndpointOptions.Port.HasValue)
|
||||
{
|
||||
return 1883;
|
||||
}
|
||||
|
||||
return options.DefaultEndpointOptions.Port.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Net;
|
||||
|
||||
namespace MQTTnet.Server
|
||||
{
|
||||
public abstract class MqttServerTcpEndpointBaseOptions
|
||||
{
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
public int Port { get; set; }
|
||||
|
||||
public int ConnectionBacklog { get; set; } = 10;
|
||||
|
||||
public IPAddress BoundInterNetworkAddress { get; set; } = IPAddress.Any;
|
||||
|
||||
public IPAddress BoundInterNetworkV6Address { get; set; } = IPAddress.IPv6Any;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace MQTTnet.Server
|
||||
{
|
||||
public class MqttServerTcpEndpointOptions : MqttServerTcpEndpointBaseOptions
|
||||
{
|
||||
public MqttServerTcpEndpointOptions()
|
||||
{
|
||||
IsEnabled = true;
|
||||
Port = 1883;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using System.Net;
|
||||
|
||||
namespace MQTTnet.Server
|
||||
{
|
||||
public class MqttServerTlsEndpointOptions
|
||||
{
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
public int? Port { get; set; }
|
||||
|
||||
public byte[] Certificate { get; set; }
|
||||
|
||||
public IPAddress BoundIPAddress { get; set; } = IPAddress.Any;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace MQTTnet.Server
|
||||
{
|
||||
public class MqttServerTlsTcpEndpointOptions : MqttServerTcpEndpointBaseOptions
|
||||
{
|
||||
public MqttServerTlsTcpEndpointOptions()
|
||||
{
|
||||
Port = 8883;
|
||||
}
|
||||
|
||||
public byte[] Certificate { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user