PICloudServer don't delete clients
This commit is contained in:
@@ -36,9 +36,14 @@ PICloudServer::PICloudServer(const PIString & path, PIIODevice::DeviceMode mode)
|
||||
CONNECTL(ð, disconnected, [this](bool){
|
||||
if (is_deleted) return;
|
||||
//piCoutObj << "disconnected" << ð
|
||||
clients_mutex.lock();
|
||||
removed_clients_.append(clients_);
|
||||
for (auto c : clients_) {
|
||||
delete c;
|
||||
c->is_connected = false;
|
||||
c->close();
|
||||
}
|
||||
clients_.clear();
|
||||
clients_mutex.unlock();
|
||||
opened_ = false;
|
||||
ping_timer.stop();
|
||||
piMSleep(100);
|
||||
@@ -54,8 +59,12 @@ PICloudServer::~PICloudServer() {
|
||||
is_deleted = true;
|
||||
stop();
|
||||
close();
|
||||
//piCout << "wait";
|
||||
waitThreadedReadFinished();
|
||||
//piCout << "wait";
|
||||
for (auto c : removed_clients_) {
|
||||
delete c;
|
||||
}
|
||||
removed_clients_.clear();
|
||||
//piCoutObj << "~PICloudServer done" << this;
|
||||
}
|
||||
|
||||
@@ -92,10 +101,11 @@ bool PICloudServer::closeDevice() {
|
||||
eth.stopAndWait();
|
||||
ping_timer.stop();
|
||||
eth.close();
|
||||
for (auto c : clients_) {
|
||||
delete c;
|
||||
}
|
||||
clients_mutex.lock();
|
||||
removed_clients_.append(clients_);
|
||||
clients_.clear();
|
||||
index_clients.clear();
|
||||
clients_mutex.unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -233,12 +243,15 @@ void PICloudServer::_readed(PIByteArray & ba) {
|
||||
uint id = tcp.parseDisconnect(ba);
|
||||
//piCoutObj << "remove Client" << id;
|
||||
clients_mutex.lock();
|
||||
Client * oc = index_clients.value(id, nullptr);
|
||||
Client * oc = index_clients.take(id, nullptr);
|
||||
clients_.removeOne(oc);
|
||||
clients_mutex.unlock();
|
||||
if (oc) {
|
||||
oc->stopAndWait();
|
||||
oc->is_connected = false;
|
||||
delete oc;
|
||||
oc->close();
|
||||
removed_clients_ << oc;
|
||||
//delete oc;
|
||||
}
|
||||
} break;
|
||||
case PICloud::TCP::Data: {
|
||||
@@ -260,6 +273,7 @@ void PICloudServer::clientDeleted(PIObject * o) {
|
||||
//piCoutObj << "clientDeleted" << c;
|
||||
clients_mutex.lock();
|
||||
clients_.removeOne(c);
|
||||
removed_clients_.removeAll(c);
|
||||
auto it = index_clients.makeIterator();
|
||||
while (it.next()) {
|
||||
if (it.value() == c) {
|
||||
|
||||
Reference in New Issue
Block a user