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