即阻塞代码,我将如何将其转换为非阻塞异步? 我试图做一个客户端和服务器之间的异步通信。 这里是我的阻止同步代码,我将如何做到异步?将阻塞同步代码转换为异步
bool S3W::CImplServerData::WaitForCompletion(unsigned int timeout)
{
unsigned int t1;
while (true)
{
BinaryMessageBuffer currBuff;
if (m_Queue.try_pop(currBuff))
{
ProcessBuffer(currBuff);
t1 = clock();
}
else
{
unsigned int t2 = clock();
if ((t2 - t1) > timeout)
{
return false;
}
else
{
Sleep(1);
}
}
}
return true;
}
你怎么做的 “沟通”?你在使用特定的框架吗?一些平台特定的功能?请详细说明!请花一些时间[阅读如何提出好问题](http://stackoverflow.com/help/how-to-ask),并学习如何创建[最小,完整和可验证示例](http: //stackoverflow.com/help/mcve)。 –
我正在使用OGR Api。我将编辑我的帖子 –