picloud patch
This commit is contained in:
@@ -130,7 +130,7 @@ void PICloudClient::_readed(PIByteArray & ba) {
|
||||
break;
|
||||
case PICloud::TCP::Disconnect:
|
||||
is_connected = false;
|
||||
eth.stop();
|
||||
static_cast<PIThread*>(ð)->stop();
|
||||
eth.close();
|
||||
disconnected();
|
||||
break;
|
||||
|
||||
@@ -26,6 +26,13 @@ PIString DispatcherClient::address() {
|
||||
}
|
||||
|
||||
void DispatcherClient::close() {
|
||||
static_cast<PIThread*>(eth)->stop(false);
|
||||
eth->close();
|
||||
}
|
||||
|
||||
|
||||
void DispatcherClient::terminate() {
|
||||
eth->stop();
|
||||
eth->close();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ public:
|
||||
~DispatcherClient();
|
||||
void start();
|
||||
void close();
|
||||
void terminate();
|
||||
void sendConnected(uint client_id);
|
||||
void sendDisconnected(uint client_id);
|
||||
void sendData(const PIByteArray & data);
|
||||
|
||||
@@ -43,22 +43,26 @@ void DispatcherServer::picoutStatus() {
|
||||
|
||||
|
||||
void DispatcherServer::cleanClients() {
|
||||
PIVector<DispatcherClient*> rm;
|
||||
map_mutex.lock();
|
||||
for (auto c: rmrf_clients) {
|
||||
delete c;
|
||||
}
|
||||
rmrf_clients.clear();
|
||||
for (auto c: clients) {
|
||||
if (!index_c_servers.contains(c) && !index_c_clients.contains(c)) {
|
||||
if (rm_clients.contains(c)) rm << c;
|
||||
else rm_clients << c;
|
||||
if (!rm_clients.contains(c)) rm_clients << c;
|
||||
} else rm_clients.removeAll(c);
|
||||
}
|
||||
for (auto c: rm_clients) {
|
||||
if (clients.contains(c)) rm << c;
|
||||
if (clients.contains(c)) {
|
||||
rmrf_clients << c;
|
||||
}
|
||||
}
|
||||
for (auto c: rmrf_clients) {
|
||||
clients.removeAll(c);
|
||||
rm_clients.removeAll(c);
|
||||
}
|
||||
map_mutex.unlock();
|
||||
for (auto c: rm) {
|
||||
c->close();
|
||||
// c->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +87,12 @@ void DispatcherServer::updateConnectionsTile(TileList * tl) {
|
||||
}
|
||||
tl->content << TileList::Row(c->address() + " " + role, PIScreenTypes::CellFormat());
|
||||
}
|
||||
for (auto c: rm_clients) {
|
||||
tl->content << TileList::Row("[deleting]" + c->address(), PIScreenTypes::CellFormat());
|
||||
}
|
||||
for (auto c: rmrf_clients) {
|
||||
tl->content << TileList::Row("[NULL]" + c->address(), PIScreenTypes::CellFormat());
|
||||
}
|
||||
map_mutex.unlock();
|
||||
}
|
||||
|
||||
@@ -160,35 +170,35 @@ void DispatcherServer::disconnectClient(DispatcherClient *client) {
|
||||
}
|
||||
piCoutObj << "remove client" << client->clientId();
|
||||
map_mutex.lock();
|
||||
clients.removeOne(client);
|
||||
clients.removeAll(client);
|
||||
rm_clients.removeAll(client);
|
||||
CloudServer * cs = index_c_servers.value(client, nullptr);
|
||||
if (cs) {
|
||||
PIVector<DispatcherClient *> cscv = cs->getClients();
|
||||
for(auto csc : cscv) {
|
||||
clients.removeOne(csc);
|
||||
index_c_clients.removeOne(csc);
|
||||
clients.removeAll(csc);
|
||||
index_c_clients.remove(csc);
|
||||
cs->removeClient(csc);
|
||||
csc->close();
|
||||
csc->deleteLater();
|
||||
rmrf_clients << csc;
|
||||
}
|
||||
c_servers.remove(cs->serverUUID());
|
||||
index_c_servers.removeOne(client);
|
||||
index_c_servers.remove(client);
|
||||
delete cs;
|
||||
}
|
||||
CloudServer * cc = index_c_clients.value(client, nullptr);
|
||||
if (cc) {
|
||||
cc->removeClient(client);
|
||||
index_c_clients.removeOne(client);
|
||||
index_c_clients.remove(client);
|
||||
}
|
||||
client->close();
|
||||
rmrf_clients << client;
|
||||
map_mutex.unlock();
|
||||
client->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
void DispatcherServer::newConnection(PIEthernet *cl) {
|
||||
if (clients.size_s() >= max_connections) {
|
||||
cl->close();
|
||||
if (clients.size() >= max_connections) {
|
||||
delete cl;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ private:
|
||||
PIMap<const DispatcherClient *, CloudServer *> index_c_servers;
|
||||
PIMap<const DispatcherClient *, CloudServer *> index_c_clients;
|
||||
PIVector<DispatcherClient*> rm_clients;
|
||||
PIVector<DispatcherClient*> rmrf_clients;
|
||||
PITimer timeout_timer;
|
||||
PIMutex map_mutex;
|
||||
uint client_gid;
|
||||
|
||||
Reference in New Issue
Block a user