Skip to content
Browse files

listener: Fix race condition in channel subscriptions

  • Loading branch information...
1 parent 1f00cdc commit ab063024d96ff350faa4eb370dca6ac671ea43e8 @hbons committed
Showing with 10 additions and 5 deletions.
  1. +10 −5 SparkleLib/SparkleListenerBase.cs
View
15 SparkleLib/SparkleListenerBase.cs
@@ -96,10 +96,11 @@ public void Announce (SparkleAnnouncement announcement)
public void AlsoListenTo (string channel)
{
- if (!this.channels.Contains (channel) && IsConnected) {
- SparkleLogger.LogInfo ("Listener", "Subscribing to channel " + channel + " on " + Server);
-
+ if (!this.channels.Contains (channel))
this.channels.Add (channel);
+
+ if (IsConnected) {
+ SparkleLogger.LogInfo ("Listener", "Subscribing to channel " + channel + " on " + Server);
AlsoListenToInternal (channel);
}
}
@@ -114,6 +115,11 @@ public void Reconnect ()
public void OnConnected ()
{
+ foreach (string channel in this.channels.GetRange (0, this.channels.Count)) {
+ SparkleLogger.LogInfo ("Listener", "Subscribing to channel " + channel + " on " + Server);
+ AlsoListenToInternal (channel);
+ }
+
SparkleLogger.LogInfo ("Listener", "Listening for announcements on " + Server);
Connected ();
@@ -139,8 +145,7 @@ public void OnDisconnected (string message)
public void OnAnnouncement (SparkleAnnouncement announcement)
{
- SparkleLogger.LogInfo ("Listener",
- "Got message " + announcement.Message + " from " +
+ SparkleLogger.LogInfo ("Listener", "Got message " + announcement.Message + " from " +
announcement.FolderIdentifier + " on " + Server);
if (IsRecentAnnouncement (announcement)) {

0 comments on commit ab06302

Please sign in to comment.
Something went wrong with that request. Please try again.