mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-04-12 03:57:27 +00:00
fix: make subscriberIds private & check for add failure
This commit is contained in:
parent
9be5823956
commit
edc10a9c2a
1 changed files with 5 additions and 7 deletions
|
|
@ -31,7 +31,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
|||
/// <remarks>
|
||||
/// Unsoliciited feedback from a device in a messenger will ONLY be sent to devices in this subscription list. When a client disconnects, it's ID will be removed from the collection.
|
||||
/// </remarks>
|
||||
protected HashSet<string> SubscriberIds = new HashSet<string>();
|
||||
private readonly HashSet<string> subscriberIds = new HashSet<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Lock object for thread-safe access to SubscriberIds
|
||||
|
|
@ -200,13 +200,11 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
|||
|
||||
lock (_subscriberLock)
|
||||
{
|
||||
if (SubscriberIds.Contains(clientId))
|
||||
if (!subscriberIds.Add(clientId))
|
||||
{
|
||||
this.LogVerbose("Client {clientId} already subscribed", clientId);
|
||||
return;
|
||||
}
|
||||
|
||||
SubscriberIds.Add(clientId);
|
||||
}
|
||||
|
||||
this.LogDebug("Client {clientId} subscribed", clientId);
|
||||
|
|
@ -227,10 +225,10 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
|||
bool wasSubscribed;
|
||||
lock (_subscriberLock)
|
||||
{
|
||||
wasSubscribed = SubscriberIds.Contains(clientId);
|
||||
wasSubscribed = subscriberIds.Contains(clientId);
|
||||
if (wasSubscribed)
|
||||
{
|
||||
SubscriberIds.Remove(clientId);
|
||||
subscriberIds.Remove(clientId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -332,7 +330,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
|||
List<string> subscriberSnapshot;
|
||||
lock (_subscriberLock)
|
||||
{
|
||||
subscriberSnapshot = new List<string>(SubscriberIds);
|
||||
subscriberSnapshot = new List<string>(subscriberIds);
|
||||
}
|
||||
|
||||
foreach (var client in subscriberSnapshot)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue