Skip to content

Commit

Permalink
Move socket event handler inside FlipperConnectionManagerImpl
Browse files Browse the repository at this point in the history
Summary:
The event handler is a friend type that was mutating the connection manager state.

Instead, just forward the event handling to it.

Then state mutation is consolidated inside the connection manager.

Reviewed By: passy

Differential Revision: D46849769

fbshipit-source-id: 594ab32c8e891564afa94e1be6b93b1dfeffe26f
  • Loading branch information
lblasa authored and facebook-github-bot committed Jun 20, 2023
1 parent 35e2dd2 commit 4379317
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
54 changes: 29 additions & 25 deletions xplat/Flipper/FlipperConnectionManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,7 @@ class ConnectionEvents {
if (impl == nullptr) {
return;
}
switch (event) {
case SocketEvent::OPEN:
impl->isConnected_ = true;
if (impl->connectionIsTrusted_) {
impl->callbacks_->onConnected();
}
break;
case SocketEvent::SSL_ERROR:
// SSL errors are not handled as a connection event
// on this handler.
break;
case SocketEvent::CLOSE:
case SocketEvent::ERROR:
if (!impl->isConnected_) {
return;
}
impl->isConnected_ = false;
if (impl->connectionIsTrusted_) {
impl->connectionIsTrusted_ = false;
impl->callbacks_->onDisconnected();
}
impl->reconnect();
break;
}
impl->handleSocketEvent(event);
}
}

Expand Down Expand Up @@ -114,7 +91,34 @@ void FlipperConnectionManagerImpl::setCertificateProvider(
std::shared_ptr<FlipperCertificateProvider>
FlipperConnectionManagerImpl::getCertificateProvider() {
return certProvider_;
};
}

void FlipperConnectionManagerImpl::handleSocketEvent(SocketEvent event) {
switch (event) {
case SocketEvent::OPEN:
isConnected_ = true;
if (connectionIsTrusted_) {
callbacks_->onConnected();
}
break;
case SocketEvent::SSL_ERROR:
// SSL errors are not handled as a connection event
// on this handler.
break;
case SocketEvent::CLOSE:
case SocketEvent::ERROR:
if (!isConnected_) {
return;
}
isConnected_ = false;
if (connectionIsTrusted_) {
connectionIsTrusted_ = false;
callbacks_->onDisconnected();
}
reconnect();
break;
}
}

void FlipperConnectionManagerImpl::start() {
if (!FlipperSocketProvider::hasProvider()) {
Expand Down
1 change: 1 addition & 0 deletions xplat/Flipper/FlipperConnectionManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class FlipperConnectionManagerImpl : public FlipperConnectionManager {
void startSync();
bool connectAndExchangeCertificate();
bool connectSecurely();
void handleSocketEvent(const SocketEvent event);
bool isCertificateExchangeNeeded();
void requestSignedCertificate();
void processSignedCertificateResponse(
Expand Down

0 comments on commit 4379317

Please sign in to comment.