Skip to content

Linter Appeasement #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions Source/HiveMQtt/Client/HiveMQClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,14 @@ public async Task<PublishResult> PublishAsync(MQTT5PublishMessage message, Cance
throw new HiveMQttClientException("Retained messages are not supported by the broker");
}

if (message.QoS.HasValue && this.Connection.ConnectionProperties.MaximumQoS.HasValue &&
if (message.QoS.HasValue && this.Connection?.ConnectionProperties?.MaximumQoS.HasValue == true &&
(ushort)message.QoS.Value > this.Connection.ConnectionProperties.MaximumQoS.Value)
{
if (this.Connection == null)
{
throw new HiveMQttClientException("Connection is not available");
}

Logger.Debug($"Reducing message QoS from {message.QoS} to broker enforced maximum of {this.Connection.ConnectionProperties.MaximumQoS}");
message.QoS = (QualityOfService)this.Connection.ConnectionProperties.MaximumQoS.Value;
}
Expand All @@ -247,12 +252,17 @@ public async Task<PublishResult> PublishAsync(MQTT5PublishMessage message, Cance
var publishPacket = new PublishPacket(message, 0);
Logger.Trace($"Queuing QoS 0 publish packet for send: {publishPacket.GetType().Name}");

this.Connection.OutgoingPublishQueue.Enqueue(publishPacket);
this.Connection?.OutgoingPublishQueue.Enqueue(publishPacket);
return new PublishResult(publishPacket.Message);
}
else if (message.QoS == QualityOfService.AtLeastOnceDelivery)
{
// QoS 1: Acknowledged Delivery
if (this.Connection == null)
{
throw new HiveMQttClientException("Connection is not available");
}

var packetIdentifier = await this.Connection.PacketIDManager.GetAvailablePacketIDAsync().ConfigureAwait(false);
var publishPacket = new PublishPacket(message, (ushort)packetIdentifier);
PubAckPacket pubAckPacket;
Expand All @@ -278,6 +288,11 @@ public async Task<PublishResult> PublishAsync(MQTT5PublishMessage message, Cance
else if (message.QoS == QualityOfService.ExactlyOnceDelivery)
{
// QoS 2: Assured Delivery
if (this.Connection == null)
{
throw new HiveMQttClientException("Connection is not available");
}

var packetIdentifier = await this.Connection.PacketIDManager.GetAvailablePacketIDAsync().ConfigureAwait(false);
var publishPacket = new PublishPacket(message, (ushort)packetIdentifier);
var publishResult = new PublishResult(publishPacket.Message);
Expand Down Expand Up @@ -406,6 +421,11 @@ public async Task<SubscribeResult> SubscribeAsync(SubscribeOptions options)
// Fire the corresponding event
this.BeforeSubscribeEventLauncher(options);

if (this.Connection == null)
{
throw new HiveMQttClientException("Connection is not available");
}

// FIXME: We should only ever have one subscribe in flight at any time (for now)
// Construct the MQTT Subscribe packet
var packetIdentifier = await this.Connection.PacketIDManager.GetAvailablePacketIDAsync().ConfigureAwait(false);
Expand Down
1 change: 1 addition & 0 deletions Source/HiveMQtt/Client/HiveMQClientEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ internal virtual void OnMessageReceivedEventLauncher(PublishPacket packet)
}
}, TaskScheduler.Default);
}

messageHandled = true;
}

Expand Down
Loading