diff options
author | bala <balanatarajan@users.noreply.github.com> | 2001-06-24 16:27:17 +0000 |
---|---|---|
committer | bala <balanatarajan@users.noreply.github.com> | 2001-06-24 16:27:17 +0000 |
commit | 6d08dada7e53cf332656492ad7d463f0a8b6203d (patch) | |
tree | 82b1d55735837c0e937a39899118ea65a3f6ca17 | |
parent | c563a80e36648099808a2e2ecc443be8c09842d2 (diff) | |
download | ATCD-6d08dada7e53cf332656492ad7d463f0a8b6203d.tar.gz |
ChangeLogTag: Sun Jun 24 11:25:07 2001 Balachandran Natarajan <bala@cs.wustl.edu>
-rw-r--r-- | ace/CDR_Stream.cpp | 46 | ||||
-rw-r--r-- | ace/Message_Block.cpp | 83 | ||||
-rw-r--r-- | ace/Message_Block.h | 16 |
3 files changed, 132 insertions, 13 deletions
diff --git a/ace/CDR_Stream.cpp b/ace/CDR_Stream.cpp index ad10c8a515e..75bf05efb43 100644 --- a/ace/CDR_Stream.cpp +++ b/ace/CDR_Stream.cpp @@ -607,7 +607,8 @@ ACE_InputCDR::ACE_InputCDR (ACE_Data_Block *data, ACE_InputCDR::ACE_InputCDR (const ACE_InputCDR& rhs, size_t size, ACE_CDR::Long offset) - : start_ (rhs.start_.data_block ()->duplicate ()), + : start_ (rhs.start_, + ACE_CDR::MAX_ALIGNMENT), do_byte_swap_ (rhs.do_byte_swap_), good_bit_ (1), char_translator_ (0), @@ -615,10 +616,16 @@ ACE_InputCDR::ACE_InputCDR (const ACE_InputCDR& rhs, major_version_ (rhs.major_version_), minor_version_ (rhs.minor_version_) { - char* newpos = rhs.start_.rd_ptr() + offset; - if (this->start_.base () <= newpos - && newpos <= this->start_.end () - && newpos + size <= this->start_.end ()) + // Align the base pointer assuming that the incoming stream is also + // aligned the way we are aligned + char *incoming_start = ACE_ptr_align_binary (rhs.start_.base (), + ACE_CDR::MAX_ALIGNMENT); + + size_t newpos = + (rhs.start_.rd_ptr() - incoming_start) + offset; + + if (newpos <= this->start_.size () + && newpos + size <= this->start_.size ()) { this->start_.rd_ptr (newpos); this->start_.wr_ptr (newpos + size); @@ -631,7 +638,8 @@ ACE_InputCDR::ACE_InputCDR (const ACE_InputCDR& rhs, ACE_InputCDR::ACE_InputCDR (const ACE_InputCDR& rhs, size_t size) - : start_ (rhs.start_.data_block ()->duplicate ()), + : start_ (rhs.start_, + ACE_CDR::MAX_ALIGNMENT), do_byte_swap_ (rhs.do_byte_swap_), good_bit_ (1), char_translator_ (0), @@ -639,10 +647,16 @@ ACE_InputCDR::ACE_InputCDR (const ACE_InputCDR& rhs, major_version_ (rhs.major_version_), minor_version_ (rhs.minor_version_) { - char* newpos = rhs.start_.rd_ptr(); - if (this->start_.base () <= newpos - && newpos <= this->start_.end () - && newpos + size <= this->start_.end ()) + // Align the base pointer assuming that the incoming stream is also + // aligned the way we are aligned + char *incoming_start = ACE_ptr_align_binary (rhs.start_.base (), + ACE_CDR::MAX_ALIGNMENT); + + size_t newpos = + rhs.start_.rd_ptr() - incoming_start; + + if (newpos <= this->start_.size () + && newpos + size <= this->start_.size ()) { // Notice that ACE_Message_Block::duplicate may leave the // wr_ptr() with a higher value that what we actually want. @@ -660,7 +674,8 @@ ACE_InputCDR::ACE_InputCDR (const ACE_InputCDR& rhs, } ACE_InputCDR::ACE_InputCDR (const ACE_InputCDR& rhs) - : start_ (rhs.start_.data_block ()->duplicate ()), + : start_ (rhs.start_, + ACE_CDR::MAX_ALIGNMENT), do_byte_swap_ (rhs.do_byte_swap_), good_bit_ (1), char_translator_ (rhs.char_translator_), @@ -668,8 +683,13 @@ ACE_InputCDR::ACE_InputCDR (const ACE_InputCDR& rhs) major_version_ (rhs.major_version_), minor_version_ (rhs.minor_version_) { - this->start_.rd_ptr (rhs.start_.rd_ptr ()); - this->start_.wr_ptr (rhs.start_.wr_ptr ()); + char *buf = ACE_ptr_align_binary (rhs.start_.base (), + ACE_CDR::MAX_ALIGNMENT); + + size_t rd_offset = rhs.start_.rd_ptr () - buf; + size_t wr_offset = rhs.start_.rd_ptr () - buf; + this->start_.rd_ptr (rd_offset); + this->start_.wr_ptr (wr_offset); } ACE_InputCDR::ACE_InputCDR (ACE_InputCDR::Transfer_Contents x) diff --git a/ace/Message_Block.cpp b/ace/Message_Block.cpp index 4d8d3473d5a..335004f9768 100644 --- a/ace/Message_Block.cpp +++ b/ace/Message_Block.cpp @@ -513,6 +513,89 @@ ACE_Message_Block::ACE_Message_Block (ACE_Data_Block *data_block, ACE_LIB_TEXT ("ACE_Message_Block"))); } +ACE_Message_Block::ACE_Message_Block (const ACE_Message_Block &mb, + size_t align) + :flags_ (0), + data_block_ (0) +{ + ACE_TRACE ("ACE_Message_Block::ACE_Message_Block"); + + if (ACE_BIT_DISABLED (mb.flags_, + ACE_Message_Block::DONT_DELETE)) + { + if (this->init_i (0, // size + MB_NORMAL, // type + 0, // cont + 0, // data + 0, // allocator + 0, // locking strategy + 0, // flags + 0, // priority + ACE_Time_Value::zero, // execution time + ACE_Time_Value::max_time, // absolute time of deadline + mb.data_block ()->duplicate (), // data block + mb.data_block ()->data_block_allocator (), + mb.message_block_allocator_) == -1) + ACE_ERROR ((LM_ERROR, + ACE_LIB_TEXT ("ACE_Message_Block"))); + + // Align ourselves + char *start = ACE_ptr_align_binary (this->base (), + align); + // Set our rd & wr pointers + this->rd_ptr (start); + this->wr_ptr (start); + + } + else + { + if (this->init_i (0, // size + MB_NORMAL, // type + 0, // cont + 0, // data + 0, // allocator + 0, // locking strategy + 0, // flags + 0, // priority + ACE_Time_Value::zero, // execution time + ACE_Time_Value::max_time, // absolute time of deadline + mb.data_block ()->clone_nocopy (),// data block + mb.data_block ()->data_block_allocator (), + mb.message_block_allocator_) == -1) + ACE_ERROR ((LM_ERROR, + ACE_LIB_TEXT ("ACE_Message_Block"))); + + // Align ourselves + char *start = ACE_ptr_align_binary (this->base (), + align); + // Set our rd & wr pointers + this->rd_ptr (start); + this->wr_ptr (start); + + // Get the alignment offset of the incoming ACE_Message_Block + start = ACE_ptr_align_binary (mb.base (), + align); + + + // Actual offset for the incoming message block assuming that it + // is also aligned to the same "align" byte + size_t wr_offset = mb.wr_ptr_ - (start - mb.base ()); + + // Copy wr_offset amount of data in to <this->data_block> + (void) ACE_OS::memcpy (this->wr_ptr (), + start, + wr_offset); + + // Dont move the write pointer, just leave it to the application + // to do what it wants + + } + + + + +} + int ACE_Message_Block::init_i (size_t size, ACE_Message_Type msg_type, diff --git a/ace/Message_Block.h b/ace/Message_Block.h index 04c0c8146a7..7633e8beb19 100644 --- a/ace/Message_Block.h +++ b/ace/Message_Block.h @@ -177,6 +177,20 @@ public: ACE_Allocator *message_block_allocator = 0); /** + * A copy constructor. This constructor is a bit different. If the + * incoming Message Block has a data block from the stack this + * constructor does a deep copy ie. allocates a new data block on + * the heap and does a copy of the data from the incoming message + * block. As a final note, the alignment information is used to + * align the data block if it is created afresh. If the incoming + * <mb> has a data block has a data block allocated from the heap, + * then this constructor just duplicates (ie. a shallow copy) the + * data block of the incoming <mb>. + */ + ACE_Message_Block (const ACE_Message_Block &mb, + size_t align); + + /** * Create a Message Block that assumes ownership of <data> (i.e., * doesn't delete it since it didn't malloc it!). Note that the * <size> of the <Message_Block> will be <size>, but the <length> @@ -291,6 +305,7 @@ public: /// Return a "shallow" copy that increments our reference count by 1. ACE_Message_Block *duplicate (void) const; + /** * Return a "shallow" copy that increments our reference count by 1. * This is similar to CORBA's <_duplicate> method, which is useful @@ -299,6 +314,7 @@ public: */ static ACE_Message_Block *duplicate (const ACE_Message_Block *mb); + /** * Decrease the shared ACE_Data_Block's reference count by 1. If the * ACE_Data_Block's reference count goes to 0, it is deleted. |