common: Make InternalPeer (more) thread-safe
authorManuel Nickschas <sputnick@quassel-irc.org>
Wed, 30 May 2018 20:01:50 +0000 (22:01 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 6 Jun 2018 19:12:17 +0000 (21:12 +0200)
commit047f7a5c2429d44adf0102ee25c7fb254f80ea69
treea320fbe6c1661314a872039052b367592dc58e75
parentc068c516487c4699d5dbefe449d62c9ebad29684
common: Make InternalPeer (more) thread-safe

The two internal peers used by a mono client live in different
threads. Previously, they each stored a pointer to their counterpart
to be able to send protocol messages wrapped in an event.
While this has never been observed in the wild, this may cause subtle
lifetime issues if one of the sides goes away before the other.

While currently, as the two peers are at least created in the same
thread (and thus, setting the mutual pointer should not cause issues),
this will change in the near future, since the mono core is slated
to move into its own thread.

Rather than trying to deal with this ourselves, let Qt do the work.
Instead of storing a pointer and sending events, use signal/slot
connections to transfer the messages between the peers. Qt will
ensure that this happens in a thread-safe manner, and that connections
are killed if one of the peers is destroyed.
src/common/internalpeer.cpp
src/common/internalpeer.h
src/common/protocol.h