mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 11:45:43 +08:00
improved api surface of mqttserver and fixed unittests
This commit is contained in:
@@ -11,8 +11,7 @@ namespace MQTTnet.Core.Server
|
||||
event EventHandler<MqttClientConnectedEventArgs> ClientConnected;
|
||||
event EventHandler<MqttClientDisconnectedEventArgs> ClientDisconnected;
|
||||
|
||||
IList<ConnectedMqttClient> GetConnectedClients();
|
||||
void InjectClient(IMqttCommunicationAdapter adapter);
|
||||
IReadOnlyList<ConnectedMqttClient> GetConnectedClients();
|
||||
void Publish(MqttApplicationMessage applicationMessage);
|
||||
|
||||
Task StartAsync();
|
||||
|
||||
@@ -157,12 +157,12 @@ namespace MQTTnet.Core.Server
|
||||
}
|
||||
else if (packet is MqttDisconnectPacket || packet is MqttConnectPacket)
|
||||
{
|
||||
_cancellationTokenSource.Cancel();
|
||||
Stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
MqttTrace.Warning(nameof(MqttClientSession), "Client '{0}': Received not supported packet ({1}). Closing connection.", ClientId, packet);
|
||||
_cancellationTokenSource.Cancel();
|
||||
Stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace MQTTnet.Core.Server
|
||||
}
|
||||
}
|
||||
|
||||
public IList<ConnectedMqttClient> GetConnectedClients()
|
||||
public IReadOnlyList<ConnectedMqttClient> GetConnectedClients()
|
||||
{
|
||||
lock (_clientSessions)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace MQTTnet.Core.Server
|
||||
_clientSessionsManager.ClientDisconnected += OnClientDisconnected;
|
||||
}
|
||||
|
||||
public IList<ConnectedMqttClient> GetConnectedClients()
|
||||
public IReadOnlyList<ConnectedMqttClient> GetConnectedClients()
|
||||
{
|
||||
return _clientSessionsManager.GetConnectedClients();
|
||||
}
|
||||
@@ -43,14 +43,6 @@ namespace MQTTnet.Core.Server
|
||||
_clientSessionsManager.DispatchPublishPacket(null, applicationMessage.ToPublishPacket());
|
||||
}
|
||||
|
||||
public void InjectClient(IMqttCommunicationAdapter adapter)
|
||||
{
|
||||
if (adapter == null) throw new ArgumentNullException(nameof(adapter));
|
||||
if (_cancellationTokenSource == null) throw new InvalidOperationException("The MQTT server is not started.");
|
||||
|
||||
OnClientAccepted(adapter);
|
||||
}
|
||||
|
||||
public async Task StartAsync()
|
||||
{
|
||||
if (_cancellationTokenSource != null) throw new InvalidOperationException("The MQTT server is already started.");
|
||||
|
||||
Reference in New Issue
Block a user