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


C++ NetworkMessage::parse_network_packet方法代码示例

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


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

示例1: newsoul

void
newsoul::DistributedSocket::onMessageReceived(const MessageData * data)
{
    if (m_DataTimeout.isValid())
        newsoul()->reactor()->removeTimeout(m_DataTimeout);

  switch(data->type)
  {
    #define MAP_MESSAGE(ID, TYPE, EVENT) \
      case ID: \
      { \
        NNLOG("newsoul.messages.distributed", "Received distributed message " #TYPE "."); \
        TYPE msg; \
        msg.setDistributedSocket(this); \
        msg.parse_network_packet(data->data, data->length); \
        EVENT(&msg); \
        break; \
      }
    #include "distributedeventtable.h"
    #undef MAP_MESSAGE

    default:
        NNLOG("newsoul.distrib.warn", "Received unknown distributed message, type: %u, length: %u", data->type, data->length);
        NetworkMessage msg;
        msg.parse_network_packet(data->data, data->length);
  }
}
开发者ID:KenjiTakahashi,项目名称:newsoul,代码行数:27,代码来源:distributedsocket.cpp

示例2: if

void
newsoul::HandshakeSocket::onMessageReceived(const MessageData * data)
{
  switch(data->type)
  {
    case 0:
    {
      // Apparently, we requested somebody to connect to us.
      NNLOG("newsoul.messages.handshake", "Received peer handshake message HPierceFirewall");
      HPierceFirewall msg;
      msg.parse_network_packet(data->data, data->length);
      m_Token = msg.token;
      receiveBuffer().seek(data->length + 5);
      // Tell the peer manager, it should know more.
      m_Newsoul->peers()->firewallPiercedEvent(this);
      // This particular socket is no longer needed. Remove it from the reactor.
      reactor()->remove(this);
      return;
    }
    case 1:
    {
      // Somebody wants to establish a connection.
      NNLOG("newsoul.messages.handshake", "Received peer handshake message HInitiate");
      HInitiate msg;
      msg.parse_network_packet(data->data, data->length);
      NNLOG("newsoul.hand.debug", "HInitiate payload: %s %s %u", msg.user.c_str(), msg.type.c_str(), msg.token);
      // Set some variables.
      m_Token = msg.token;
      m_User = msg.user;
      // Seek past the message.
      if (receiveBuffer().count() >= data->length + 5)
        receiveBuffer().seek(data->length + 5);
      else
        receiveBuffer().clear();
      if(msg.type == "P")
      {
        // Create a new PeerSocket which will copy our descriptor and state.
        newsoul::PeerSocket * that = new newsoul::PeerSocket(this);
        newsoul()->peers()->addPeerSocket(that);
        // Add the newly constructed socket to the reactor.
        reactor()->add(that);
      }
      else if(msg.type == "F")
      {
        // Create a new TicketSocket which will copy our descriptor and state.
        newsoul::TicketSocket * that = new newsoul::TicketSocket(this);
        // Add the newly constructed socket to the reactor.
        reactor()->add(that);
        // There may be some data waiting in the buffer (sent at connection). We have to ask the ticketsocket to check it.
        that->findTicket();
      }
      else if(msg.type == "D")
      {
        // Create a new DistributedSocket which will copy our descriptor and state.
        newsoul::DistributedSocket * that = new newsoul::DistributedSocket(this);
        // A potential parent doesn't care about our position
        if (!newsoul()->searches()->isPotentialParent(m_User))
            that->sendPosition();
        // Add the newly constructed socket to the reactor.
        reactor()->add(that);
      }
      else
      {
        NNLOG("newsoul.hand.warn", "Invalid incoming connection type '%s'.", msg.type.c_str());
      }
      // Clear our receive buffer so we stop processing data.
      receiveBuffer().clear();
      // Remove this socket from the reactor as it's no longer needed.
      reactor()->remove(this);
      return;
    }
    default:
        NNLOG("newsoul.hand.warn", "Received unknown peer handshake message, type: %u, length: %u", data->type, data->length);
        NetworkMessage msg;
        msg.parse_network_packet(data->data, data->length);
  }
}
开发者ID:KenjiTakahashi,项目名称:newsoul,代码行数:77,代码来源:handshakesocket.cpp


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