本文整理汇总了C++中NetBuffer::setReference方法的典型用法代码示例。如果您正苦于以下问题:C++ NetBuffer::setReference方法的具体用法?C++ NetBuffer::setReference怎么用?C++ NetBuffer::setReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetBuffer
的用法示例。
在下文中一共展示了NetBuffer::setReference方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createFragmentsFrom
bool IpPacketFragmentFeature::createFragmentsFrom(NetBuffer *inputBuffer,
const void *sourceData,
uint16_t sourceDataSize,
NetBuffer **outputBuffers,
uint16_t firstOutputBuffer,
bool lastFragmentIsHere,
uint16_t& offset) {
NetBuffer *nb;
uint16_t fragmentSize,flags;
const uint8_t *ptr;
ptr=reinterpret_cast<const uint8_t *>(sourceData);
while(sourceDataSize) {
// calculate sizes
fragmentSize=sourceDataSize<_mtu-IpPacketHeader::getNoOptionsHeaderSize() ?
sourceDataSize :
_mtu-IpPacketHeader::getNoOptionsHeaderSize();
// create a new netbuffer for the fragment
nb=new NetBuffer(_linkHeaderSize+IpPacketHeader::getNoOptionsHeaderSize(), // needs IP and link layer headers
0,
ptr, // fragment data starts here
fragmentSize); // size of this fragment
// more fragments flag if this is not the last in the run
if(lastFragmentIsHere && fragmentSize==sourceDataSize) {
// this is the last
flags=0;
nb->setReference(inputBuffer);
}
else
flags=MORE_FRAGMENTS;
// insert the IP fragment header
IpPacketHeader *header=reinterpret_cast<IpPacketHeader *>(nb->moveWritePointerBack(IpPacketHeader::getNoOptionsHeaderSize()));
// set up only the parts that are unique to the fragmenter
header->ip_hdr_length=NetUtil::htons(IpPacketHeader::getNoOptionsHeaderSize()+fragmentSize);
header->ip_hdr_identification=_identification;
header->ip_hdr_flagsAndOffset=NetUtil::htons((offset/8) | flags);
// store the netbuffer in the array
outputBuffers[firstOutputBuffer++]=nb;
// update pointers
ptr+=fragmentSize;
sourceDataSize-=fragmentSize;
offset+=fragmentSize;
}
return true;
}