Compare commits
5 Commits
2db9440a38
...
c7c3852747
| Author | SHA1 | Date | |
|---|---|---|---|
| c7c3852747 | |||
| c18d0c918e | |||
| 9c4fd41eef | |||
| 9173dc936d | |||
| 77c8681b43 |
@@ -7,21 +7,15 @@ CloudServer::CloudServer(DispatcherClient * c, const PIByteArray & sname): serve
|
|||||||
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();
|
|
||||||
if (cl) cl->sendData(ba);
|
if (cl) cl->sendData(ba);
|
||||||
|
mutex_clients.unlock();
|
||||||
}));
|
}));
|
||||||
connects << CONNECTL(c, pingReceived, [this]() { last_ping.reset(); });
|
connects << CONNECTL(c, pingReceived, [this]() { last_ping.reset(); });
|
||||||
last_ping.reset();
|
last_ping.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CloudServer::~CloudServer() {
|
CloudServer::~CloudServer() {}
|
||||||
for (auto c: clients) {
|
|
||||||
c->close();
|
|
||||||
}
|
|
||||||
for (auto & c: connects)
|
|
||||||
c.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PIByteArray CloudServer::serverUUID() const {
|
PIByteArray CloudServer::serverUUID() const {
|
||||||
@@ -73,6 +67,8 @@ void CloudServer::close() {
|
|||||||
|
|
||||||
|
|
||||||
void CloudServer::stop() {
|
void CloudServer::stop() {
|
||||||
|
for (auto c: clients)
|
||||||
|
c->close();
|
||||||
server->stop();
|
server->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,13 +45,13 @@ void DispatcherServer::picoutStatus() {
|
|||||||
|
|
||||||
void DispatcherServer::cleanClients() {
|
void DispatcherServer::cleanClients() {
|
||||||
PIMutexLocker locker(map_mutex);
|
PIMutexLocker locker(map_mutex);
|
||||||
|
for (auto s: rmrf_servers)
|
||||||
|
s->close();
|
||||||
|
piDeleteAllAndClear(rmrf_servers);
|
||||||
for (auto c: rmrf_clients) {
|
for (auto c: rmrf_clients) {
|
||||||
if (!c->isPIObject()) piCout << "ACHTUNG! Non-piobject client!";
|
if (!c->isPIObject()) piCout << "ACHTUNG! Non-piobject client!";
|
||||||
}
|
}
|
||||||
piDeleteAllAndClear(rmrf_clients);
|
piDeleteAllAndClear(rmrf_clients);
|
||||||
for (auto s: rmrf_servers)
|
|
||||||
s->close();
|
|
||||||
piDeleteAllAndClear(rmrf_servers);
|
|
||||||
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_clients << c;
|
if (!rm_clients.contains(c)) rm_clients << c;
|
||||||
@@ -75,7 +75,7 @@ void DispatcherServer::cleanClients() {
|
|||||||
c_servers.remove(c->serverUUID());
|
c_servers.remove(c->serverUUID());
|
||||||
index_c_servers.remove(c->getConnection());
|
index_c_servers.remove(c->getConnection());
|
||||||
rmrf_clients << const_cast<DispatcherClient *>(c->getConnection());
|
rmrf_clients << const_cast<DispatcherClient *>(c->getConnection());
|
||||||
delete c;
|
rmrf_servers << c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto c: rm_clients) {
|
for (auto c: rm_clients) {
|
||||||
@@ -223,10 +223,10 @@ void DispatcherServer::disconnectClient(DispatcherClient * client) {
|
|||||||
|
|
||||||
|
|
||||||
void DispatcherServer::newConnection(PIEthernet * cl) {
|
void DispatcherServer::newConnection(PIEthernet * cl) {
|
||||||
piCout << "DispatcherServer::newConnection" << (void *)cl;
|
// piCout << "DispatcherServer::newConnection" << (void *)cl;
|
||||||
PIMutexLocker locker(map_mutex);
|
PIMutexLocker locker(map_mutex);
|
||||||
if (clients.size() >= max_connections) {
|
if (clients.size() >= max_connections) {
|
||||||
piCout << "DispatcherServer::newConnection overflow" << (void *)cl;
|
// piCout << "DispatcherServer::newConnection overflow" << (void *)cl;
|
||||||
delete cl;
|
delete cl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -237,7 +237,7 @@ void DispatcherServer::newConnection(PIEthernet * cl) {
|
|||||||
CloudServer * cs = c_servers.value(sname, nullptr);
|
CloudServer * cs = c_servers.value(sname, nullptr);
|
||||||
if (cs) {
|
if (cs) {
|
||||||
rm_clients << c;
|
rm_clients << c;
|
||||||
piCoutObj << "dublicate Server ->" << sname.toHex();
|
piCoutObj << "duplicate Server ->" << sname.toHex();
|
||||||
} else {
|
} else {
|
||||||
piCoutObj << "add new Server ->" << sname.toHex();
|
piCoutObj << "add new Server ->" << sname.toHex();
|
||||||
CloudServer * cs = new CloudServer(c, sname);
|
CloudServer * cs = new CloudServer(c, sname);
|
||||||
@@ -262,5 +262,5 @@ void DispatcherServer::newConnection(PIEthernet * cl) {
|
|||||||
// piCoutObj << "add client" << client;
|
// piCoutObj << "add client" << client;
|
||||||
clients.push_back(client);
|
clients.push_back(client);
|
||||||
client->start();
|
client->start();
|
||||||
piCout << "DispatcherServer::newConnection started" << (void *)cl;
|
// piCout << "DispatcherServer::newConnection started" << (void *)cl;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user