cloud inspecting ...
This commit is contained in:
@@ -312,8 +312,9 @@ bool PIEthernet::closeDevice() {
|
|||||||
if (sock_s == sock) sock_s = -1;
|
if (sock_s == sock) sock_s = -1;
|
||||||
closeSocket(sock);
|
closeSocket(sock);
|
||||||
closeSocket(sock_s);
|
closeSocket(sock_s);
|
||||||
while (!clients_.isEmpty())
|
clients_mutex.lock();
|
||||||
delete clients_.back();
|
piDeleteAllAndClear(clients_);
|
||||||
|
clients_mutex.unlock();
|
||||||
if (ned) {
|
if (ned) {
|
||||||
// piCoutObj << "Disconnect on close";
|
// piCoutObj << "Disconnect on close";
|
||||||
disconnected(false);
|
disconnected(false);
|
||||||
@@ -529,6 +530,21 @@ bool PIEthernet::listen(const PINetworkAddress & addr, bool threaded) {
|
|||||||
return listen(threaded);
|
return listen(threaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PIEthernet * PIEthernet::client(int index) {
|
||||||
|
PIMutexLocker locker(clients_mutex);
|
||||||
|
return clients_[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
int PIEthernet::clientsCount() const {
|
||||||
|
PIMutexLocker locker(clients_mutex);
|
||||||
|
return clients_.size_s();
|
||||||
|
}
|
||||||
|
|
||||||
|
PIVector<PIEthernet *> PIEthernet::clients() const {
|
||||||
|
PIMutexLocker locker(clients_mutex);
|
||||||
|
return clients_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PIEthernet::send(const void * data, int size, bool threaded) {
|
bool PIEthernet::send(const void * data, int size, bool threaded) {
|
||||||
if (threaded) {
|
if (threaded) {
|
||||||
@@ -823,9 +839,8 @@ void PIEthernet::applyParameters() {
|
|||||||
|
|
||||||
|
|
||||||
void PIEthernet::clientDeleted(PIObject * o) {
|
void PIEthernet::clientDeleted(PIObject * o) {
|
||||||
clients_mutex.lock();
|
PIMutexLocker locker(clients_mutex);
|
||||||
clients_.removeOne((PIEthernet *)o);
|
clients_.removeOne((PIEthernet *)o);
|
||||||
clients_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -251,9 +251,9 @@ public:
|
|||||||
//! Start listen for incoming TCP connections on address "addr". Use only for TCP_Server
|
//! Start listen for incoming TCP connections on address "addr". Use only for TCP_Server
|
||||||
bool listen(const PINetworkAddress & addr, bool threaded = false);
|
bool listen(const PINetworkAddress & addr, bool threaded = false);
|
||||||
|
|
||||||
PIEthernet * client(int index) { return clients_[index]; }
|
PIEthernet * client(int index);
|
||||||
int clientsCount() const { return clients_.size_s(); }
|
int clientsCount() const;
|
||||||
PIVector<PIEthernet *> clients() const { return clients_; }
|
PIVector<PIEthernet *> clients() const;
|
||||||
|
|
||||||
|
|
||||||
//! Send data "data" with size "size" to address \a sendAddress() for UDP or \a readAddress() for TCP_Client
|
//! Send data "data" with size "size" to address \a sendAddress() for UDP or \a readAddress() for TCP_Client
|
||||||
@@ -484,7 +484,7 @@ protected:
|
|||||||
mutable PINetworkAddress addr_r, addr_s, addr_lr;
|
mutable PINetworkAddress addr_r, addr_s, addr_lr;
|
||||||
Type eth_type;
|
Type eth_type;
|
||||||
PIThread server_thread_;
|
PIThread server_thread_;
|
||||||
PIMutex clients_mutex;
|
mutable PIMutex clients_mutex;
|
||||||
PIVector<PIEthernet *> clients_;
|
PIVector<PIEthernet *> clients_;
|
||||||
PIQueue<PIString> mcast_queue;
|
PIQueue<PIString> mcast_queue;
|
||||||
PIStringList mcast_groups;
|
PIStringList mcast_groups;
|
||||||
|
|||||||
@@ -54,9 +54,8 @@ void CloudServer::removeClient(DispatcherClient * c) {
|
|||||||
|
|
||||||
|
|
||||||
PIVector<DispatcherClient *> CloudServer::getClients() {
|
PIVector<DispatcherClient *> CloudServer::getClients() {
|
||||||
mutex_clients.lock();
|
PIMutexLocker locker(mutex_clients);
|
||||||
PIVector<DispatcherClient *> cl = clients;
|
PIVector<DispatcherClient *> cl = clients;
|
||||||
mutex_clients.unlock();
|
|
||||||
return cl;
|
return cl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,11 +66,10 @@ double CloudServer::lastPing() {
|
|||||||
|
|
||||||
|
|
||||||
void CloudServer::printStatus() {
|
void CloudServer::printStatus() {
|
||||||
mutex_clients.lock();
|
PIMutexLocker locker(mutex_clients);
|
||||||
piCout << " "
|
piCout << " "
|
||||||
<< "Clients for" << server->address() << server_uuid.toHex() << ":";
|
<< "Clients for" << server->address() << server_uuid.toHex() << ":";
|
||||||
for (auto c: clients) {
|
for (auto c: clients) {
|
||||||
piCout << " " << c->address() << c->clientId();
|
piCout << " " << c->address() << c->clientId();
|
||||||
}
|
}
|
||||||
mutex_clients.unlock();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ void DispatcherClient::start() {
|
|||||||
|
|
||||||
|
|
||||||
DispatcherClient::~DispatcherClient() {
|
DispatcherClient::~DispatcherClient() {
|
||||||
delete eth;
|
piDeleteSafety(eth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ void DispatcherServer::cleanClients() {
|
|||||||
piCout << "remove Server by ping timeout" << c->getConnection()->clientId();
|
piCout << "remove Server by ping timeout" << c->getConnection()->clientId();
|
||||||
PIVector<DispatcherClient *> cscv = c->getClients();
|
PIVector<DispatcherClient *> cscv = c->getClients();
|
||||||
for (auto csc: cscv) {
|
for (auto csc: cscv) {
|
||||||
|
if (!csc->isPIObject()) piCout << "ACHTUNG! Non-piobject DispatcherClient!";
|
||||||
clients.removeAll(csc);
|
clients.removeAll(csc);
|
||||||
index_c_clients.remove(csc);
|
index_c_clients.remove(csc);
|
||||||
c->removeClient(csc);
|
c->removeClient(csc);
|
||||||
@@ -183,12 +184,12 @@ void DispatcherServer::setMaxConnections(uint max_count) {
|
|||||||
|
|
||||||
|
|
||||||
void DispatcherServer::disconnectClient(DispatcherClient * client) {
|
void DispatcherServer::disconnectClient(DispatcherClient * client) {
|
||||||
|
PIMutexLocker locker(map_mutex);
|
||||||
if (!clients.contains(client)) {
|
if (!clients.contains(client)) {
|
||||||
// piCoutObj << "INVALID client" << client;
|
// piCoutObj << "INVALID client" << client;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
piCoutObj << "remove ..." << client->clientId();
|
piCoutObj << "remove ..." << client->clientId();
|
||||||
PIMutexLocker locker(map_mutex);
|
|
||||||
clients.removeAll(client);
|
clients.removeAll(client);
|
||||||
rm_clients.removeAll(client);
|
rm_clients.removeAll(client);
|
||||||
CloudServer * cs = index_c_servers.value(client, nullptr);
|
CloudServer * cs = index_c_servers.value(client, nullptr);
|
||||||
@@ -219,6 +220,7 @@ void DispatcherServer::disconnectClient(DispatcherClient * client) {
|
|||||||
|
|
||||||
|
|
||||||
void DispatcherServer::newConnection(PIEthernet * cl) {
|
void DispatcherServer::newConnection(PIEthernet * cl) {
|
||||||
|
PIMutexLocker locker(map_mutex);
|
||||||
if (clients.size() >= max_connections) {
|
if (clients.size() >= max_connections) {
|
||||||
delete cl;
|
delete cl;
|
||||||
return;
|
return;
|
||||||
@@ -253,7 +255,6 @@ void DispatcherServer::newConnection(PIEthernet * cl) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
// piCoutObj << "add client" << client;
|
// piCoutObj << "add client" << client;
|
||||||
PIMutexLocker locker(map_mutex);
|
|
||||||
clients.push_back(client);
|
clients.push_back(client);
|
||||||
client->start();
|
client->start();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user