diff --git a/libs/cloud/picloudserver.cpp b/libs/cloud/picloudserver.cpp index 2e0949eb..220473a1 100644 --- a/libs/cloud/picloudserver.cpp +++ b/libs/cloud/picloudserver.cpp @@ -29,7 +29,9 @@ PICloudServer::PICloudServer(const PIString & path, PIIODevice::DeviceMode mode) CONNECTL(ð, connected, [this](){opened_ = true; piCoutObj << "connected" << ð tcp.sendStart();}); CONNECTL(ð, disconnected, [this](bool){ piCoutObj << "disconnected" << ð - eth.stop(); + for (auto c : clients_) { + delete c; + } opened_ = false; ping_timer.stop(false); piMSleep(100); @@ -88,6 +90,7 @@ bool PICloudServer::closeDevice() { for (auto c : clients_) { delete c; } + clients_.clear(); return true; } @@ -220,6 +223,7 @@ void PICloudServer::_readed(PIByteArray & ba) { Client * oc = index_clients.value(id, nullptr); clients_mutex.unlock(); if (oc) { + oc->stopAndWait(); //oc->is_connected = false; //oc->close(); delete oc; @@ -245,8 +249,7 @@ void PICloudServer::clientDeleted(PIObject * o) { clients_mutex.lock(); clients_.removeOne(c); auto it = index_clients.makeIterator(); - while (it.hasNext()) { - it.next(); + while (it.next()) { if (it.value() == c) { index_clients.remove(it.key()); break; diff --git a/main_picloud_test.cpp b/main_picloud_test.cpp index dbaea6ba..c94886b0 100644 --- a/main_picloud_test.cpp +++ b/main_picloud_test.cpp @@ -52,10 +52,9 @@ int main(int argc, char * argv[]) { })); CONNECTL(cl, closed, ([&clients, cl](){ piCout << "[Server] client closed ..." << cl; - cl->stop(); + cl->stopAndWait(); clients.removeAll(cl); piCout << "[Server] client closed ok" << cl; - //cl->deleteLater(); })); cl->startThreadedRead(); }));