This PR was originally written as a code cleanup to follow up on review comments in earlier PRs. Several other commits were added afterward building on the earlier changes, and necessary for the bugfixes in https://github.com/bitcoin/bitcoin/pull/32345, which resolves issues #123, #176 and #182.
Summary of changes:
- The commit “Improve IPC client disconnected exceptions” is the only external change, and lets clients detect when they are trying to call a remote method after a connection has been closed. This change is used by bitcoin/bitcoin#32345 commit “ipc: Handle bitcoin-wallet disconnection” to fix #123.
- The commits “Prevent EventLoop async cleanup thread early exit during shutdown” and “Prevent IPC server crash if disconnected during IPC call” fix issues reported in #182.
- New tests are added in other commits to verify these fixes, covering different kinds of disconnections.
- The change to detect disconnects also relies on an earlier “Add ProxyContext EventLoop* member” commit.
- An “Add EventLoopRef RAII class” commit simplifies a recent bugfix in #159 and also relies on the earlier “EventLoop* member” commit.
- The “Remove DestructorCatcher and AsyncCallable” commit follows up on #144 (comment).
- The “Add clang thread safety annotations” commit follows up on #129 (comment).