cloud fix ... ((

This commit is contained in:
2024-03-25 21:17:05 +03:00
parent 02a9bfb76f
commit 0d585cfebf
5 changed files with 24 additions and 11 deletions

View File

@@ -3,14 +3,14 @@
CloudServer::CloudServer(DispatcherClient * c, const PIByteArray & sname): server(c) {
setName(sname.toHex());
server_uuid = sname;
CONNECTL(c, dataReadedServer, ([this](uint id, PIByteArray & ba) {
last_ping.reset();
mutex_clients.lock();
DispatcherClient * cl = index_clients.value(id, nullptr);
mutex_clients.unlock();
if (cl) cl->sendData(ba);
}));
CONNECTL(c, pingReceived, [this]() { last_ping.reset(); });
connects << CONNECTL(c, dataReadedServer, ([this](uint id, PIByteArray & ba) {
last_ping.reset();
mutex_clients.lock();
DispatcherClient * cl = index_clients.value(id, nullptr);
mutex_clients.unlock();
if (cl) cl->sendData(ba);
}));
connects << CONNECTL(c, pingReceived, [this]() { last_ping.reset(); });
last_ping.reset();
}
@@ -19,6 +19,8 @@ CloudServer::~CloudServer() {
for (auto c: clients) {
c->close();
}
for (auto & c: connects)
c.disconnect();
}
@@ -70,6 +72,11 @@ void CloudServer::close() {
}
void CloudServer::stop() {
server->stop();
}
void CloudServer::printStatus() {
PIMutexLocker locker(mutex_clients);
piCout << " "

View File

@@ -18,8 +18,10 @@ public:
const DispatcherClient * getConnection() const { return server; }
double lastPing();
void close();
void stop();
private:
PIVector<PIObject::Connection> connects;
DispatcherClient * server;
PIVector<DispatcherClient *> clients;
PIMap<uint, DispatcherClient *> index_clients;

View File

@@ -36,6 +36,11 @@ void DispatcherClient::close() {
}
void DispatcherClient::stop() {
eth->stop();
}
void DispatcherClient::sendConnected(uint client_id) {
piCoutObj << "sendConnected" << client_id;
tcp.sendConnected(client_id);

View File

@@ -14,6 +14,7 @@ public:
~DispatcherClient();
void start();
void close();
void stop();
void sendConnected(uint client_id);
void sendDisconnected(uint client_id);
void sendData(const PIByteArray & data);

View File

@@ -196,15 +196,13 @@ void DispatcherServer::disconnectClient(DispatcherClient * client) {
CloudServer * cs = index_c_servers.value(client, nullptr);
if (cs) {
piCoutObj << "remove Server" << client->clientId();
cs->stop();
PIVector<DispatcherClient *> cscv = cs->getClients();
for (auto csc: cscv) {
clients.removeAll(csc);
index_c_clients.remove(csc);
cs->removeClient(csc);
csc->close();
if (!rmrf_clients.contains(csc)) rmrf_clients << csc;
}
cs->close();
c_servers.remove(cs->serverUUID());
index_c_servers.remove(client);
delete cs;