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


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

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


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

示例1: AllocateNewMessage

NetworkMessage *MessageConnection::StartNewMessage(unsigned long id, size_t numBytes)
{
    NetworkMessage *msg = AllocateNewMessage();
    if (!msg)
    {
        LOG(LogError, "MessageConnection::SendMessage: StartNewMessage failed! Discarding message send.");
        return 0; // Failed to allocate a new message. This is caused only by memory allocation issues.
    }

    msg->id = id;
    msg->reliable = false;
    msg->contentID = 0;
    msg->obsolete = false;

    // Give the new message the lowest priority by default.
    msg->priority = 0;

    // By default, the message is not fragmented. Later when admitting the message into the send queue, the need for
    // fragmentation is examined and this field will be updated if needed.
    msg->transfer = 0;

#ifdef KNET_NETWORK_PROFILING
    msg->profilerName = "";
#endif

    msg->Resize(numBytes);

    return msg;
}
开发者ID:r8d8,项目名称:Urho3D,代码行数:29,代码来源:MessageConnection.cpp

示例2: HandleInboundMessage

void MessageConnection::HandleInboundMessage(packet_id_t packetID, const char *data, size_t numBytes)
{
    AssertInWorkerThreadContext();

    if (!socket)
        return; // Ignore all messages from connections that have already died.

    assert(data && numBytes > 0);

    // Read the message ID.
    DataDeserializer reader(data, numBytes);
    message_id_t messageID = reader.ReadVLE<VLE8_16_32>(); ///\todo Check that there actually is enough space to read.
    if (messageID == DataDeserializer::VLEReadError)
    {
        LOG(LogError, "Error parsing messageID of a message in socket %s. Data size: %d bytes.", socket->ToString().c_str(), (int)numBytes);
        throw NetException("MessageConnection::HandleInboundMessage: Network error occurred when deserializing message ID VLE field!");
    }
    LOG(LogData, "Received message with ID %d and size %d from peer %s.", (int)packetID, (int)numBytes, socket->ToString().c_str());

    char str[256];
    sprintf(str, "messageIn.%u", (unsigned int)messageID);
    ADDEVENT(str, (float)reader.BytesLeft(), "bytes");

    // Pass the message to TCP/UDP -specific message handler.
    bool childHandledMessage = HandleMessage(packetID, messageID, data + reader.BytePos(), reader.BytesLeft());
    if (childHandledMessage)
        return; // If the derived class handled the message, no need to propagate it further.

    switch(messageID)
    {
    case MsgIdPingRequest:
        HandlePingRequestMessage(data + reader.BytePos(), reader.BytesLeft());
        break;
    case MsgIdPingReply:
        HandlePingReplyMessage(data + reader.BytePos(), reader.BytesLeft());
        break;
    default:
    {
        NetworkMessage *msg = AllocateNewMessage();
        msg->Resize(numBytes);
        assert(reader.BitPos() == 0);
        memcpy(msg->data, data + reader.BytePos(), reader.BytesLeft());
        msg->dataSize = reader.BytesLeft();
        msg->id = messageID;
        msg->contentID = 0;
        msg->receivedPacketID = packetID;
        bool success = inboundMessageQueue.Insert(msg);
        if (!success)
        {
            LOG(LogError, "Failed to add a new message of ID %d and size %dB to inbound queue! Queue was full.",
                (int)messageID, (int)msg->dataSize);
            FreeMessage(msg);
        }
    }
    break;
    }
}
开发者ID:r8d8,项目名称:Urho3D,代码行数:57,代码来源:MessageConnection.cpp


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