本文整理汇总了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();
}