void OutputMessagePool::sendAll() { boost::recursive_mutex::scoped_lock lockClass(m_outputPoolLock); OutputMessageMessageList::iterator it; for(it = m_toAddQueue.begin(); it != m_toAddQueue.end();) { //drop messages that are older than 10 seconds if(OTSYS_TIME() - (*it)->getFrame() > 10 * 1000) { (*it)->getProtocol()->onSendMessage(*it); it = m_toAddQueue.erase(it); continue; } (*it)->setState(OutputMessage::STATE_ALLOCATED); m_autoSendOutputMessages.push_back(*it); ++it; } m_toAddQueue.clear(); for(it = m_autoSendOutputMessages.begin(); it != m_autoSendOutputMessages.end();) { OutputMessage_ptr omsg = *it; #ifdef __NO_PLAYER_SENDBUFFER__ //use this define only for debugging bool v = 1; #else //It will send only messages bigger then 1 kb or with a lifetime greater than 10 ms bool v = omsg->getMessageLength() > 1024 || (m_frameTime - omsg->getFrame() > 10); #endif if(v) { #ifdef __DEBUG_NET_DETAIL__ std::cout << "Sending message - ALL" << std::endl; #endif if(omsg->getConnection()) { if(!omsg->getConnection()->send(omsg)) { // Send only fails when connection is closing (or in error state) // This call will free the message omsg->getProtocol()->onSendMessage(omsg); } } else { #ifdef __DEBUG_NET__ std::cout << "Error: [OutputMessagePool::send] NULL connection." << std::endl; #endif } it = m_autoSendOutputMessages.erase(it); } else ++it; } }
void OutputMessagePool::sendAll() { OTSYS_THREAD_LOCK_CLASS lockClass(m_outputPoolLock); OutputMessageList::iterator it; for(it = m_toAddQueue.begin(); it != m_toAddQueue.end();) { //drop messages that are older than 10 seconds if(OTSYS_TIME() - (*it)->getFrame() > 10000) { if((*it)->getProtocol()) (*it)->getProtocol()->onSendMessage(*it); it = m_toAddQueue.erase(it); continue; } (*it)->setState(OutputMessage::STATE_ALLOCATED); m_autoSendOutputMessages.push_back(*it); ++it; } m_toAddQueue.clear(); for(it = m_autoSendOutputMessages.begin(); it != m_autoSendOutputMessages.end(); ) { OutputMessage_ptr omsg = (*it); #ifdef __NO_PLAYER_SENDBUFFER__ //use this define only for debugging if(true) #else //It will send only messages bigger then 1 kb or with a lifetime greater than 10 ms if(omsg->getMessageLength() > 1024 || (m_frameTime - omsg->getFrame() > 10)) #endif { #ifdef __DEBUG_NET_DETAIL__ std::cout << "Sending message - ALL" << std::endl; #endif if(omsg->getConnection()) { if(!omsg->getConnection()->send(omsg) && omsg->getProtocol()) omsg->getProtocol()->onSendMessage(omsg); } #ifdef __DEBUG_NET__ else std::cout << "Error: [OutputMessagePool::send] NULL connection." << std::endl; #endif it = m_autoSendOutputMessages.erase(it); } else ++it; } }
void OutputMessagePool::sendAll() { std::lock_guard<std::recursive_mutex> lockClass(m_outputPoolLock); const int64_t dropTime = m_frameTime - 10000; const int64_t frameTime = m_frameTime - 10; for (OutputMessage_ptr omsg : m_toAddQueue) { const int64_t msgFrame = omsg->getFrame(); if (msgFrame >= dropTime) { omsg->setState(OutputMessage::STATE_ALLOCATED); if (frameTime > msgFrame) { m_autoSendOutputMessages.push_front(omsg); } else { m_autoSendOutputMessages.push_back(omsg); } } else { //drop messages that are older than 10 seconds omsg->getProtocol()->onSendMessage(omsg); } } m_toAddQueue.clear(); for (auto it = m_autoSendOutputMessages.begin(), end = m_autoSendOutputMessages.end(); it != end; it = m_autoSendOutputMessages.erase(it)) { OutputMessage_ptr omsg = *it; if (frameTime <= omsg->getFrame()) { break; } Connection_ptr connection = omsg->getConnection(); if (connection && !connection->send(omsg)) { // Send only fails when connection is closing (or in error state) // This call will free the message omsg->getProtocol()->onSendMessage(omsg); } } }