some fix for PICloudServer
This commit is contained in:
@@ -29,7 +29,9 @@ PICloudServer::PICloudServer(const PIString & path, PIIODevice::DeviceMode mode)
|
|||||||
CONNECTL(ð, connected, [this](){opened_ = true; piCoutObj << "connected" << ð tcp.sendStart();});
|
CONNECTL(ð, connected, [this](){opened_ = true; piCoutObj << "connected" << ð tcp.sendStart();});
|
||||||
CONNECTL(ð, disconnected, [this](bool){
|
CONNECTL(ð, disconnected, [this](bool){
|
||||||
piCoutObj << "disconnected" << ð
|
piCoutObj << "disconnected" << ð
|
||||||
eth.stop();
|
for (auto c : clients_) {
|
||||||
|
delete c;
|
||||||
|
}
|
||||||
opened_ = false;
|
opened_ = false;
|
||||||
ping_timer.stop(false);
|
ping_timer.stop(false);
|
||||||
piMSleep(100);
|
piMSleep(100);
|
||||||
@@ -88,6 +90,7 @@ bool PICloudServer::closeDevice() {
|
|||||||
for (auto c : clients_) {
|
for (auto c : clients_) {
|
||||||
delete c;
|
delete c;
|
||||||
}
|
}
|
||||||
|
clients_.clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,6 +223,7 @@ void PICloudServer::_readed(PIByteArray & ba) {
|
|||||||
Client * oc = index_clients.value(id, nullptr);
|
Client * oc = index_clients.value(id, nullptr);
|
||||||
clients_mutex.unlock();
|
clients_mutex.unlock();
|
||||||
if (oc) {
|
if (oc) {
|
||||||
|
oc->stopAndWait();
|
||||||
//oc->is_connected = false;
|
//oc->is_connected = false;
|
||||||
//oc->close();
|
//oc->close();
|
||||||
delete oc;
|
delete oc;
|
||||||
@@ -245,8 +249,7 @@ void PICloudServer::clientDeleted(PIObject * o) {
|
|||||||
clients_mutex.lock();
|
clients_mutex.lock();
|
||||||
clients_.removeOne(c);
|
clients_.removeOne(c);
|
||||||
auto it = index_clients.makeIterator();
|
auto it = index_clients.makeIterator();
|
||||||
while (it.hasNext()) {
|
while (it.next()) {
|
||||||
it.next();
|
|
||||||
if (it.value() == c) {
|
if (it.value() == c) {
|
||||||
index_clients.remove(it.key());
|
index_clients.remove(it.key());
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -52,10 +52,9 @@ int main(int argc, char * argv[]) {
|
|||||||
}));
|
}));
|
||||||
CONNECTL(cl, closed, ([&clients, cl](){
|
CONNECTL(cl, closed, ([&clients, cl](){
|
||||||
piCout << "[Server] client closed ..." << cl;
|
piCout << "[Server] client closed ..." << cl;
|
||||||
cl->stop();
|
cl->stopAndWait();
|
||||||
clients.removeAll(cl);
|
clients.removeAll(cl);
|
||||||
piCout << "[Server] client closed ok" << cl;
|
piCout << "[Server] client closed ok" << cl;
|
||||||
//cl->deleteLater();
|
|
||||||
}));
|
}));
|
||||||
cl->startThreadedRead();
|
cl->startThreadedRead();
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user