예제 #1
0
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
}
예제 #2
0
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;
}
예제 #3
0
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;
	}
}
예제 #4
0
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;
}
예제 #5
0
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
	}
}
예제 #6
0
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;
	}
}
예제 #7
0
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;
}
예제 #8
0
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);
		}
	}
}
예제 #9
0
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;
}
예제 #10
0
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;
}
예제 #11
0
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);
		}
	}
}
예제 #12
0
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;
}