TAO_Asynch_Queued_Message Class Reference

Specialize TAO_Queued_Message for asynch requests, i.e. oneways sent with SYNC_NONE policy. More...

#include <Asynch_Queued_Message.h>

Inheritance diagram for TAO_Asynch_Queued_Message:

Inheritance graph
[legend]
Collaboration diagram for TAO_Asynch_Queued_Message:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TAO_Asynch_Queued_Message (const ACE_Message_Block *contents, TAO_ORB_Core *oc, ACE_Allocator *alloc=0, bool is_heap_allocated=false)
 Constructor.

virtual ~TAO_Asynch_Queued_Message (void)
 Destructor.

Implement the Template Methods from TAO_Queued_Message
virtual size_t message_length (void) const
 Return the length of the message.

virtual int all_data_sent (void) const
 Return 1 if all the data has been sent.

virtual void fill_iov (int iovcnt_max, int &iovcnt, iovec iov[]) const
 Fill up an io vector using the connects of the message.

virtual void bytes_transferred (size_t &byte_count)
 Update the internal state, data has been sent.

virtual TAO_Queued_Messageclone (ACE_Allocator *alloc)
virtual void destroy (void)
 Reclaim resources.


Protected Member Functions

 TAO_Asynch_Queued_Message (char *buf, TAO_ORB_Core *oc, size_t size, ACE_Allocator *alloc=0)
 Constructor.


Private Attributes

const size_t size_
 The number of bytes in the buffer.

size_t offset_
 The offset in the buffer.

char * buffer_
 The buffer containing the complete message.


Detailed Description

Specialize TAO_Queued_Message for asynch requests, i.e. oneways sent with SYNC_NONE policy.

Definition at line 33 of file Asynch_Queued_Message.h.


Constructor & Destructor Documentation

TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_Asynch_Queued_Message::TAO_Asynch_Queued_Message const ACE_Message_Block contents,
TAO_ORB_Core oc,
ACE_Allocator alloc = 0,
bool  is_heap_allocated = false
 

Constructor.

Parameters:
contents The message block chain that must be sent.
alloc Allocator used for creating this object.

Todo:
I'm almost sure this class will require a callback interface for AMIs sent with SYNC_NONE policy. Those guys need to hear when the connection timeouts or closes, but cannot block waiting for the message to be delivered.

Definition at line 19 of file Asynch_Queued_Message.cpp.

References ACE_NEW, ACE_Message_Block::cont(), ACE_Message_Block::length(), ACE_OS::memcpy(), and ACE_Message_Block::rd_ptr().

Referenced by clone().

00024   : TAO_Queued_Message (oc, alloc, is_heap_allocated)
00025   , size_ (contents->total_length ())
00026   , offset_ (0)
00027 {
00028   // @@ Use a pool for these guys!!
00029   ACE_NEW (this->buffer_, char[this->size_]);
00030 
00031   size_t copy_offset = 0;
00032   for (const ACE_Message_Block *i = contents;
00033        i != 0;
00034        i = i->cont ())
00035     {
00036       ACE_OS::memcpy (this->buffer_ + copy_offset,
00037                       i->rd_ptr (),
00038                       i->length ());
00039       copy_offset += i->length ();
00040     }
00041 }

TAO_Asynch_Queued_Message::~TAO_Asynch_Queued_Message void   )  [virtual]
 

Destructor.

Definition at line 54 of file Asynch_Queued_Message.cpp.

00055 {
00056   // @@ Use a pool for these guys!
00057   delete [] this->buffer_;
00058 }

TAO_Asynch_Queued_Message::TAO_Asynch_Queued_Message char *  buf,
TAO_ORB_Core oc,
size_t  size,
ACE_Allocator alloc = 0
[protected]
 

Constructor.

Parameters:
buf The buffer that needs to be sent on the wire. The buffer will be owned by this class. The buffer will be deleted when the destructor is called and hence the buffer should always come off the heap!
size The size of the buffer that is being handed over.
alloc Allocator used for creating object.

Definition at line 43 of file Asynch_Queued_Message.cpp.

00047   : TAO_Queued_Message (oc, alloc)
00048   , size_ (size)
00049   , offset_ (0)
00050   , buffer_ (buf)
00051 {
00052 }


Member Function Documentation

int TAO_Asynch_Queued_Message::all_data_sent void   )  const [virtual]
 

Return 1 if all the data has been sent.

Implements TAO_Queued_Message.

Definition at line 67 of file Asynch_Queued_Message.cpp.

Referenced by bytes_transferred().

00068 {
00069   return this->size_ == this->offset_;
00070 }

void TAO_Asynch_Queued_Message::bytes_transferred size_t &  byte_count  )  [virtual]
 

Update the internal state, data has been sent.

After the TAO_Transport class completes a successful (or partially successful) I/O operation it must update the state of all the messages queued. This callback method is used by each message to update its state and determine if all the data has been sent already.

Parameters:
byte_count The number of bytes succesfully sent. The TAO_Queued_Message should decrement this value by the number of bytes that must still be sent.
Returns:
Returns 1 if the TAO_Queued_Message has any more data to send.

Implements TAO_Queued_Message.

Definition at line 86 of file Asynch_Queued_Message.cpp.

References all_data_sent(), TAO_LF_Event::state_changed(), and TAO_LF_Invocation_Event::state_changed_i().

00087 {
00088   this->state_changed_i (TAO_LF_Event::LFS_ACTIVE);
00089 
00090   size_t const remaining_bytes = this->size_ - this->offset_;
00091   if (byte_count > remaining_bytes)
00092     {
00093       this->offset_ = this->size_;
00094       byte_count -= remaining_bytes;
00095       return;
00096     }
00097   this->offset_ += byte_count;
00098   byte_count = 0;
00099 
00100   if (this->all_data_sent ())
00101     this->state_changed (TAO_LF_Event::LFS_SUCCESS,
00102                          this->orb_core_->leader_follower ());
00103 }

TAO_Queued_Message * TAO_Asynch_Queued_Message::clone ACE_Allocator alloc  )  [virtual]
 

Note:
No reason to believe why this would be called. But have it here for the sake of uniformity.

Implements TAO_Queued_Message.

Definition at line 107 of file Asynch_Queued_Message.cpp.

References ACE_DEBUG, ACE_NEW_MALLOC_RETURN, ACE_NEW_RETURN, TAO_Queued_Message::is_heap_created_, LM_DEBUG, ACE_Allocator::malloc(), ACE_OS::memcpy(), TAO_Asynch_Queued_Message(), and TAO_debug_level.

00108 {
00109   char *buf = 0;
00110 
00111   // @@todo: Need to use a memory pool. But certain things need to
00112   // change a bit in this class for that. Till then.
00113 
00114   // Just allocate and copy data that needs to be sent, no point
00115   // copying the whole buffer.
00116   size_t const sz = this->size_ - this->offset_;
00117 
00118   ACE_NEW_RETURN (buf,
00119                   char[sz],
00120                   0);
00121 
00122   ACE_OS::memcpy (buf,
00123                   this->buffer_ + this->offset_,
00124                   sz);
00125 
00126   TAO_Asynch_Queued_Message *qm = 0;
00127 
00128   if (alloc)
00129     {
00130       ACE_NEW_MALLOC_RETURN (qm,
00131                              static_cast<TAO_Asynch_Queued_Message *> (
00132                                  alloc->malloc (sizeof (TAO_Asynch_Queued_Message))),
00133                              TAO_Asynch_Queued_Message (buf,
00134                                                         this->orb_core_,
00135                                                         sz,
00136                                                         alloc),
00137                              0);
00138     }
00139   else
00140     {
00141       // No allocator, so use the common heap!
00142       if (TAO_debug_level == 4)
00143         {
00144           // This debug is for testing purposes!
00145           ACE_DEBUG ((LM_DEBUG,
00146                       "TAO (%P|%t) - Asynch_Queued_Message::clone\n"
00147                       "Using global pool for allocation \n"));
00148         }
00149 
00150       ACE_NEW_RETURN (qm,
00151                       TAO_Asynch_Queued_Message (buf,
00152                                                  this->orb_core_,
00153                                                  sz),
00154                       0);
00155     }
00156 
00157   // Set the flag to indicate that <qm> is created on the heap.
00158   if (qm)
00159     qm->is_heap_created_ = true;
00160 
00161   return qm;
00162 }

void TAO_Asynch_Queued_Message::destroy void   )  [virtual]
 

Reclaim resources.

Reliable messages are allocated from the stack, thus they do not be deallocated. Asynchronous (SYNC_NONE) messages are allocated from the heap (or a pool), they need to be reclaimed explicitly.

Implements TAO_Queued_Message.

Definition at line 165 of file Asynch_Queued_Message.cpp.

References ACE_DES_FREE.

00166 {
00167   if (this->is_heap_created_)
00168     {
00169       // If we have an allocator release the memory to the allocator
00170       // pool.
00171       if (this->allocator_)
00172         {
00173           ACE_DES_FREE (this,
00174                         this->allocator_->free,
00175                         TAO_Asynch_Queued_Message);
00176 
00177         }
00178       else // global release..
00179         {
00180           delete this;
00181         }
00182     }
00183 
00184 }

void TAO_Asynch_Queued_Message::fill_iov int  iovcnt_max,
int &  iovcnt,
iovec  iov[]
const [virtual]
 

Fill up an io vector using the connects of the message.

Different versions of this class represent the message using either a single buffer, or a message block. This method allows a derived class to fill up the contents of an io vector, the TAO_Transport class uses this method to group as many messages as possible in an iovector before sending them to the OS I/O subsystem.

Parameters:
iovcnt_max The number of elements in iov
iovcnt The number of elements already used by iov, this method should update this counter
iov The io vector

Implements TAO_Queued_Message.

Definition at line 73 of file Asynch_Queued_Message.cpp.

References ACE_ASSERT, iovec::iov_base, and iovec::iov_len.

00076 {
00077   ACE_ASSERT (iovcnt_max > iovcnt);
00078   ACE_UNUSED_ARG (iovcnt_max); // not used if ACE_ASSERT() is empty
00079 
00080   iov[iovcnt].iov_base = this->buffer_ + this->offset_;
00081   iov[iovcnt].iov_len  = static_cast<u_long> (this->size_ - this->offset_);
00082   ++iovcnt;
00083 }

size_t TAO_Asynch_Queued_Message::message_length void   )  const [virtual]
 

Return the length of the message.

If the message has been partially sent it returns the number of bytes that are still not sent.

Implements TAO_Queued_Message.

Definition at line 61 of file Asynch_Queued_Message.cpp.

00062 {
00063   return this->size_ - this->offset_;
00064 }


Member Data Documentation

char* TAO_Asynch_Queued_Message::buffer_ [private]
 

The buffer containing the complete message.

Definition at line 99 of file Asynch_Queued_Message.h.

size_t TAO_Asynch_Queued_Message::offset_ [private]
 

The offset in the buffer.

Data up to offset has been sent already, only the [offset_,size_) range remains to be sent.

Definition at line 96 of file Asynch_Queued_Message.h.

const size_t TAO_Asynch_Queued_Message::size_ [private]
 

The number of bytes in the buffer.

Definition at line 89 of file Asynch_Queued_Message.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 12:12:16 2006 for TAO by doxygen 1.3.6