ADD: adden a function to delete clients
This commit is contained in:
@@ -48,7 +48,14 @@ namespace DirectCommunication
|
||||
for (auto it = connectedClients_.begin(); it != connectedClients_.end(); ++it) {
|
||||
zmq::message_t zmqMsg(msg.begin(),msg.end());
|
||||
zmqMsg.set_routing_id(*it);
|
||||
try {
|
||||
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_()
|
||||
{
|
||||
LOG_S(INFO)<<"worker started";
|
||||
while (stopWorker_ == false)
|
||||
{
|
||||
zmq::message_t msg;
|
||||
@@ -87,13 +93,13 @@ namespace DirectCommunication
|
||||
}
|
||||
if (msg.to_string() == "CLOSE")
|
||||
{
|
||||
auto it = std::find(connectedClients_.begin(), connectedClients_.end(), msg.routing_id());
|
||||
connectedClients_.erase(it);
|
||||
LOG_S(INFO)<<"CLOSE received from: "<< msg.routing_id();
|
||||
deleteClient(msg.routing_id());
|
||||
LOG_S(INFO)<<"remaining connected clients: " <<connectedClients_.size();
|
||||
}else
|
||||
{
|
||||
if (MessageHandle_ != nullptr)
|
||||
{
|
||||
LOG_S(INFO)<<"using handle";
|
||||
MessageHandle_(msg.to_string());
|
||||
}
|
||||
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