Skip to content
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

Engine: protect calls to events delegate to avoid concurrency issues #202

Open
wants to merge 1 commit into
base: master
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
11 changes: 6 additions & 5 deletions src/Engine/Config/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ public object this[string key] {

// only raise event if the value changed
if (!value.Equals(oldValue)) {
if (Changed != null) {
Changed(this, new ConfigChangedEventArgs(key, value));
var handler = Changed;
if (handler != null) {
handler(this, new ConfigChangedEventArgs(key, value));
}
}
}
Expand Down Expand Up @@ -703,9 +704,9 @@ public void Remove(string key)
m_IniDocument.Sections[key].Remove(key);
}
#endif

if (Changed != null) {
Changed(this, new ConfigChangedEventArgs(key, null));
var handler = Changed;
if (handler != null) {
handler(this, new ConfigChangedEventArgs(key, null));
}
}

Expand Down
27 changes: 16 additions & 11 deletions src/Engine/Protocols/ProtocolManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ protected virtual void OnConnected(EventArgs e)

Session.UpdateNetworkStatus();

if (Connected != null) {
Connected(this, e);
var handler = Connected;
if (handler != null) {
handler(this, e);
}

var hooks = new HookRunner("engine", "protocol-manager", "on-connected");
Expand Down Expand Up @@ -245,9 +246,10 @@ protected virtual void OnDisconnected(EventArgs e)
_PresenceStatus = PresenceStatus.Offline;

Session.UpdateNetworkStatus();

if (Disconnected != null) {
Disconnected(this, e);

var handler = Disconnected;
if (handler != null) {
handler(this, e);
}

var hooks = new HookRunner("engine", "protocol-manager", "on-disconnected");
Expand All @@ -267,8 +269,9 @@ protected virtual void OnMessageSent(MessageEventArgs e)
{
Trace.Call(e);

if (MessageSent != null) {
MessageSent(this, e);
var handler = MessageSent;
if (handler != null) {
handler(this, e);
}

var hooks = new HookRunner("engine", "protocol-manager", "on-message-sent");
Expand All @@ -294,8 +297,9 @@ protected virtual void OnMessageReceived(MessageEventArgs e)
{
Trace.Call(e);

if (MessageReceived != null) {
MessageReceived(this, e);
var handler = MessageReceived;
if (handler != null) {
handler(this, e);
}

var hooks = new HookRunner("engine", "protocol-manager", "on-message-received");
Expand All @@ -321,8 +325,9 @@ protected virtual void OnPresenceStatusChanged(PresenceStatusChangedEventArgs e)
{
Trace.Call(e);

if (PresenceStatusChanged != null) {
PresenceStatusChanged(this, e);
var handler = PresenceStatusChanged;
if (handler != null) {
handler(this, e);
}

var hooks = new HookRunner("engine", "protocol-manager", "on-presence-status-changed");
Expand Down
15 changes: 9 additions & 6 deletions src/Engine/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1979,8 +1979,9 @@ void UpdateNewsFeed()

protected virtual void OnGroupChatPersonAdded(GroupChatPersonAddedEventArgs e)
{
if (GroupChatPersonAdded != null) {
GroupChatPersonAdded(this, e);
var handler = GroupChatPersonAdded;
if (handler != null) {
handler(this, e);
}

var pm = e.GroupChat.ProtocolManager;
Expand Down Expand Up @@ -2029,8 +2030,9 @@ protected virtual void OnGroupChatPersonRemoved(GroupChatPersonRemovedEventArgs

protected virtual void OnGroupChatPersonUpdated(GroupChatPersonUpdatedEventArgs e)
{
if (GroupChatPersonUpdated != null) {
GroupChatPersonUpdated(this, e);
var handler = GroupChatPersonUpdated;
if (handler != null) {
handler(this, e);
}

var pm = e.GroupChat.ProtocolManager;
Expand All @@ -2055,8 +2057,9 @@ protected virtual void OnGroupChatPersonUpdated(GroupChatPersonUpdatedEventArgs

protected virtual void OnEventMessage(EventMessageEventArgs e)
{
if (EventMessage != null) {
EventMessage(this, e);
var handler = EventMessage;
if (handler != null) {
handler(this, e);
}

var pm = e.Chat.ProtocolManager;
Expand Down