ADD: adden a function to delete clients
This commit is contained in:
@@ -46,6 +46,7 @@ namespace DirectCommunication
|
|||||||
std::vector<std::uint32_t> connectedClients_;
|
std::vector<std::uint32_t> connectedClients_;
|
||||||
|
|
||||||
bool hasClient(std::uint32_t clientId);
|
bool hasClient(std::uint32_t clientId);
|
||||||
|
void deleteClient(std::uint32_t clientId);
|
||||||
|
|
||||||
std::function<void(std::string)> MessageHandle_ = nullptr;
|
std::function<void(std::string)> MessageHandle_ = nullptr;
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,14 @@ namespace DirectCommunication
|
|||||||
for (auto it = connectedClients_.begin(); it != connectedClients_.end(); ++it) {
|
for (auto it = connectedClients_.begin(); it != connectedClients_.end(); ++it) {
|
||||||
zmq::message_t zmqMsg(msg.begin(),msg.end());
|
zmq::message_t zmqMsg(msg.begin(),msg.end());
|
||||||
zmqMsg.set_routing_id(*it);
|
zmqMsg.set_routing_id(*it);
|
||||||
|
try {
|
||||||
socket_.send(zmqMsg,zmq::send_flags::dontwait);
|
socket_.send(zmqMsg,zmq::send_flags::dontwait);
|
||||||
|
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
LOG_S(ERROR)<<e.what();
|
||||||
|
LOG_S(ERROR)<< "Routing id: " << *it;
|
||||||
|
deleteClient(*it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,7 +79,6 @@ namespace DirectCommunication
|
|||||||
|
|
||||||
void DirectCommunicationServer::workerFunc_()
|
void DirectCommunicationServer::workerFunc_()
|
||||||
{
|
{
|
||||||
LOG_S(INFO)<<"worker started";
|
|
||||||
while (stopWorker_ == false)
|
while (stopWorker_ == false)
|
||||||
{
|
{
|
||||||
zmq::message_t msg;
|
zmq::message_t msg;
|
||||||
@@ -87,13 +93,13 @@ namespace DirectCommunication
|
|||||||
}
|
}
|
||||||
if (msg.to_string() == "CLOSE")
|
if (msg.to_string() == "CLOSE")
|
||||||
{
|
{
|
||||||
auto it = std::find(connectedClients_.begin(), connectedClients_.end(), msg.routing_id());
|
LOG_S(INFO)<<"CLOSE received from: "<< msg.routing_id();
|
||||||
connectedClients_.erase(it);
|
deleteClient(msg.routing_id());
|
||||||
|
LOG_S(INFO)<<"remaining connected clients: " <<connectedClients_.size();
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
if (MessageHandle_ != nullptr)
|
if (MessageHandle_ != nullptr)
|
||||||
{
|
{
|
||||||
LOG_S(INFO)<<"using handle";
|
|
||||||
MessageHandle_(msg.to_string());
|
MessageHandle_(msg.to_string());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -119,6 +125,15 @@ namespace DirectCommunication
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DirectCommunicationServer::deleteClient(std::uint32_t clientId)
|
||||||
|
{
|
||||||
|
auto it = std::find(connectedClients_.begin(), connectedClients_.end(), clientId);
|
||||||
|
if (it != connectedClients_.end() ) {
|
||||||
|
connectedClients_.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user