try to fix cloud again

This commit is contained in:
2024-06-01 22:27:39 +03:00
parent af4b718053
commit d46b5e008a
8 changed files with 24 additions and 18 deletions

View File

@@ -7,8 +7,8 @@ CloudServer::CloudServer(DispatcherClient * c, const PIByteArray & sname): serve
last_ping.reset();
mutex_clients.lock();
DispatcherClient * cl = index_clients.value(id, nullptr);
if (cl) cl->sendData(ba);
mutex_clients.unlock();
if (cl) cl->sendData(ba);
}));
connects << CONNECTL(c, pingReceived, [this]() { last_ping.reset(); });
last_ping.reset();

View File

@@ -22,6 +22,7 @@ void DispatcherClient::start() {
DispatcherClient::~DispatcherClient() {
PIMutexLocker send_lock(mutex_send);
piDeleteSafety(eth);
}
@@ -43,28 +44,32 @@ void DispatcherClient::stop() {
void DispatcherClient::sendConnected(uint client_id) {
piCoutObj << "sendConnected" << client_id;
PIMutexLocker send_lock(mutex_send);
tcp.sendConnected(client_id);
}
void DispatcherClient::sendDisconnected(uint client_id) {
piCoutObj << "sendDisconnected" << client_id;
PIMutexLocker send_lock(mutex_send);
tcp.sendDisconnected(client_id);
}
void DispatcherClient::sendData(const PIByteArray & data) {
if (tcp.role() == PICloud::TCP::Client)
if (tcp.role() == PICloud::TCP::Client) {
PIMutexLocker send_lock(mutex_send);
tcp.sendData(data);
else
} else
piCoutObj << "error sendData, invalid role";
}
void DispatcherClient::sendDataToClient(const PIByteArray & data, uint client_id) {
if (tcp.role() == PICloud::TCP::Server)
if (tcp.role() == PICloud::TCP::Server) {
PIMutexLocker send_lock(mutex_send);
tcp.sendData(data, client_id);
else
} else
piCoutObj << "error sendDataToClient, invalid role";
}

View File

@@ -39,6 +39,7 @@ private:
PIEthernet * eth;
PIStreamPacker streampacker;
PICloud::TCP tcp;
PIMutex mutex_send;
uint client_id;
};

View File

@@ -59,7 +59,7 @@ void DispatcherServer::cleanClients() {
if (!index_c_servers.contains(c) && !index_c_clients.contains(c)) {
if (!rm_clients.contains(c)) rm_clients << c;
} else
rm_clients.removeAll(c);
rm_clients.remove(c);
}
auto ss = c_servers.values();
for (auto c: ss) {
@@ -76,7 +76,7 @@ void DispatcherServer::cleanClients() {
index_c_clients.remove(csc);
c->removeClient(csc);
csc->close();
if (!rmrf_clients.contains(csc)) rmrf_clients << csc;
rmrf_clients << csc;
}
c_servers.remove(c->serverUUID());
index_c_servers.remove(c->getConnection());
@@ -86,7 +86,7 @@ void DispatcherServer::cleanClients() {
}
for (auto c: rm_clients) {
if (clients.contains(c)) {
if (!rmrf_clients.contains(c)) rmrf_clients << c;
rmrf_clients << c;
}
}
for (auto c: rmrf_clients) {
@@ -96,7 +96,7 @@ void DispatcherServer::cleanClients() {
index_c_servers.remove(c);
}
index_c_clients.remove(c);
rm_clients.removeAll(c);
rm_clients.remove(c);
}
}
@@ -201,7 +201,7 @@ void DispatcherServer::disconnectClient(DispatcherClient * client) {
}
piCoutObj << "remove ..." << client->clientId();
clients.removeAll(client);
rm_clients.removeAll(client);
rm_clients.remove(client);
CloudServer * cs = index_c_servers.value(client, nullptr);
if (cs) {
piCoutObj << "remove Server" << client->clientId();
@@ -210,11 +210,11 @@ void DispatcherServer::disconnectClient(DispatcherClient * client) {
for (auto csc: cscv) {
clients.removeAll(csc);
index_c_clients.remove(csc);
if (!rmrf_clients.contains(csc)) rmrf_clients << csc;
rmrf_clients << csc;
}
c_servers.remove(cs->serverUUID());
index_c_servers.remove(client);
if (!rmrf_servers.contains(cs)) rmrf_servers << cs;
rmrf_servers << cs;
}
CloudServer * cc = index_c_clients.value(client, nullptr);
if (cc) {
@@ -223,7 +223,7 @@ void DispatcherServer::disconnectClient(DispatcherClient * client) {
index_c_clients.remove(client);
}
// client->close();
if (!rmrf_clients.contains(client)) rmrf_clients << client;
rmrf_clients << client;
piCoutObj << "remove done" << client->clientId();
}

View File

@@ -34,8 +34,8 @@ private:
PIMap<PIByteArray, CloudServer *> c_servers;
PIMap<const DispatcherClient *, CloudServer *> index_c_servers;
PIMap<const DispatcherClient *, CloudServer *> index_c_clients;
PIVector<DispatcherClient *> rm_clients;
PIVector<DispatcherClient *> rmrf_clients;
PISet<DispatcherClient *> rm_clients;
PISet<DispatcherClient *> rmrf_clients;
PIVector<CloudServer *> rmrf_servers;
PITimer timeout_timer;
PIMutex map_mutex;