partial fix for #608 - when a new TCP API connection arrives, close old one completely

This commit is contained in:
Kevin Hester
2020-12-31 09:52:08 +08:00
parent de37a0c31e
commit cdf416cb73
4 changed files with 39 additions and 15 deletions

View File

@@ -21,11 +21,17 @@ void PhoneAPI::init()
observe(&service.fromNumChanged);
}
PhoneAPI::~PhoneAPI() {
close();
}
void PhoneAPI::close() {
unobserve();
state = STATE_SEND_NOTHING;
bool oldConnected = isConnected;
isConnected = false;
onConnectionChanged(isConnected);
if(oldConnected != isConnected)
onConnectionChanged(isConnected);
}
void PhoneAPI::checkConnectionTimeout()

View File

@@ -55,12 +55,15 @@ class PhoneAPI
public:
PhoneAPI();
/// Destructor - calls close()
virtual ~PhoneAPI();
/// Do late init that can't happen at constructor time
virtual void init();
// Call this when the client drops the connection, resets the state to STATE_SEND_NOTHING
// Unregisters our observer
void close();
// Unregisters our observer. A closed connection **can** be reopened by calling init again.
virtual void close();
/**
* Handle a ToRadio protobuf