Skip to content

Commit ed6c95a

Browse files
authored
Linter Appeasement (#241)
1 parent 516c011 commit ed6c95a

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Source/HiveMQtt/Client/HiveMQClient.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,14 @@ public async Task<PublishResult> PublishAsync(MQTT5PublishMessage message, Cance
234234
throw new HiveMQttClientException("Retained messages are not supported by the broker");
235235
}
236236

237-
if (message.QoS.HasValue && this.Connection.ConnectionProperties.MaximumQoS.HasValue &&
237+
if (message.QoS.HasValue && this.Connection?.ConnectionProperties?.MaximumQoS.HasValue == true &&
238238
(ushort)message.QoS.Value > this.Connection.ConnectionProperties.MaximumQoS.Value)
239239
{
240+
if (this.Connection == null)
241+
{
242+
throw new HiveMQttClientException("Connection is not available");
243+
}
244+
240245
Logger.Debug($"Reducing message QoS from {message.QoS} to broker enforced maximum of {this.Connection.ConnectionProperties.MaximumQoS}");
241246
message.QoS = (QualityOfService)this.Connection.ConnectionProperties.MaximumQoS.Value;
242247
}
@@ -247,12 +252,17 @@ public async Task<PublishResult> PublishAsync(MQTT5PublishMessage message, Cance
247252
var publishPacket = new PublishPacket(message, 0);
248253
Logger.Trace($"Queuing QoS 0 publish packet for send: {publishPacket.GetType().Name}");
249254

250-
this.Connection.OutgoingPublishQueue.Enqueue(publishPacket);
255+
this.Connection?.OutgoingPublishQueue.Enqueue(publishPacket);
251256
return new PublishResult(publishPacket.Message);
252257
}
253258
else if (message.QoS == QualityOfService.AtLeastOnceDelivery)
254259
{
255260
// QoS 1: Acknowledged Delivery
261+
if (this.Connection == null)
262+
{
263+
throw new HiveMQttClientException("Connection is not available");
264+
}
265+
256266
var packetIdentifier = await this.Connection.PacketIDManager.GetAvailablePacketIDAsync().ConfigureAwait(false);
257267
var publishPacket = new PublishPacket(message, (ushort)packetIdentifier);
258268
PubAckPacket pubAckPacket;
@@ -278,6 +288,11 @@ public async Task<PublishResult> PublishAsync(MQTT5PublishMessage message, Cance
278288
else if (message.QoS == QualityOfService.ExactlyOnceDelivery)
279289
{
280290
// QoS 2: Assured Delivery
291+
if (this.Connection == null)
292+
{
293+
throw new HiveMQttClientException("Connection is not available");
294+
}
295+
281296
var packetIdentifier = await this.Connection.PacketIDManager.GetAvailablePacketIDAsync().ConfigureAwait(false);
282297
var publishPacket = new PublishPacket(message, (ushort)packetIdentifier);
283298
var publishResult = new PublishResult(publishPacket.Message);
@@ -406,6 +421,11 @@ public async Task<SubscribeResult> SubscribeAsync(SubscribeOptions options)
406421
// Fire the corresponding event
407422
this.BeforeSubscribeEventLauncher(options);
408423

424+
if (this.Connection == null)
425+
{
426+
throw new HiveMQttClientException("Connection is not available");
427+
}
428+
409429
// FIXME: We should only ever have one subscribe in flight at any time (for now)
410430
// Construct the MQTT Subscribe packet
411431
var packetIdentifier = await this.Connection.PacketIDManager.GetAvailablePacketIDAsync().ConfigureAwait(false);

Source/HiveMQtt/Client/HiveMQClientEvents.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ internal virtual void OnMessageReceivedEventLauncher(PublishPacket packet)
262262
}
263263
}, TaskScheduler.Default);
264264
}
265+
265266
messageHandled = true;
266267
}
267268

0 commit comments

Comments
 (0)