Handle socket not open error individually

Summary:
It's expected that whenever not connected to a desktop, or when the sonar desktop app isn't running, we'll get
errors connecting. Isolate these so we can treat all other exceptions properly.

Reviewed By: passy

Differential Revision: D9333323

fbshipit-source-id: c9853ca84d1a04827ebf7bae0fe87859ca6110d1
This commit is contained in:
John Knox
2018-08-15 06:03:07 -07:00
committed by Facebook Github Bot
parent 292cb4107b
commit dfcfa9f7fa

View File

@@ -20,6 +20,7 @@
#include <fstream>
#include <iostream>
#include <thread>
#include <folly/io/async/AsyncSocketException.h>
#include "CertificateUtils.h"
#ifdef __ANDROID__
@@ -116,14 +117,25 @@ void SonarWebSocketImpl::startSync() {
SONAR_LOG("Already connected");
return;
}
auto connect = sonarState_->start("Connect to desktop");
try {
if (isCertificateExchangeNeeded()) {
doCertificateExchange();
return;
}
connectSecurely();
} catch (const std::exception&) {
connect->complete();
} catch (const folly::AsyncSocketException& e) {
if (e.getType() == folly::AsyncSocketException::NOT_OPEN) {
// The expected code path when flipper desktop is not running.
} else {
SONAR_LOG(e.what());
failedConnectionAttempts_++;
}
reconnect();
} catch (const std::exception& e) {
SONAR_LOG(e.what());
failedConnectionAttempts_++;
reconnect();
}