本文整理汇总了C++中OutputMessagePool类的典型用法代码示例。如果您正苦于以下问题:C++ OutputMessagePool类的具体用法?C++ OutputMessagePool怎么用?C++ OutputMessagePool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OutputMessagePool类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: srand
OTSYS_THREAD_RETURN Dispatcher::dispatcherThread(void* p)
{
#if defined __EXCEPTION_TRACER__
ExceptionHandler dispatcherExceptionHandler;
dispatcherExceptionHandler.InstallHandler();
#endif
srand((uint32_t)OTSYS_TIME());
OutputMessagePool* outputPool = NULL;
while(Dispatcher::m_threadState != Dispatcher::STATE_TERMINATED)
{
Task* task = NULL;
// check if there are tasks waiting
OTSYS_THREAD_LOCK(getDispatcher().m_taskLock, "");
if(getDispatcher().m_taskList.empty()) //if the list is empty wait for signal
OTSYS_THREAD_WAITSIGNAL(getDispatcher().m_taskSignal, getDispatcher().m_taskLock);
if(!getDispatcher().m_taskList.empty() && Dispatcher::m_threadState != Dispatcher::STATE_TERMINATED)
{
// take the first task
task = getDispatcher().m_taskList.front();
getDispatcher().m_taskList.pop_front();
}
OTSYS_THREAD_UNLOCK(getDispatcher().m_taskLock, "");
// finally execute the task...
if(!task)
continue;
if(!task->hasExpired())
{
if((outputPool = OutputMessagePool::getInstance()))
outputPool->startExecutionFrame();
(*task)();
if(outputPool)
outputPool->sendAll();
g_game.clearSpectatorCache();
}
delete task;
}
#if defined __EXCEPTION_TRACER__
dispatcherExceptionHandler.RemoveHandler();
#endif
#if not defined(WIN32)
return NULL;
#endif
}
示例2: srand
void Dispatcher::dispatcherThread(void* p)
{
Dispatcher* dispatcher = (Dispatcher*)p;
#if defined __EXCEPTION_TRACER__
ExceptionHandler dispatcherExceptionHandler;
dispatcherExceptionHandler.InstallHandler();
#endif
srand((uint32_t)OTSYS_TIME());
OutputMessagePool* outputPool = NULL;
boost::unique_lock<boost::mutex> taskLockUnique(dispatcher->m_taskLock, boost::defer_lock);
while(Dispatcher::m_threadState != Dispatcher::STATE_TERMINATED)
{
Task* task = NULL;
// check if there are tasks waiting
taskLockUnique.lock();
if(dispatcher->m_taskList.empty()) //if the list is empty wait for signal
dispatcher->m_taskSignal.wait(taskLockUnique);
if(!dispatcher->m_taskList.empty() && Dispatcher::m_threadState != Dispatcher::STATE_TERMINATED)
{
// take the first task
task = dispatcher->m_taskList.front();
dispatcher->m_taskList.pop_front();
}
taskLockUnique.unlock();
// finally execute the task...
if(!task)
continue;
if(!task->hasExpired())
{
if((outputPool = OutputMessagePool::getInstance()))
outputPool->startExecutionFrame();
(*task)();
if(outputPool)
outputPool->sendAll();
g_game.clearSpectatorCache();
}
delete task;
}
#if defined __EXCEPTION_TRACER__
dispatcherExceptionHandler.RemoveHandler();
#endif
}
示例3: while
void Dispatcher::flush()
{
while (!m_taskList.empty()) {
Task* task = m_taskList.front();
m_taskList.pop_front();
(*task)();
delete task;
OutputMessagePool* outputPool = OutputMessagePool::getInstance();
if (outputPool) {
outputPool->sendAll();
}
g_game.clearSpectatorCache();
}
}
示例4: while
void Dispatcher::flush()
{
Task* task = NULL;
while(!m_taskList.empty()){
task = m_taskList.front();
m_taskList.pop_front();
(*task)();
delete task;
OutputMessagePool* outputPool = OutputMessagePool::getInstance();
if(outputPool)
outputPool->sendAll();
g_game.clearSpectatorCache();
}
#ifdef __DEBUG_SCHEDULER__
std::cout << "Flushing Dispatcher" << std::endl;
#endif
}
示例5: internalSend
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* outputPool = OutputMessagePool::getInstance();
outputPool->addToAutoSend(msg);
}
m_connectionLock.unlock();
return true;
}
示例6: dispatcherThread
void Dispatcher::dispatcherThread()
{
OutputMessagePool* outputPool = OutputMessagePool::getInstance();
// NOTE: second argument defer_lock is to prevent from immediate locking
std::unique_lock<std::mutex> taskLockUnique(m_taskLock, std::defer_lock);
while (m_threadState != STATE_TERMINATED) {
Task* task = nullptr;
// check if there are tasks waiting
taskLockUnique.lock();
if (m_taskList.empty()) {
//if the list is empty wait for signal
m_taskSignal.wait(taskLockUnique);
}
if (!m_taskList.empty() && (m_threadState != STATE_TERMINATED)) {
// take the first task
task = m_taskList.front();
m_taskList.pop_front();
}
taskLockUnique.unlock();
// finally execute the task...
if (task) {
if (!task->hasExpired()) {
outputPool->startExecutionFrame();
(*task)();
outputPool->sendAll();
g_game.clearSpectatorCache();
}
delete task;
}
}
}
示例7: TRACK_MESSAGE
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;
}
示例8: dispatcherThread
void Dispatcher::dispatcherThread()
{
OutputMessagePool* outputPool = OutputMessagePool::getInstance();
// NOTE: second argument defer_lock is to prevent from immediate locking
std::unique_lock<std::mutex> taskLockUnique(taskLock, std::defer_lock);
while (getState() != THREAD_STATE_TERMINATED) {
// check if there are tasks waiting
taskLockUnique.lock();
if (taskList.empty()) {
//if the list is empty wait for signal
taskSignal.wait(taskLockUnique);
}
if (!taskList.empty()) {
// take the first task
Task* task = taskList.front();
taskList.pop_front();
taskLockUnique.unlock();
if (!task->hasExpired()) {
// execute it
outputPool->startExecutionFrame();
(*task)();
outputPool->sendAll();
g_game.map.clearSpectatorCache();
}
delete task;
} else {
taskLockUnique.unlock();
}
}
}
示例9: srand
void Dispatcher::dispatcherThread(void* p)
{
#if defined __EXCEPTION_TRACER__
ExceptionHandler dispatcherExceptionHandler;
dispatcherExceptionHandler.InstallHandler();
#endif
srand((unsigned int)OTSYS_TIME());
#ifdef __DEBUG_SCHEDULER__
std::cout << "Starting Dispatcher" << std::endl;
#endif
OutputMessagePool* outputPool;
// NOTE: second argument defer_lock is to prevent from immediate locking
boost::unique_lock<boost::mutex> taskLockUnique(getDispatcher().m_taskLock, boost::defer_lock);
while(Dispatcher::m_threadState != Dispatcher::STATE_TERMINATED){
Task* task = NULL;
// check if there are tasks waiting
taskLockUnique.lock();//getDispatcher().m_taskLock.lock();
if(getDispatcher().m_taskList.empty()){
//if the list is empty wait for signal
#ifdef __DEBUG_SCHEDULER__
std::cout << "Dispatcher: Waiting for task" << std::endl;
#endif
getDispatcher().m_taskSignal.wait(taskLockUnique);
}
#ifdef __DEBUG_SCHEDULER__
std::cout << "Dispatcher: Signalled" << std::endl;
#endif
if(!getDispatcher().m_taskList.empty() && (Dispatcher::m_threadState != Dispatcher::STATE_TERMINATED)){
// take the first task
task = getDispatcher().m_taskList.front();
getDispatcher().m_taskList.pop_front();
}
taskLockUnique.unlock();
// finally execute the task...
if(task){
OutputMessagePool::getInstance()->startExecutionFrame();
(*task)();
delete task;
outputPool = OutputMessagePool::getInstance();
if(outputPool){
outputPool->sendAll();
}
g_game.clearSpectatorCache();
#ifdef __DEBUG_SCHEDULER__
std::cout << "Dispatcher: Executing task" << std::endl;
#endif
}
}
#if defined __EXCEPTION_TRACER__
dispatcherExceptionHandler.RemoveHandler();
#endif
}
示例10: getConnection
void ProtocolAdmin::parsePacket(NetworkMessage& msg)
{
if (g_game.getGameState() == GAME_STATE_SHUTDOWN) {
getConnection()->closeConnection();
return;
}
uint8_t recvbyte = msg.GetByte();
OutputMessagePool* outputPool = OutputMessagePool::getInstance();
OutputMessage_ptr output = outputPool->getOutputMessage(this, false);
if (!output) {
return;
}
switch (m_state) {
case ENCRYPTION_NO_SET: {
if (g_adminConfig->requireEncryption()) {
if ((time(NULL) - m_startTime) > 30000) {
getConnection()->closeConnection();
addLogLine(this, LOGTYPE_WARNING, 1, "encryption timeout");
return;
}
if (recvbyte != AP_MSG_ENCRYPTION && recvbyte != AP_MSG_KEY_EXCHANGE) {
output->AddByte(AP_MSG_ERROR);
output->AddString("encryption needed");
outputPool->send(output);
getConnection()->closeConnection();
addLogLine(this, LOGTYPE_WARNING, 1, "wrong command while ENCRYPTION_NO_SET");
return;
}
break;
} else {
m_state = NO_LOGGED_IN;
}
}
case NO_LOGGED_IN: {
if (g_adminConfig->requireLogin()) {
if ((time(NULL) - m_startTime) > 30000) {
//login timeout
getConnection()->closeConnection();
addLogLine(this, LOGTYPE_WARNING, 1, "login timeout");
return;
}
if (m_loginTries > 3) {
output->AddByte(AP_MSG_ERROR);
output->AddString("too many login tries");
outputPool->send(output);
getConnection()->closeConnection();
addLogLine(this, LOGTYPE_WARNING, 1, "too many login tries");
return;
}
if (recvbyte != AP_MSG_LOGIN) {
output->AddByte(AP_MSG_ERROR);
output->AddString("you are not logged in");
outputPool->send(output);
getConnection()->closeConnection();
addLogLine(this, LOGTYPE_WARNING, 1, "wrong command while NO_LOGGED_IN");
return;
}
break;
} else {
m_state = LOGGED_IN;
}
}
case LOGGED_IN: {
//can execute commands
break;
}
default: {
getConnection()->closeConnection();
return;
}
}
m_lastCommand = time(NULL);
switch (recvbyte) {
case AP_MSG_LOGIN: {
if (m_state == NO_LOGGED_IN && g_adminConfig->requireLogin()) {
std::string password = msg.GetString();
if (g_adminConfig->passwordMatch(password)) {
m_state = LOGGED_IN;
output->AddByte(AP_MSG_LOGIN_OK);
addLogLine(this, LOGTYPE_EVENT, 1, "login ok");
} else {
m_loginTries++;
output->AddByte(AP_MSG_LOGIN_FAILED);
output->AddString("wrong password");
//.........这里部分代码省略.........
示例11: taskLockUnique
void Dispatcher::dispatcherThread(void* p)
{
Dispatcher* dispatcher = static_cast<Dispatcher*>(p);
ExceptionHandler dispatcherExceptionHandler;
dispatcherExceptionHandler.InstallHandler();
#ifdef __DEBUG_SCHEDULER__
std::cout << "Starting Dispatcher" << std::endl;
#endif
OutputMessagePool* outputPool;
// NOTE: second argument defer_lock is to prevent from immediate locking
boost::unique_lock<boost::mutex> taskLockUnique(dispatcher->m_taskLock, boost::defer_lock);
while (dispatcher->m_threadState != STATE_TERMINATED)
{
Task* task = NULL;
// check if there are tasks waiting
taskLockUnique.lock();
if (dispatcher->m_taskList.empty())
{
//if the list is empty wait for signal
#ifdef __DEBUG_SCHEDULER__
std::cout << "Dispatcher: Waiting for task" << std::endl;
#endif
dispatcher->m_taskSignal.wait(taskLockUnique);
}
#ifdef __DEBUG_SCHEDULER__
std::cout << "Dispatcher: Signalled" << std::endl;
#endif
if (!dispatcher->m_taskList.empty() && (dispatcher->m_threadState != STATE_TERMINATED))
{
// take the first task
task = dispatcher->m_taskList.front();
dispatcher->m_taskList.pop_front();
}
taskLockUnique.unlock();
// finally execute the task...
if (task)
{
if (!task->hasExpired())
{
OutputMessagePool::getInstance()->startExecutionFrame();
(*task)();
outputPool = OutputMessagePool::getInstance();
if (outputPool)
{
outputPool->sendAll();
}
g_game.clearSpectatorCache();
}
delete task;
#ifdef __DEBUG_SCHEDULER__
std::cout << "Dispatcher: Executing task" << std::endl;
#endif
}
}
dispatcherExceptionHandler.RemoveHandler();
}