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


C++ ConnectionPtr::Receive方法代码示例

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


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

示例1: HandleRead

///////////////////////////////////////////////////////////////////////////////
/// CListener::HandleRead
/// @description The callback which accepts messages from the remote sender.
/// @param e The errorcode if any associated.
/// @param bytes_transferred The size of the datagram being read.
/// @pre The connection has had start called and some message has been placed
///   in the buffer by the receive call.
/// @post The message is scheduled for delivery by the dispatcher to one or
///     more modules. The message has been processed by the CConnection that
///     manages messages between this process and the sender. ScheduleListen()
///     is waiting for another datagram to arrive.
///////////////////////////////////////////////////////////////////////////////
void CListener::HandleRead(const boost::system::error_code& e,
                           std::size_t bytes_transferred)
{
    Logger.Trace << __PRETTY_FUNCTION__ << std::endl;

    if (e)
    {
        Logger.Error<<"HandleRead failed: " << e.message();
        ScheduleListen();
    }

    Logger.Debug<<"Loading protobuf"<<std::endl;
    ProtocolMessageWindow pmw;
    if(!pmw.ParseFromArray(m_buffer.begin(), bytes_transferred))
    {
        Logger.Error<<"Failed to load protobuf"<<std::endl;
        ScheduleListen();
        return;
    }

#ifdef CUSTOMNETWORK
    if((rand()%100) >= GetReliability())
    {
        Logger.Debug<<"Dropped datagram "<<pm.hash()<<":"<<pm.sequence_num()<<std::endl;
        ScheduleListen();
        return;
    }
#endif

    Logger.Debug<<"Fetching Connection"<<std::endl;
    std::string uuid = pmw.source_uuid();
    /// We can make the remote host from the endpoint:
    SRemoteHost host = { m_recv_from.address().to_string(), boost::lexical_cast<std::string>(m_recv_from.port()) };

    ///Make sure the hostname is registered:
    CConnectionManager::Instance().PutHost(uuid,host);

    ///Get the pointer to the connection:
    ConnectionPtr conn = CConnectionManager::Instance().CreateConnection(uuid, m_recv_from);
    //ConnectionPtr conn = CConnectionManager::Instance().GetConnectionByUUID(uuid);
    Logger.Debug<<"Fetched Connection"<<std::endl;

    BOOST_FOREACH(const ProtocolMessage &pm, pmw.messages())
    {
        if(pm.status() == ProtocolMessage::ACCEPTED)
        {
            Logger.Debug<<"Processing Accept Message"<<std::endl;
            Logger.Debug<<"Received ACK"<<pm.hash()<<":"<<pm.sequence_num()<<std::endl;
            conn->ReceiveACK(pm);
        }
        else if(conn->Receive(pm))
        {
            Logger.Debug<<"Accepted message "<<pm.hash()<<":"<<pm.sequence_num()<<std::endl;
            CDispatcher::Instance().HandleRequest(
                boost::make_shared<const ModuleMessage>(
                    ModuleMessage(pm.module_message())), uuid);
        }
        else if(pm.status() != ProtocolMessage::CREATED)
        {
            Logger.Debug<<"Rejected message "<<pm.hash()<<":"<<pm.sequence_num()<<std::endl;
        }
    }
    conn->OnReceive();
    ScheduleListen();
}
开发者ID:FREEDM-DGI,项目名称:FREEDM,代码行数:77,代码来源:CListener.cpp


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