void TcpConnectionHandler::HandleSend() { if (m_queue->SendSize() > 0) { NetworkMessage msg = m_queue->DequeueMessageToSend(); uint32_t size; std::unique_ptr<uint8_t> data(msg.SerializeData(size)); if (msg.GetDistributionMode() == DistributionMode::Others) { m_listMutex.lock(); for (int i = 0; i < m_list.size(); i++) { std::shared_ptr<TcpConnection> c = m_list.at(i); if (c->GetID() != msg.GetSenderID()) { int32_t sent; if (!c->GetClient()->Send(data.get(), size, sent)) { // it failed - retry? or just disconnect right in the first try } } } m_listMutex.unlock(); } else if (msg.GetDistributionMode() == DistributionMode::OthersAndServer) { m_listMutex.lock(); for (int i = 0; i < m_list.size(); i++) { std::shared_ptr<TcpConnection> c = m_list.at(i); if (c->GetID() != msg.GetSenderID()) { int32_t sent; if (!c->GetClient()->Send(data.get(), size, sent)) { // it failed - retry? or just disconnect right in the first try } } } m_listMutex.unlock(); //handle to plugins too } else if (msg.GetDistributionMode() == DistributionMode::ID) { m_listMutex.lock(); for (int i = 0; i < m_list.size(); i++) { std::shared_ptr<TcpConnection> c = m_list.at(i); if (c->GetID() == msg.GetSenderID()) { int32_t sent; if (!c->GetClient()->Send(data.get(), size, sent)) { // it failed - retry? or just disconnect right in the first try } } } m_listMutex.unlock(); } else if (msg.GetDistributionMode() == DistributionMode::All) { m_listMutex.lock(); for (int i = 0; i < m_list.size(); i++) { std::shared_ptr<TcpConnection> c = m_list.at(i); int32_t sent; if (!c->GetClient()->Send(data.get(), size, sent)) { // it failed - retry? or just disconnect right in the first try } } m_listMutex.unlock(); } else if (msg.GetDistributionMode() == DistributionMode::AllAndMe) { m_listMutex.lock(); for (int i = 0; i < m_list.size(); i++) { std::shared_ptr<TcpConnection> c = m_list.at(i); int32_t sent; if (!c->GetClient()->Send(data.get(), size, sent)) { // it failed - retry? or just disconnect right in the first try } } m_listMutex.unlock(); //handle to plugins too } else if (msg.GetDistributionMode() == DistributionMode::Server) { //handle just in plugins } } }