diff options
author | Steve Huston <shuston@riverace.com> | 2006-12-11 20:23:51 +0000 |
---|---|---|
committer | Steve Huston <shuston@riverace.com> | 2006-12-11 20:23:51 +0000 |
commit | 128354217763fb3f6c76739718421099faa920e7 (patch) | |
tree | 1c1e265807dc85799a98e54a495a02a343ae0b87 /ACE/ace/CDR_Stream.cpp | |
parent | 39db6c29c279fe07771e073e39378a4fed41875a (diff) | |
download | ATCD-128354217763fb3f6c76739718421099faa920e7.tar.gz |
ChangeLogTag:Mon Dec 11 20:21:14 UTC 2006 Steve Huston <shuston@riverace.com>
Diffstat (limited to 'ACE/ace/CDR_Stream.cpp')
-rw-r--r-- | ACE/ace/CDR_Stream.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/ACE/ace/CDR_Stream.cpp b/ACE/ace/CDR_Stream.cpp index 516e4fd2c63..b033d8a1587 100644 --- a/ACE/ace/CDR_Stream.cpp +++ b/ACE/ace/CDR_Stream.cpp @@ -677,6 +677,51 @@ ACE_OutputCDR::write_boolean_array (const ACE_CDR::Boolean* x, return this->good_bit (); } + +int +ACE_OutputCDR::consolidate (void) +{ + // Optimize by only doing something if we need to + if (this->current_ != &this->start_) + { + // Set the number of bytes in the top-level block, reallocating + // if necessary. The rd_ptr and wr_ptr remain at the original offsets + // into the buffer, even if it is reallocated. + // Return an error if the allocation failed. + size_t newsize = + ACE_CDR::first_size (this->total_length () + + ACE_CDR::MAX_ALIGNMENT); + if (this->start_.size (newsize) < 0) + { + return -1; + } + + // Consolidate the chain into the first block. NOTE that + // ACE_CDR::consolidate can not be used since we don't want to + // overwrite what is already in the first block. We just append it since + // the read and write pointers weren't affected by the resizing above. + // We also don't have to worry about alignment since the start block is + // already aligned. + // NOTE also we know there is a continuation since we checked for it + // above. There is therefore no reason to check for a 0 continuation + // field here. + ACE_Message_Block *cont = this->start_.cont (); + for (const ACE_Message_Block* i = cont; i != 0; i = i->cont ()) + { + this->start_.copy (i->rd_ptr (), i->length ()); + } + + // Release the old blocks that were consolidated and reset the + // current_ and current_is_writable_ to reflect the single used block. + ACE_Message_Block::release (cont); + this->start_.cont (0); + this->current_ = &this->start_; + this->current_is_writable_ = true; + } + + return 0; +} + ACE_Message_Block* ACE_OutputCDR::find (char* loc) |