some fix for PICloudServer

This commit is contained in:
Бычков Андрей
2022-11-08 15:25:27 +03:00
parent 897f03f3d0
commit b17510218b
2 changed files with 7 additions and 5 deletions

View File

@@ -29,7 +29,9 @@ PICloudServer::PICloudServer(const PIString & path, PIIODevice::DeviceMode mode)
CONNECTL(&eth, connected, [this](){opened_ = true; piCoutObj << "connected" << &eth; tcp.sendStart();});
CONNECTL(&eth, disconnected, [this](bool){
piCoutObj << "disconnected" << &eth;
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;

View File

@@ -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();
}));