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