Skip to content

Commit 394c89a

Browse files
authored
Extended AfterDisconnect Support (#93)
1 parent fe7d12f commit 394c89a

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

Examples/Reconnect/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,6 @@
135135
}
136136
}
137137

138-
Console.WriteLine("Disconnecting gracefully...");
138+
Console.WriteLine("Disconnecting gracefully and waiting 5 seconds...");
139139
await client.DisconnectAsync().ConfigureAwait(false);
140+
await Task.Delay(5000).ConfigureAwait(false);

Examples/Reconnect/Reconnect.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<!-- Update the version to match -->
1616
<ItemGroup>
17-
<PackageReference Include="HiveMQtt" Version="0.4.0" />
17+
<PackageReference Include="HiveMQtt" Version="0.4.1" />
1818
</ItemGroup>
1919

2020
</Project>

Source/HiveMQtt/Client/HiveMQClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ public async Task<bool> DisconnectAsync(DisconnectOptions? options = null)
158158
this.OnDisconnectSent -= eventHandler;
159159
}
160160

161-
this.connectState = ConnectState.Disconnected;
162-
163161
// Close the socket
164162
this.CloseSocket();
165163

164+
this.connectState = ConnectState.Disconnected;
165+
166166
// Clear the send queue
167167
this.sendQueue.Clear();
168168
return true;

Source/HiveMQtt/Client/HiveMQClientSocket.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ internal async Task<bool> ConnectSocketAsync()
137137

138138
internal bool CloseSocket(bool? shutdownPipeline = true)
139139
{
140-
this.cancellationSource.Cancel();
141-
142140
if (shutdownPipeline == true)
143141
{
144142
// Shutdown the pipeline
@@ -150,6 +148,8 @@ internal bool CloseSocket(bool? shutdownPipeline = true)
150148
this.socket?.Shutdown(SocketShutdown.Both);
151149
this.socket?.Close();
152150

151+
this.cancellationSource.Cancel();
152+
153153
return true;
154154
}
155155
}

Source/HiveMQtt/Client/HiveMQClientTrafficProcessor.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ private Task<bool> TrafficInflowProcessorAsync(CancellationToken cancellationTok
353353
switch (this.connectState)
354354
{
355355
case ConnectState.Disconnecting:
356+
case ConnectState.Disconnected:
356357
// This disconnect was either user or broker initiated.
357358
// Launch the AfterDisconnect event with a clean disconnect set to true.
358359
this.AfterDisconnectEventLauncher(true);
@@ -364,8 +365,6 @@ private Task<bool> TrafficInflowProcessorAsync(CancellationToken cancellationTok
364365
break;
365366
case ConnectState.Connecting:
366367
break;
367-
case ConnectState.Disconnected:
368-
break;
369368
default:
370369
break;
371370
}

0 commit comments

Comments
 (0)