Clear event handler on deallocation

Summary:
It's just bad that we give a naked pointer of the connection manager to other instances. If the connection manager gets deallocated, the instances keeping a pointer to it are doomed to crash.

This change creates a wrapper on top of the pointer that can be freely shared. On deallocation, the shared wrapper gets invalidated.

Reviewed By: timur-valiev

Differential Revision: D30398466

fbshipit-source-id: 8f228e7fbaebc0ea28921409de071b58bbb69f1e
This commit is contained in:
Lorenzo Blasa
2021-08-19 04:41:35 -07:00
committed by Facebook GitHub Bot
parent ebe5e7f9ff
commit 8e2a839f9d
3 changed files with 49 additions and 29 deletions

View File

@@ -35,11 +35,11 @@ rsocket::Payload toRSocketPayload(folly::dynamic data);
class RSocketEvents : public rsocket::RSocketConnectionEvents {
private:
const SocketEventHandler& handler_;
const SocketEventHandler handler_;
public:
RSocketEvents(const SocketEventHandler& eventHandler)
: handler_(eventHandler) {}
RSocketEvents(const SocketEventHandler eventHandler)
: handler_(std::move(eventHandler)) {}
void onConnected() {
handler_(SocketEvent::OPEN);