summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ace/Message_Block.cpp17
-rw-r--r--ace/Message_Block.h35
-rw-r--r--ace/Message_Block.i30
3 files changed, 75 insertions, 7 deletions
diff --git a/ace/Message_Block.cpp b/ace/Message_Block.cpp
index 00d49cd725f..ff5e761ef86 100644
--- a/ace/Message_Block.cpp
+++ b/ace/Message_Block.cpp
@@ -250,6 +250,23 @@ ACE_Message_Block::total_length (void) const
return length;
}
+size_t
+ACE_Message_Block::total_capacity (void) const
+{
+ ACE_TRACE ("ACE_Message_Block::total_size");
+
+ size_t size = 0;
+
+ for (const ACE_Message_Block *i = this;
+ i != 0;
+ i = i->cont ())
+ {
+ size += i->capacity ();
+ }
+
+ return size;
+}
+
ACE_Data_Block::ACE_Data_Block (void)
: type_ (ACE_Message_Block::MB_DATA),
cur_size_ (0),
diff --git a/ace/Message_Block.h b/ace/Message_Block.h
index ba92c88d3b3..ea520e5b157 100644
--- a/ace/Message_Block.h
+++ b/ace/Message_Block.h
@@ -291,6 +291,9 @@ public:
// method succeeds. Returns -1 if the size of the message is too
// small, i.e., for this to work correct, <end> must be >= <wr_ptr>.
+ void crunch (void);
+ // Normalizes data in the top-level <Message_Block> to align with the base.
+
char *base (void) const;
// Get message data.
@@ -300,7 +303,12 @@ public:
// Set message data (doesn't reallocate).
char *end (void) const;
- // Return a pointer to 1 past the end of the data in a message.
+ // Return a pointer to 1 past the end of the allocated data in a message.
+
+ char *mark (void) const;
+ // Return a pointer to 1 past the end of the allotted data in a message.
+ // Allotted data may be less than allocated data if a value smaller than
+ // capacity() to is passed to size().
char *rd_ptr (void) const;
// Get the read pointer.
@@ -341,13 +349,17 @@ public:
// <wr_ptr_> remain at the original offsets into the buffer, even if
// it is reallocated. Returns 0 if successful, else -1.
+ size_t total_capacity (void) const;
+ // Get the number of allocated bytes in all <Message_Block>, including
+ // chained <Message_Block>s.
+
+ size_t capacity (void) const;
+ // Get the number of allocated bytes in the top-level <Message_Block>.
+
size_t space (void) const;
// Get the number of bytes available after the <wr_ptr_> in the
// top-level <Message_Block>.
- void crunch (void);
- // Normalizes data in message block to align with the base.
-
// = <ACE_Data_Block> methods.
ACE_Data_Block *data_block (void) const;
// Get the data block.
@@ -508,15 +520,26 @@ public:
// Set message data pointer (doesn't reallocate).
char *end (void) const;
- // Return a pointer to 1 past the end of the data in a message.
+ // Return a pointer to 1 past the end of the allocated data in a message.
+
+ char *mark (void) const;
+ // Return a pointer to 1 past the end of the allotted data in a message.
+ // The allotted data may be less than allocated data if <size()> is passed
+ // an argument less than <capacity()>.
// = Message size is the total amount of space alloted.
+
size_t size (void) const;
- // Get the total amount of space in the message.
+ // Get the total amount of allotted space in the message. The amount of
+ // allotted space may be less than allocated space.
+
int size (size_t length);
// Set the total amount of space in the message. Returns 0 if
// successful, else -1.
+ size_t capacity (void) const;
+ // Get the total amount of allocated space.
+
virtual ACE_Data_Block *clone (ACE_Message_Block::Message_Flags mask = 0) const;
// Return an exact "deep copy" of the message, i.e., create fresh
// new copies of all the Data_Blocks and continuations.
diff --git a/ace/Message_Block.i b/ace/Message_Block.i
index 830a3ad5c49..fc076f55a0e 100644
--- a/ace/Message_Block.i
+++ b/ace/Message_Block.i
@@ -38,6 +38,13 @@ ACE_Data_Block::size (void) const
return this->cur_size_;
}
+ACE_INLINE size_t
+ACE_Data_Block::capacity (void) const
+{
+ ACE_TRACE ("ACE_Data_Block::capacity");
+ return this->max_size_;
+}
+
ACE_INLINE ACE_Message_Block::Message_Flags
ACE_Data_Block::set_flags (ACE_Message_Block::Message_Flags more_flags)
{
@@ -119,6 +126,13 @@ ACE_Message_Block::size (void) const
return this->data_block ()->size ();
}
+ACE_INLINE size_t
+ACE_Message_Block::capacity (void) const
+{
+ ACE_TRACE ("ACE_Message_Block::capacity");
+ return this->data_block ()->capacity ();
+}
+
ACE_INLINE ACE_Message_Block::ACE_Message_Type
ACE_Data_Block::msg_type (void) const
{
@@ -249,6 +263,20 @@ ACE_Message_Block::wr_ptr (char *new_ptr)
// Return a pointer to 1 past the end of the data buffer.
ACE_INLINE char *
+ACE_Data_Block::mark (void) const
+{
+ ACE_TRACE ("ACE_Data_Block::mark");
+ return this->base_ + this->cur_size_;
+}
+
+ACE_INLINE char *
+ACE_Message_Block::mark (void) const
+{
+ ACE_TRACE ("ACE_Message_Block::mark");
+ return this->data_block ()->mark ();
+}
+
+ACE_INLINE char *
ACE_Data_Block::end (void) const
{
ACE_TRACE ("ACE_Data_Block::end");
@@ -295,7 +323,7 @@ ACE_INLINE size_t
ACE_Message_Block::space (void) const
{
ACE_TRACE ("ACE_Message_Block::space");
- return this->end () - this->wr_ptr ();
+ return this->mark () - this->wr_ptr ();
}
ACE_INLINE ACE_Data_Block *