本文整理汇总了C++中Chrono::getMillis方法的典型用法代码示例。如果您正苦于以下问题:C++ Chrono::getMillis方法的具体用法?C++ Chrono::getMillis怎么用?C++ Chrono::getMillis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chrono
的用法示例。
在下文中一共展示了Chrono::getMillis方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: waitForMessage
void ClientInterface::waitForMessage(){
Chrono chrono;
chrono.start();
while(getNextMessageType()==nmtInvalid){
if(!isConnected()){
throw runtime_error("Disconnected");
}
if(chrono.getMillis()>messageWaitTimeout){
throw runtime_error("Timeout waiting for message");
}
sleep(waitSleepTime);
}
}
示例2: waitUntilReady
void ClientInterface::waitUntilReady(Checksum* checksum){
NetworkMessageReady networkMessageReady;
Chrono chrono;
chrono.start();
//send ready message
sendMessage(&networkMessageReady);
//wait until we get a ready message from the server
while(true){
NetworkMessageType networkMessageType= getNextMessageType();
if(networkMessageType==nmtReady){
if(receiveMessage(&networkMessageReady)){
break;
}
}
else if(networkMessageType==nmtInvalid){
if(chrono.getMillis()>readyWaitTimeout){
throw runtime_error("Timeout waiting for server");
}
}
else{
throw runtime_error("Unexpected network message: " + intToStr(networkMessageType) );
}
// sleep a bit
sleep(waitSleepTime);
}
//check checksum
if(Config::getInstance().getBool("NetworkConsistencyChecks")){
if(networkMessageReady.getChecksum()!=checksum->getSum()){
throw runtime_error("Checksum error, you don't have the same data as the server");
}
}
//delay the start a bit, so clients have nore room to get messages
sleep(GameConstants::networkExtraLatency);
}