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:
committed by
Facebook GitHub Bot
parent
35e2dd2e17
commit
4379317258
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user