try to fix cloud again
This commit is contained in:
@@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
|||||||
project(PIP)
|
project(PIP)
|
||||||
set(PIP_MAJOR 3)
|
set(PIP_MAJOR 3)
|
||||||
set(PIP_MINOR 19)
|
set(PIP_MINOR 19)
|
||||||
set(PIP_REVISION 2)
|
set(PIP_REVISION 3)
|
||||||
set(PIP_SUFFIX )
|
set(PIP_SUFFIX )
|
||||||
set(PIP_COMPANY SHS)
|
set(PIP_COMPANY SHS)
|
||||||
set(PIP_DOMAIN org.SHS)
|
set(PIP_DOMAIN org.SHS)
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ PICloudServer::PICloudServer(const PIString & path, PIIODevice::DeviceMode mode)
|
|||||||
open_mutex.unlock();
|
open_mutex.unlock();
|
||||||
ping_timer.stop();
|
ping_timer.stop();
|
||||||
});
|
});
|
||||||
CONNECTL(&ping_timer, tickEvent, [this](void *, int) {
|
ping_timer.setSlot([this]() {
|
||||||
if (eth.isConnected()) tcp.sendPing();
|
if (eth.isConnected()) tcp.sendPing();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ private:
|
|||||||
PIVector<Client *> clients_;
|
PIVector<Client *> clients_;
|
||||||
PIVector<Client *> removed_clients_;
|
PIVector<Client *> removed_clients_;
|
||||||
PIMap<uint, Client *> index_clients;
|
PIMap<uint, Client *> index_clients;
|
||||||
PITimer ping_timer;
|
PIThread ping_timer;
|
||||||
PIConditionVariable cvar;
|
PIConditionVariable cvar;
|
||||||
PIMutex open_mutex;
|
PIMutex open_mutex;
|
||||||
mutable PIMutex clients_mutex;
|
mutable PIMutex clients_mutex;
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ 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);
|
||||||
if (cl) cl->sendData(ba);
|
|
||||||
mutex_clients.unlock();
|
mutex_clients.unlock();
|
||||||
|
if (cl) cl->sendData(ba);
|
||||||
}));
|
}));
|
||||||
connects << CONNECTL(c, pingReceived, [this]() { last_ping.reset(); });
|
connects << CONNECTL(c, pingReceived, [this]() { last_ping.reset(); });
|
||||||
last_ping.reset();
|
last_ping.reset();
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ void DispatcherClient::start() {
|
|||||||
|
|
||||||
|
|
||||||
DispatcherClient::~DispatcherClient() {
|
DispatcherClient::~DispatcherClient() {
|
||||||
|
PIMutexLocker send_lock(mutex_send);
|
||||||
piDeleteSafety(eth);
|
piDeleteSafety(eth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,28 +44,32 @@ void DispatcherClient::stop() {
|
|||||||
|
|
||||||
void DispatcherClient::sendConnected(uint client_id) {
|
void DispatcherClient::sendConnected(uint client_id) {
|
||||||
piCoutObj << "sendConnected" << client_id;
|
piCoutObj << "sendConnected" << client_id;
|
||||||
|
PIMutexLocker send_lock(mutex_send);
|
||||||
tcp.sendConnected(client_id);
|
tcp.sendConnected(client_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DispatcherClient::sendDisconnected(uint client_id) {
|
void DispatcherClient::sendDisconnected(uint client_id) {
|
||||||
piCoutObj << "sendDisconnected" << client_id;
|
piCoutObj << "sendDisconnected" << client_id;
|
||||||
|
PIMutexLocker send_lock(mutex_send);
|
||||||
tcp.sendDisconnected(client_id);
|
tcp.sendDisconnected(client_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DispatcherClient::sendData(const PIByteArray & data) {
|
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);
|
tcp.sendData(data);
|
||||||
else
|
} else
|
||||||
piCoutObj << "error sendData, invalid role";
|
piCoutObj << "error sendData, invalid role";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DispatcherClient::sendDataToClient(const PIByteArray & data, uint client_id) {
|
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);
|
tcp.sendData(data, client_id);
|
||||||
else
|
} else
|
||||||
piCoutObj << "error sendDataToClient, invalid role";
|
piCoutObj << "error sendDataToClient, invalid role";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ private:
|
|||||||
PIEthernet * eth;
|
PIEthernet * eth;
|
||||||
PIStreamPacker streampacker;
|
PIStreamPacker streampacker;
|
||||||
PICloud::TCP tcp;
|
PICloud::TCP tcp;
|
||||||
|
PIMutex mutex_send;
|
||||||
uint client_id;
|
uint client_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ void DispatcherServer::cleanClients() {
|
|||||||
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;
|
||||||
} else
|
} else
|
||||||
rm_clients.removeAll(c);
|
rm_clients.remove(c);
|
||||||
}
|
}
|
||||||
auto ss = c_servers.values();
|
auto ss = c_servers.values();
|
||||||
for (auto c: ss) {
|
for (auto c: ss) {
|
||||||
@@ -76,7 +76,7 @@ void DispatcherServer::cleanClients() {
|
|||||||
index_c_clients.remove(csc);
|
index_c_clients.remove(csc);
|
||||||
c->removeClient(csc);
|
c->removeClient(csc);
|
||||||
csc->close();
|
csc->close();
|
||||||
if (!rmrf_clients.contains(csc)) rmrf_clients << csc;
|
rmrf_clients << csc;
|
||||||
}
|
}
|
||||||
c_servers.remove(c->serverUUID());
|
c_servers.remove(c->serverUUID());
|
||||||
index_c_servers.remove(c->getConnection());
|
index_c_servers.remove(c->getConnection());
|
||||||
@@ -86,7 +86,7 @@ void DispatcherServer::cleanClients() {
|
|||||||
}
|
}
|
||||||
for (auto c: rm_clients) {
|
for (auto c: rm_clients) {
|
||||||
if (clients.contains(c)) {
|
if (clients.contains(c)) {
|
||||||
if (!rmrf_clients.contains(c)) rmrf_clients << c;
|
rmrf_clients << c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto c: rmrf_clients) {
|
for (auto c: rmrf_clients) {
|
||||||
@@ -96,7 +96,7 @@ void DispatcherServer::cleanClients() {
|
|||||||
index_c_servers.remove(c);
|
index_c_servers.remove(c);
|
||||||
}
|
}
|
||||||
index_c_clients.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();
|
piCoutObj << "remove ..." << client->clientId();
|
||||||
clients.removeAll(client);
|
clients.removeAll(client);
|
||||||
rm_clients.removeAll(client);
|
rm_clients.remove(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();
|
||||||
@@ -210,11 +210,11 @@ void DispatcherServer::disconnectClient(DispatcherClient * client) {
|
|||||||
for (auto csc: cscv) {
|
for (auto csc: cscv) {
|
||||||
clients.removeAll(csc);
|
clients.removeAll(csc);
|
||||||
index_c_clients.remove(csc);
|
index_c_clients.remove(csc);
|
||||||
if (!rmrf_clients.contains(csc)) rmrf_clients << csc;
|
rmrf_clients << csc;
|
||||||
}
|
}
|
||||||
c_servers.remove(cs->serverUUID());
|
c_servers.remove(cs->serverUUID());
|
||||||
index_c_servers.remove(client);
|
index_c_servers.remove(client);
|
||||||
if (!rmrf_servers.contains(cs)) rmrf_servers << cs;
|
rmrf_servers << cs;
|
||||||
}
|
}
|
||||||
CloudServer * cc = index_c_clients.value(client, nullptr);
|
CloudServer * cc = index_c_clients.value(client, nullptr);
|
||||||
if (cc) {
|
if (cc) {
|
||||||
@@ -223,7 +223,7 @@ void DispatcherServer::disconnectClient(DispatcherClient * client) {
|
|||||||
index_c_clients.remove(client);
|
index_c_clients.remove(client);
|
||||||
}
|
}
|
||||||
// client->close();
|
// client->close();
|
||||||
if (!rmrf_clients.contains(client)) rmrf_clients << client;
|
rmrf_clients << client;
|
||||||
piCoutObj << "remove done" << client->clientId();
|
piCoutObj << "remove done" << client->clientId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ private:
|
|||||||
PIMap<PIByteArray, CloudServer *> c_servers;
|
PIMap<PIByteArray, CloudServer *> c_servers;
|
||||||
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;
|
PISet<DispatcherClient *> rm_clients;
|
||||||
PIVector<DispatcherClient *> rmrf_clients;
|
PISet<DispatcherClient *> rmrf_clients;
|
||||||
PIVector<CloudServer *> rmrf_servers;
|
PIVector<CloudServer *> rmrf_servers;
|
||||||
PITimer timeout_timer;
|
PITimer timeout_timer;
|
||||||
PIMutex map_mutex;
|
PIMutex map_mutex;
|
||||||
|
|||||||
Reference in New Issue
Block a user