improved api surface of mqttserver and fixed unittests

This commit is contained in:
JanEggers
2017-10-02 22:55:56 +02:00
parent 3079ad37ce
commit 1d78d675f7
9 changed files with 90 additions and 181 deletions
+1 -2
View File
@@ -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();
+2 -2
View File
@@ -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)
{
+1 -9
View File
@@ -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.");