mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-24 14:43:04 +08:00
Refactor logging. Remove TCP adapter from HTTP host if disabled.
This commit is contained in:
@@ -504,20 +504,16 @@ namespace MQTTnet.Client
|
||||
|
||||
private void StartReceivingPackets(CancellationToken cancellationToken)
|
||||
{
|
||||
_packetReceiverTask = Task.Factory.StartNew(
|
||||
_packetReceiverTask = Task.Run(
|
||||
() => ReceivePacketsAsync(cancellationToken),
|
||||
cancellationToken,
|
||||
TaskCreationOptions.LongRunning,
|
||||
TaskScheduler.Current);
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
private void StartSendingKeepAliveMessages(CancellationToken cancellationToken)
|
||||
{
|
||||
_keepAliveMessageSenderTask = Task.Factory.StartNew(
|
||||
_keepAliveMessageSenderTask = Task.Run(
|
||||
() => SendKeepAliveMessagesAsync(cancellationToken),
|
||||
cancellationToken,
|
||||
TaskCreationOptions.LongRunning,
|
||||
TaskScheduler.Current);
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
private void StartProcessReceivedPacketAsync(MqttBasePacket packet, CancellationToken cancellationToken)
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace MQTTnet.Diagnostics
|
||||
{
|
||||
public interface IMqttNetChildLogger
|
||||
{
|
||||
IMqttNetChildLogger CreateChildLogger(string source);
|
||||
IMqttNetChildLogger CreateChildLogger(string source = null);
|
||||
|
||||
void Verbose(string message, params object[] parameters);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace MQTTnet.Diagnostics
|
||||
{
|
||||
event EventHandler<MqttNetLogMessagePublishedEventArgs> LogMessagePublished;
|
||||
|
||||
IMqttNetChildLogger CreateChildLogger(string source);
|
||||
IMqttNetChildLogger CreateChildLogger(string source = null);
|
||||
|
||||
void Publish(MqttNetLogLevel logLevel, string source, string message, object[] parameters, Exception exception);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace MQTTnet.Diagnostics
|
||||
|
||||
public event EventHandler<MqttNetLogMessagePublishedEventArgs> LogMessagePublished;
|
||||
|
||||
public IMqttNetChildLogger CreateChildLogger(string source)
|
||||
public IMqttNetChildLogger CreateChildLogger(string source = null)
|
||||
{
|
||||
return new MqttNetChildLogger(this, source);
|
||||
}
|
||||
|
||||
@@ -45,11 +45,8 @@ namespace MQTTnet.Implementations
|
||||
_defaultEndpointSocket.Bind(new IPEndPoint(options.DefaultEndpointOptions.BoundIPAddress, options.GetDefaultEndpointPort()));
|
||||
_defaultEndpointSocket.Listen(options.ConnectionBacklog);
|
||||
|
||||
Task.Factory.StartNew(
|
||||
() => AcceptDefaultEndpointConnectionsAsync(_cancellationTokenSource.Token),
|
||||
_cancellationTokenSource.Token,
|
||||
TaskCreationOptions.LongRunning,
|
||||
TaskScheduler.Current);
|
||||
Task.Run(() => AcceptDefaultEndpointConnectionsAsync(_cancellationTokenSource.Token),
|
||||
_cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
if (options.TlsEndpointOptions.IsEnabled)
|
||||
@@ -69,11 +66,9 @@ namespace MQTTnet.Implementations
|
||||
_tlsEndpointSocket.Bind(new IPEndPoint(options.TlsEndpointOptions.BoundIPAddress, options.GetTlsEndpointPort()));
|
||||
_tlsEndpointSocket.Listen(options.ConnectionBacklog);
|
||||
|
||||
Task.Factory.StartNew(
|
||||
() => AcceptTlsEndpointConnectionsAsync(_cancellationTokenSource.Token),
|
||||
_cancellationTokenSource.Token,
|
||||
TaskCreationOptions.LongRunning,
|
||||
TaskScheduler.Current);
|
||||
Task.Run(
|
||||
() => AcceptTlsEndpointConnectionsAsync(_cancellationTokenSource.Token),
|
||||
_cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
return Task.FromResult(0);
|
||||
|
||||
@@ -25,14 +25,14 @@ namespace MQTTnet
|
||||
|
||||
public IManagedMqttClient CreateManagedMqttClient()
|
||||
{
|
||||
return new ManagedMqttClient(CreateMqttClient(), new MqttNetLogger().CreateChildLogger(string.Empty));
|
||||
return new ManagedMqttClient(CreateMqttClient(), new MqttNetLogger().CreateChildLogger());
|
||||
}
|
||||
|
||||
public IManagedMqttClient CreateManagedMqttClient(IMqttNetLogger logger)
|
||||
{
|
||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
return new ManagedMqttClient(CreateMqttClient(), logger.CreateChildLogger(string.Empty));
|
||||
return new ManagedMqttClient(CreateMqttClient(), logger.CreateChildLogger());
|
||||
}
|
||||
|
||||
public IMqttServer CreateMqttServer()
|
||||
@@ -45,7 +45,7 @@ namespace MQTTnet
|
||||
{
|
||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
return CreateMqttServer(new List<IMqttServerAdapter> { new MqttTcpServerAdapter(logger.CreateChildLogger(string.Empty)) }, logger);
|
||||
return CreateMqttServer(new List<IMqttServerAdapter> { new MqttTcpServerAdapter(logger.CreateChildLogger()) }, logger);
|
||||
}
|
||||
|
||||
public IMqttServer CreateMqttServer(IEnumerable<IMqttServerAdapter> adapters, IMqttNetLogger logger)
|
||||
@@ -53,7 +53,7 @@ namespace MQTTnet
|
||||
if (adapters == null) throw new ArgumentNullException(nameof(adapters));
|
||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
return new MqttServer(adapters, logger.CreateChildLogger(string.Empty));
|
||||
return new MqttServer(adapters, logger.CreateChildLogger());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,11 +157,9 @@ namespace MQTTnet.Server
|
||||
|
||||
private void OnClientAccepted(object sender, MqttServerAdapterClientAcceptedEventArgs eventArgs)
|
||||
{
|
||||
eventArgs.SessionTask = Task.Factory.StartNew(
|
||||
eventArgs.SessionTask = Task.Run(
|
||||
() => _clientSessionsManager.RunSessionAsync(eventArgs.Client, _cancellationTokenSource.Token),
|
||||
_cancellationTokenSource.Token,
|
||||
TaskCreationOptions.LongRunning,
|
||||
TaskScheduler.Current);
|
||||
_cancellationTokenSource.Token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user