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


C++ OTString::MemSet方法代码示例

本文整理汇总了C++中OTString::MemSet方法的典型用法代码示例。如果您正苦于以下问题:C++ OTString::MemSet方法的具体用法?C++ OTString::MemSet怎么用?C++ OTString::MemSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OTString的用法示例。


在下文中一共展示了OTString::MemSet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

bool OTSocket_ZMQ_2::Receive(OTString & strServerReply)
{
    if (!m_bInitialized) { OT_FAIL; }
    if (!m_HasContext) { OT_FAIL; }
    if (NULL == m_pzmq->context_zmq)  { OTLog::vError("%s: Error: %s must exist to Receive!\n", __FUNCTION__, "m_pzmq->context_zmq");	OT_FAIL; }

    if (!m_bConnected && !m_bListening) return false;
    if (m_bConnected && m_bListening) return false;
    if (NULL == m_pzmq->socket_zmq) { OTLog::vError("%s: Error: %s must exist to Receive!\n", __FUNCTION__, "m_pzmq->socket_zmq");	OT_FAIL; }


    // -----------------------------------	
    const long lLatencyRecvMilliSec = m_lLatencyReceiveMs;
    const long lLatencyRecvMicroSec = lLatencyRecvMilliSec * 1000;

    // ***********************************
    //  Get the reply.
    zmq::message_t zmq_message;

    bool bSuccessReceiving = false;

    // If failure receiving, re-tries 2 times, with 4000 ms max delay between each (Doubling every time.)
    //
    if (m_bIsBlocking)
    {
        bSuccessReceiving = m_pzmq->socket_zmq->recv(&zmq_message); // Blocking.
    }
    else	// not blocking
    {
        long	lDoubling = lLatencyRecvMicroSec;
        int		nReceiveTries = m_nLatencyReceiveNoTries;
        bool	expect_reply = true;
        while (expect_reply)
        {
            //  Poll socket for a reply, with timeout
            zmq::pollitem_t items[] = { { *m_pzmq->socket_zmq, 0, ZMQ_POLLIN, 0 } };

            const int nPoll = zmq::poll(&items[0], 1, lDoubling);
            lDoubling *= 2;

            //  If we got a reply, process it
            if (items[0].revents & ZMQ_POLLIN)
            {
                bSuccessReceiving = m_pzmq->socket_zmq->recv(&zmq_message, ZMQ_NOBLOCK); // <=========== RECEIVE ===============
                OTLog::SleepMilliseconds(1);

                if (!bSuccessReceiving)
                {
                    if (false == HandleReceivingError())
                        expect_reply = false;
                }
                else
                    break; // (Success -- we're done in this loop.)				
            }
            else if (nReceiveTries == 0)
            {
                //OTLog::Error("OTSocket::Receive: no message.\n");
                expect_reply = false;
                break;
            }
            else if ((-1) == nPoll) // error.
            {
                if (false == HandlePollingError())
                    expect_reply = false;
            }

            --nReceiveTries;
        }
    }
    // ***********************************

    if (bSuccessReceiving && (zmq_message.size() > 0))
        strServerReply.MemSet(static_cast<const char*>(zmq_message.data()), static_cast<uint32_t> (zmq_message.size()));

    return (bSuccessReceiving && (zmq_message.size() > 0));
}
开发者ID:BugFreeSoftware,项目名称:Open-Transactions,代码行数:76,代码来源:OTSocket.cpp


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