用户界面UI -- 客户端 -- 数据库 交互时时间保护
2016-09-23 18:26
369 查看
界面UI和客户端交互用的是windows消息机制,PostMessage();是异步的,操作之后就会返回结果,客户端与数据库链接是长连接,异步的,根据报文多少设置心跳包时间长短。为了让一个操作能连贯,在中间加一个时间保护机制。当UI传消息给客户端时,交互结束,增加一个时间保护,等到数据库传输结束。
注意要针对异常操作加时间保护释放。
代码片段
void CDB::StartProtect(bool bEnableMsgPump, unsigned int nTimeLimit)
{
if (s_bEnableMsgPump || s_nTimeLimit)
throw soci::soci_error("server is busy", soci::soci_error::DBE_CMD_BUSY);
ResetProtect(bEnableMsgPump, nTimeLimit);
}
void CDB::ResetProtect(bool bEnableMsgPump, unsigned int nTimeLimit)
{
s_bEnableMsgPump = bEnableMsgPump;
s_nTimeLimit = nTimeLimit;
if (s_nTimeLimit)
m_Session.timelimit(s_nTimeLimit);
if (s_bEnableMsgPump)
m_Session.msg_pump(true);
}
//
void CDB::EndProtect()
{
if (s_nTimeLimit)
m_Session.timelimit(0);
if (s_bEnableMsgPump)
m_Session.msg_pump(false);
s_bEnableMsgPump = false;
s_nTimeLimit = 0;
}
注意要针对异常操作加时间保护释放。
代码片段
void CDB::StartProtect(bool bEnableMsgPump, unsigned int nTimeLimit)
{
if (s_bEnableMsgPump || s_nTimeLimit)
throw soci::soci_error("server is busy", soci::soci_error::DBE_CMD_BUSY);
ResetProtect(bEnableMsgPump, nTimeLimit);
}
void CDB::ResetProtect(bool bEnableMsgPump, unsigned int nTimeLimit)
{
s_bEnableMsgPump = bEnableMsgPump;
s_nTimeLimit = nTimeLimit;
if (s_nTimeLimit)
m_Session.timelimit(s_nTimeLimit);
if (s_bEnableMsgPump)
m_Session.msg_pump(true);
}
//
void CDB::EndProtect()
{
if (s_nTimeLimit)
m_Session.timelimit(0);
if (s_bEnableMsgPump)
m_Session.msg_pump(false);
s_bEnableMsgPump = false;
s_nTimeLimit = 0;
}
相关文章推荐
- Kafka中QueueFullException异常
- VC添加ESXi异常datacenter.queryconnectioninfo
- Query中ajax的使用与缓存问题的解决方法
- Query中ajax的使用与缓存问题的解决方法
- Query中ajax的使用与缓存问题的解决方法
- Query中ajax的使用与缓存问题的解决方法
- Query中ajax的使用与缓存问题的解决方法
- Query中ajax的使用与缓存问题的解决方法
- Query中ajax的使用与缓存问题的解决方法
- Query中ajax的使用与缓存问题的解决方法
- Query中ajax的使用与缓存问题的解决方法
- 制作支持UEFI PC的Server2008 R2系统安装U盘
- java基于GUI的定时关机程序
- linphone configure: error: "Could not find bctoolbox (required dependency)"
- The method buildSessionFactory() from the type Configuration is deprecated
- Mysql索引PRIMARY、NORMAL、UNIQUE、FULLTEXT 区别和使用场合
- json格式化为适用easyUI tree的json
- spark2.0 翻译:Quick Start 快速开始
- easyUI tree方法
- 解决 "检出Maven项目web.xml is missing"错误 和 “Dynamic Web Module 3.0 requires Java 1.6 or newer.”错误