Clean shutdown, stability
This commit is contained in:
@@ -516,26 +516,47 @@ private:
|
||||
|
||||
std::mutex activePortMonitorsMutex;
|
||||
std::vector<std::shared_ptr<PortMonitorSubscription>> activePortMonitors;
|
||||
std::atomic<bool> closed = false;
|
||||
|
||||
public:
|
||||
virtual int64_t GetClientId() { return clientId; }
|
||||
|
||||
virtual ~PiPedalSocketHandler()
|
||||
{
|
||||
if (!closed)
|
||||
{
|
||||
FinalCleanup();
|
||||
}
|
||||
}
|
||||
|
||||
bool finalCleanup = false;
|
||||
void FinalCleanup()
|
||||
{
|
||||
if (finalCleanup) return;
|
||||
finalCleanup = true;
|
||||
// avoid use after free.
|
||||
for (int i = 0; i < this->activePortMonitors.size(); ++i)
|
||||
{
|
||||
model.UnmonitorPort(activePortMonitors[i]->subscriptionHandle);
|
||||
}
|
||||
activePortMonitors.resize(0);
|
||||
for (int i = 0; i < this->activeVuSubscriptions.size(); ++i)
|
||||
{
|
||||
model.RemoveVuSubscription(activeVuSubscriptions[i].subscriptionHandle);
|
||||
}
|
||||
activeVuSubscriptions.resize(0);
|
||||
|
||||
model.RemoveNotificationSubsription(this);
|
||||
|
||||
}
|
||||
|
||||
virtual void Close()
|
||||
{
|
||||
if (closed) return;
|
||||
closed = true;
|
||||
|
||||
FinalCleanup(); // do it while we can. &model will no longer be valid after this. ( :-( )
|
||||
|
||||
SocketHandler::Close();
|
||||
}
|
||||
|
||||
@@ -935,6 +956,10 @@ public:
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (closed)
|
||||
{
|
||||
this->SendError(replyTo, "Server has shut down.");
|
||||
}
|
||||
if (message == "setControl")
|
||||
{
|
||||
ControlChangedBody message;
|
||||
|
||||
Reference in New Issue
Block a user