本文整理汇总了C++中Header::SetMessageId方法的典型用法代码示例。如果您正苦于以下问题:C++ Header::SetMessageId方法的具体用法?C++ Header::SetMessageId怎么用?C++ Header::SetMessageId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Header
的用法示例。
在下文中一共展示了Header::SetMessageId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SendEmptyMessage
void Client::SendEmptyMessage(const Ip6::Address &aAddress, uint16_t aPort, uint16_t aMessageId, Header::Type aType)
{
Header header;
Ip6::MessageInfo messageInfo;
Message *message;
ThreadError error = kThreadError_None;
header.Init(aType, kCoapCodeEmpty);
header.SetMessageId(aMessageId);
VerifyOrExit((message = NewMessage(header)) != NULL, ;);
示例2: SendMessage
ThreadError Client::SendMessage(Message &aMessage, const Ip6::MessageInfo &aMessageInfo,
otCoapResponseHandler aHandler, void *aContext)
{
ThreadError error;
Header header;
RequestMetadata requestMetadata;
Message *storedCopy = NULL;
uint16_t copyLength = 0;
SuccessOrExit(error = header.FromMessage(aMessage));
// Set Message Id if it was not already set.
if (header.GetMessageId() == 0)
{
header.SetMessageId(mMessageId++);
aMessage.Write(0, Header::kMinHeaderLength, header.GetBytes());
}
if (header.IsConfirmable())
{
// Create a copy of entire message and enqueue it.
copyLength = aMessage.GetLength();
}
else if (header.IsNonConfirmable() && header.IsRequest() && (aHandler != NULL))
{
// As we do not retransmit non confirmable messages, create a copy of header only, for token information.
copyLength = header.GetLength();
}
if (copyLength > 0)
{
requestMetadata = RequestMetadata(header.IsConfirmable(), aMessageInfo, aHandler, aContext);
VerifyOrExit((storedCopy = CopyAndEnqueueMessage(aMessage, copyLength, requestMetadata)) != NULL,
error = kThreadError_NoBufs);
}
SuccessOrExit(error = mSocket.SendTo(aMessage, aMessageInfo));
exit:
if (error != kThreadError_None && storedCopy != NULL)
{
DequeueMessage(*storedCopy);
}
return error;
}