本文整理汇总了C++中Duration::asMilliseconds方法的典型用法代码示例。如果您正苦于以下问题:C++ Duration::asMilliseconds方法的具体用法?C++ Duration::asMilliseconds怎么用?C++ Duration::asMilliseconds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Duration
的用法示例。
在下文中一共展示了Duration::asMilliseconds方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wait
bool SocketPollerImpl::wait(const Duration& timeout)
{
if(!m_sockets.empty())
{
return poll(m_sockets, static_cast<int>(timeout.asMilliseconds())) > 0;
}
return false;
}
示例2: connect
void TcpClient::connect(const IpAddress& address, NetPort port, const Duration& timeout, const Duration& pause)
{
Expect(address.isValid(), Throw(InvalidParameter, "Invalid IpAddress"));
Expect(port != NetPort_Any, Throw(InvalidParameter, "Invalid NetPort"));
int ret;
Clock clock;
Socket::create(address.getProtocol());
prv::SockAddrBuffer buffer(address, port);
clock.start();
do
{
ret = ::connect(getHandler(), buffer.getSockAddr(), buffer.getLength());
if(ret != 0)
{
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<long long>(pause.asMilliseconds())));
}
}while(ret != 0 && clock.getElapsedTime() < timeout);
Expect(ret == 0, Throw(InternalError, "Failed to connect to the remote host"));
}
示例3: ping
Duration IcmpImpl::ping(const IpAddressV4& address, const Duration& timeout)
{
HANDLE icmpHandle = IcmpCreateFile();
Expect(icmpHandle != INVALID_HANDLE_VALUE, Throw(Win32Error, "Failed to create ICMP handler"));
ByteArray request(32);
IPAddr addr = address.toInt();
ByteArray response(sizeof(ICMP_ECHO_REPLY) + request.getCapacity());
DWORD retval = IcmpSendEcho(icmpHandle, addr, &request[0], request.getCapacity(), nullptr, &response[0], response.getCapacity(), timeout.asMilliseconds());
Expect(retval > 0, Throw(Win32Error, "Failed to send ICMP request"));
const ICMP_ECHO_REPLY* reply = reinterpret_cast<const ICMP_ECHO_REPLY*>(response.getBuffer());
Duration duration = Duration::milliseconds(reply->RoundTripTime);
IcmpCloseHandle(icmpHandle);
return duration;
}