|
楼主 |
发表于 2008-3-8 22:04:08
|
显示全部楼层
ACE_OutputCDR ocr(mblk);
和你想象的有差别,这里没有写入mblk,你跟踪一下代码就知道了。
默认是写入另外的地方,做了内部连接。需要复制出来。
int
ACE_OutputCDR::grow_and_adjust (size_t size,
size_t align,
char*& buf)
{
if (!this->current_is_writable_
|| this->current_->cont () == 0
|| this->current_->cont ()->size () < size + ACE_CDR::MAX_ALIGNMENT)
{
// Calculate the new buffer's length; if growing for encode, we
// don't grow in "small" chunks because of the cost.
size_t cursize = this->current_->size ();
if (this->current_->cont () != 0)
cursize = this->current_->cont ()->size ();
size_t minsize = size;
#if !defined (ACE_LACKS_CDR_ALIGNMENT)
minsize += ACE_CDR::MAX_ALIGNMENT;
#endif /* ACE_LACKS_CDR_ALIGNMENT */
// Make sure that there is enough room for <minsize> bytes, but
// also make it bigger than whatever our current size is.
if (minsize < cursize)
minsize = cursize;
const size_t newsize = ACE_CDR::next_size (minsize);
this->good_bit_ = false;
ACE_Message_Block* tmp;
ACE_NEW_RETURN (tmp,
ACE_Message_Block (newsize,
ACE_Message_Block::MB_DATA,
0,
0,
this->current_->data_block ()->allocator_strategy (),
0,
0,
ACE_Time_Value::zero,
ACE_Time_Value::max_time,
this->current_->data_block ()->data_block_allocator ()),
-1);
this->good_bit_ = true;
#if !defined (ACE_LACKS_CDR_ALIGNMENT)
// The new block must start with the same alignment as the
// previous block finished.
ptrdiff_t tmpalign =
ptrdiff_t(tmp->rd_ptr ()) % ACE_CDR::MAX_ALIGNMENT;
ptrdiff_t curalign =
ptrdiff_t(this->current_alignment_) % ACE_CDR::MAX_ALIGNMENT;
ptrdiff_t offset = curalign - tmpalign;
if (offset < 0)
offset += ACE_CDR::MAX_ALIGNMENT;
tmp->rd_ptr (static_cast<size_t> (offset));
tmp->wr_ptr (tmp->rd_ptr ());
#endif /* ACE_LACKS_CDR_ALIGNMENT */
// grow the chain and set the current block.
tmp->cont (this->current_->cont ());
this->current_->cont (tmp);
}
this->current_ = this->current_->cont ();
this->current_is_writable_ = true;
return this->adjust (size, align, buf);
} |
|