void OutputMessagePool::send(OutputMessage_ptr msg) { OTSYS_THREAD_LOCK(m_outputPoolLock, ""); OutputMessage::OutputMessageState state = msg->getState(); OTSYS_THREAD_UNLOCK(m_outputPoolLock, ""); if(state == OutputMessage::STATE_ALLOCATED_NO_AUTOSEND) { #ifdef __DEBUG_NET_DETAIL__ std::cout << "Sending message - SINGLE" << std::endl; #endif if(msg->getConnection()) { if(!msg->getConnection()->send(msg) && msg->getProtocol()) msg->getProtocol()->onSendMessage(msg); } #ifdef __DEBUG_NET__ else std::cout << "Error: [OutputMessagePool::send] NULL connection." << std::endl; #endif } #ifdef __DEBUG_NET__ else std::cout << "Warning: [OutputMessagePool::send] State != STATE_ALLOCATED_NO_AUTOSEND" << std::endl; #endif }
bool Connection::send(OutputMessage_ptr msg) { LOGt("Connection::send()"); boost::recursive_mutex::scoped_lock lock(m_connectionLock); if(m_connectionState != CONNECTION_STATE_OPEN || m_writeError) { return false; } TRACK_MESSAGE(msg); if(!m_pendingWrite) { if(msg->getProtocol()) msg->getProtocol()->onSendMessage(msg); internalSend(msg); } else if(m_pendingWrite > 100 && server.configManager().getBool(ConfigManager::FORCE_CLOSE_SLOW_CONNECTION)) { LOGd("Forcing slow connection to disconnect!"); close(); } else { OutputMessagePool::getInstance()->autoSend(msg); } return true; }
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; } }
bool Connection::send(OutputMessage_ptr msg) { m_connectionLock.lock(); if(m_closeState == CLOSE_STATE_CLOSING || m_writeError) { m_connectionLock.unlock(); return false; } msg->getProtocol()->onSendMessage(msg); if(m_pendingWrite == 0) { #ifdef __DEBUG_NET_DETAIL__ std::clog << "Connection::send " << msg->getMessageLength() << std::endl; #endif internalSend(msg); } else { #ifdef __DEBUG_NET__ std::clog << "Connection::send Adding to queue " << msg->getMessageLength() << std::endl; #endif m_outputQueue.push_back(msg); } m_connectionLock.unlock(); return true; }
void OutputMessagePool::send(OutputMessage_ptr msg) { m_outputPoolLock.lock(); OutputMessage::OutputMessageState state = msg->getState(); m_outputPoolLock.unlock(); if(state == OutputMessage::STATE_ALLOCATED_NO_AUTOSEND) { #ifdef __DEBUG_NET_DETAIL__ std::cout << "Sending message - SINGLE" << std::endl; #endif if(msg->getConnection()) { if(!msg->getConnection()->send(msg)) { // Send only fails when connection is closing (or in error state) // This call will free the message msg->getProtocol()->onSendMessage(msg); } } else { #ifdef __DEBUG_NET__ std::cout << "Error: [OutputMessagePool::send] NULL connection." << std::endl; #endif } } else { #ifdef __DEBUG_NET__ std::cout << "Warning: [OutputMessagePool::send] State != STATE_ALLOCATED_NO_AUTOSEND" << std::endl; #endif } }
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; } }
bool Connection::send(OutputMessage_ptr msg) { #ifdef __DEBUG_NET_DETAIL__ std::clog << "Connection::send init" << std::endl; #endif m_connectionLock.lock(); if(m_connectionState != CONNECTION_STATE_OPEN || m_writeError) { m_connectionLock.unlock(); return false; } TRACK_MESSAGE(msg); if(!m_pendingWrite) { if(msg->getProtocol()) msg->getProtocol()->onSendMessage(msg); #ifdef __DEBUG_NET_DETAIL__ std::clog << "Connection::send " << msg->size() << std::endl; #endif internalSend(msg); } else if(m_pendingWrite > 100 && g_config.getBool(ConfigManager::FORCE_CLOSE_SLOW_CONNECTION)) { std::clog << "NOTICE: Forcing slow connection to disconnect!" << std::endl; close(); } else { #ifdef __DEBUG_NET__ std::clog << "Connection::send Adding to queue " << msg->size() << std::endl; #endif OutputMessagePool::getInstance()->autoSend(msg); } m_connectionLock.unlock(); return true; }
void OutputMessagePool::send(OutputMessage_ptr msg) { m_outputPoolLock.lock(); OutputMessage::OutputMessageState state = msg->getState(); m_outputPoolLock.unlock(); if (state == OutputMessage::STATE_ALLOCATED_NO_AUTOSEND) { Connection_ptr connection = msg->getConnection(); if (connection && !connection->send(msg)) { // Send only fails when connection is closing (or in error state) // This call will free the message msg->getProtocol()->onSendMessage(msg); } } }
bool Connection::send(OutputMessage_ptr msg) { std::lock_guard<std::recursive_mutex> lockClass(m_connectionLock); if (m_connectionState != CONNECTION_STATE_OPEN || m_writeError) { return false; } if (m_pendingWrite == 0) { msg->getProtocol()->onSendMessage(msg); internalSend(msg); } else { OutputMessagePool::getInstance()->addToAutoSend(msg); } return true; }
bool Connection::send(OutputMessage_ptr msg) { m_connectionLock.lock(); if (m_connectionState != CONNECTION_STATE_OPEN || m_writeError) { m_connectionLock.unlock(); return false; } if (m_pendingWrite == 0) { msg->getProtocol()->onSendMessage(msg); internalSend(msg); } else { OutputMessagePool::getInstance()->addToAutoSend(msg); } m_connectionLock.unlock(); return true; }
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); } } }
bool Connection::send(OutputMessage_ptr msg) { #ifdef __DEBUG_NET_DETAIL__ std::cout << "Connection::send init" << std::endl; #endif m_connectionLock.lock(); if(m_connectionState != CONNECTION_STATE_OPEN || m_writeError){ m_connectionLock.unlock(); return false; } if(m_pendingWrite == 0){ msg->getProtocol()->onSendMessage(msg); TRACK_MESSAGE(msg); #ifdef __DEBUG_NET_DETAIL__ std::cout << "Connection::send " << msg->getMessageLength() << std::endl; #endif internalSend(msg); } else{ #ifdef __DEBUG_NET__ std::cout << "Connection::send Adding to queue " << msg->getMessageLength() << std::endl; #endif TRACK_MESSAGE(msg); OutputMessagePool* outputPool = OutputMessagePool::getInstance(); outputPool->addToAutoSend(msg); } m_connectionLock.unlock(); return true; }