当前位置: 首页>>代码示例>>C++>>正文


C++ Duration::asMilliseconds方法代码示例

本文整理汇总了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;
        }
开发者ID:siliace,项目名称:Bull,代码行数:9,代码来源:SocketPollerImpl.cpp

示例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"));
    }
开发者ID:siliace,项目名称:Bull,代码行数:26,代码来源:TcpClient.cpp

示例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;
        }
开发者ID:siliace,项目名称:Bull,代码行数:22,代码来源:IcmpImpl.cpp


注:本文中的Duration::asMilliseconds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。