|
@@ -54,6 +54,13 @@ void CServer::Init()
|
|
|
t.detach();
|
|
t.detach();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //开一个线程,每隔30分钟清理一次过期的消息
|
|
|
|
|
+ for (int i = 0; i < 1; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ std::thread t(&CServer::HandleCleanupDueMessage, this);
|
|
|
|
|
+ t.detach();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//开始异步执行
|
|
//开始异步执行
|
|
|
io_context_.run();
|
|
io_context_.run();
|
|
|
}
|
|
}
|
|
@@ -235,9 +242,7 @@ void CServer::HandleOfflineMessage()
|
|
|
bool ret = session->send_message(data);
|
|
bool ret = session->send_message(data);
|
|
|
if (ret == false)
|
|
if (ret == false)
|
|
|
{
|
|
{
|
|
|
- //发送失败,把数据写会数据库,等下次发送
|
|
|
|
|
- AddMessageToDB(username, due_time, data);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ //发送失败,等下次发送
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -401,8 +406,6 @@ void CServer::ReceiveMNSMessage()
|
|
|
m_queue_mutex.lock();
|
|
m_queue_mutex.lock();
|
|
|
m_message_queue.push(newMessage);
|
|
m_message_queue.push(newMessage);
|
|
|
m_queue_mutex.unlock();
|
|
m_queue_mutex.unlock();
|
|
|
-
|
|
|
|
|
- //LOG_INFO("push message to queue!");
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -465,6 +468,20 @@ void CServer::SendMessageToClient()
|
|
|
LOG_INFO("send to client success, username:" << username.c_str());
|
|
LOG_INFO("send to client success, username:" << username.c_str());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/*
|
|
|
|
|
+ *每30分钟清理一次数据库
|
|
|
|
|
+ **/
|
|
|
|
|
+void CServer::HandleCleanupDueMessage()
|
|
|
|
|
+{
|
|
|
|
|
+ while (true)
|
|
|
|
|
+ {
|
|
|
|
|
+ std::string curTime = CLewaimaiTime::DatetimeToString(time(NULL));
|
|
|
|
|
+ std::string sql = "DELETE FROM pos_message WHERE due_time <= '" + curTime + "';";
|
|
|
|
|
+ sqlite3_exec(m_db, sql.c_str(), 0, 0, 0);
|
|
|
|
|
+
|
|
|
|
|
+ CSystem::my_sleep(60 * 30);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|