cloud fix ... ((
This commit is contained in:
@@ -3,14 +3,14 @@
|
|||||||
CloudServer::CloudServer(DispatcherClient * c, const PIByteArray & sname): server(c) {
|
CloudServer::CloudServer(DispatcherClient * c, const PIByteArray & sname): server(c) {
|
||||||
setName(sname.toHex());
|
setName(sname.toHex());
|
||||||
server_uuid = sname;
|
server_uuid = sname;
|
||||||
CONNECTL(c, dataReadedServer, ([this](uint id, PIByteArray & ba) {
|
connects << CONNECTL(c, dataReadedServer, ([this](uint id, PIByteArray & ba) {
|
||||||
last_ping.reset();
|
last_ping.reset();
|
||||||
mutex_clients.lock();
|
mutex_clients.lock();
|
||||||
DispatcherClient * cl = index_clients.value(id, nullptr);
|
DispatcherClient * cl = index_clients.value(id, nullptr);
|
||||||
mutex_clients.unlock();
|
mutex_clients.unlock();
|
||||||
if (cl) cl->sendData(ba);
|
if (cl) cl->sendData(ba);
|
||||||
}));
|
}));
|
||||||
CONNECTL(c, pingReceived, [this]() { last_ping.reset(); });
|
connects << CONNECTL(c, pingReceived, [this]() { last_ping.reset(); });
|
||||||
last_ping.reset();
|
last_ping.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,6 +19,8 @@ CloudServer::~CloudServer() {
|
|||||||
for (auto c: clients) {
|
for (auto c: clients) {
|
||||||
c->close();
|
c->close();
|
||||||
}
|
}
|
||||||
|
for (auto & c: connects)
|
||||||
|
c.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -70,6 +72,11 @@ void CloudServer::close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CloudServer::stop() {
|
||||||
|
server->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CloudServer::printStatus() {
|
void CloudServer::printStatus() {
|
||||||
PIMutexLocker locker(mutex_clients);
|
PIMutexLocker locker(mutex_clients);
|
||||||
piCout << " "
|
piCout << " "
|
||||||
|
|||||||
@@ -18,8 +18,10 @@ public:
|
|||||||
const DispatcherClient * getConnection() const { return server; }
|
const DispatcherClient * getConnection() const { return server; }
|
||||||
double lastPing();
|
double lastPing();
|
||||||
void close();
|
void close();
|
||||||
|
void stop();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
PIVector<PIObject::Connection> connects;
|
||||||
DispatcherClient * server;
|
DispatcherClient * server;
|
||||||
PIVector<DispatcherClient *> clients;
|
PIVector<DispatcherClient *> clients;
|
||||||
PIMap<uint, DispatcherClient *> index_clients;
|
PIMap<uint, DispatcherClient *> index_clients;
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ void DispatcherClient::close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DispatcherClient::stop() {
|
||||||
|
eth->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DispatcherClient::sendConnected(uint client_id) {
|
void DispatcherClient::sendConnected(uint client_id) {
|
||||||
piCoutObj << "sendConnected" << client_id;
|
piCoutObj << "sendConnected" << client_id;
|
||||||
tcp.sendConnected(client_id);
|
tcp.sendConnected(client_id);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public:
|
|||||||
~DispatcherClient();
|
~DispatcherClient();
|
||||||
void start();
|
void start();
|
||||||
void close();
|
void close();
|
||||||
|
void stop();
|
||||||
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);
|
||||||
|
|||||||
@@ -196,15 +196,13 @@ void DispatcherServer::disconnectClient(DispatcherClient * client) {
|
|||||||
CloudServer * cs = index_c_servers.value(client, nullptr);
|
CloudServer * cs = index_c_servers.value(client, nullptr);
|
||||||
if (cs) {
|
if (cs) {
|
||||||
piCoutObj << "remove Server" << client->clientId();
|
piCoutObj << "remove Server" << client->clientId();
|
||||||
|
cs->stop();
|
||||||
PIVector<DispatcherClient *> cscv = cs->getClients();
|
PIVector<DispatcherClient *> cscv = cs->getClients();
|
||||||
for (auto csc: cscv) {
|
for (auto csc: cscv) {
|
||||||
clients.removeAll(csc);
|
clients.removeAll(csc);
|
||||||
index_c_clients.remove(csc);
|
index_c_clients.remove(csc);
|
||||||
cs->removeClient(csc);
|
|
||||||
csc->close();
|
|
||||||
if (!rmrf_clients.contains(csc)) rmrf_clients << csc;
|
if (!rmrf_clients.contains(csc)) rmrf_clients << csc;
|
||||||
}
|
}
|
||||||
cs->close();
|
|
||||||
c_servers.remove(cs->serverUUID());
|
c_servers.remove(cs->serverUUID());
|
||||||
index_c_servers.remove(client);
|
index_c_servers.remove(client);
|
||||||
delete cs;
|
delete cs;
|
||||||
|
|||||||
Reference in New Issue
Block a user