Move socket event handler inside FlipperConnectionManagerImpl

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
This commit is contained in:
Lorenzo Blasa
2023-06-20 07:55:25 -07:00
committed by Facebook GitHub Bot
parent 35e2dd2e17
commit 4379317258
2 changed files with 30 additions and 25 deletions

View File

@@ -53,30 +53,7 @@ class ConnectionEvents {
if (impl == nullptr) { if (impl == nullptr) {
return; return;
} }
switch (event) { impl->handleSocketEvent(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;
}
} }
} }
@@ -114,7 +91,34 @@ void FlipperConnectionManagerImpl::setCertificateProvider(
std::shared_ptr<FlipperCertificateProvider> std::shared_ptr<FlipperCertificateProvider>
FlipperConnectionManagerImpl::getCertificateProvider() { FlipperConnectionManagerImpl::getCertificateProvider() {
return certProvider_; 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() { void FlipperConnectionManagerImpl::start() {
if (!FlipperSocketProvider::hasProvider()) { if (!FlipperSocketProvider::hasProvider()) {

View File

@@ -82,6 +82,7 @@ class FlipperConnectionManagerImpl : public FlipperConnectionManager {
void startSync(); void startSync();
bool connectAndExchangeCertificate(); bool connectAndExchangeCertificate();
bool connectSecurely(); bool connectSecurely();
void handleSocketEvent(const SocketEvent event);
bool isCertificateExchangeNeeded(); bool isCertificateExchangeNeeded();
void requestSignedCertificate(); void requestSignedCertificate();
void processSignedCertificateResponse( void processSignedCertificateResponse(