00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Queued_Message.h 00006 * 00007 * Queued_Message.h,v 1.19 2006/04/19 09:06:37 jwillemsen Exp 00008 * 00009 * @author Carlos O'Ryan <coryan@uci.edu> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef TAO_QUEUED_MESSAGE_H 00014 #define TAO_QUEUED_MESSAGE_H 00015 00016 #include /**/ "ace/pre.h" 00017 00018 #include "tao/LF_Invocation_Event.h" 00019 #include "ace/os_include/os_stddef.h" 00020 00021 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00022 # pragma once 00023 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00024 00025 struct iovec; 00026 00027 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00028 class ACE_Message_Block; 00029 class ACE_Allocator; 00030 ACE_END_VERSIONED_NAMESPACE_DECL 00031 00032 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00033 00034 class TAO_ORB_Core; 00035 00036 /** 00037 * @class TAO_Queued_Message 00038 * 00039 * @brief Represent messages queued in the outgoing data path of the 00040 * TAO_Transport class. 00041 * 00042 * Please read the documentation in the TAO_Transport class to find 00043 * out more about the design of the outgoing data path. 00044 * 00045 * In some configurations TAO needs to maintain a per-connection queue 00046 * of outgoing messages. This queue is drained by the pluggable 00047 * protocols framework, normally under control of the ACE_Reactor, but 00048 * other configurations are conceivable. The elements in the queue 00049 * may be removed early, for example, because the application can 00050 * specify timeouts for each message, or because the underlying 00051 * connection is broken. 00052 * 00053 * In many cases the message corresponds to some application request, 00054 * the application may be blocked waiting for the request to be sent, 00055 * even more importantlyl, the ORB can be configured to use the 00056 * Leader/Followers strategy, in which case one of the waiting threads 00057 * can be required to wake up before its message completes 00058 * each message may contain a 'Sent_Notifier' 00059 * 00060 * <H4>NOTE:</H4> The contents of the ACE_Message_Block may have been 00061 * allocated from TSS storage, in that case we cannot steal them. 00062 * However, we do not need to perform a deep copy all the time, for 00063 * example, in a twoway request the sending thread blocks until the 00064 * data goes out. The queued message can borrow the memory as it will 00065 * be deallocated by the sending thread when it finishes. 00066 * Oneways and asynchronous calls are another story. 00067 * 00068 * @todo Change the ORB to allocate oneway and AMI buffer from global 00069 * memory, to avoid the data copy in this path. What happens 00070 * if the there is no queueing? Can we check that before 00071 * allocating the memory? 00072 * 00073 */ 00074 class TAO_Export TAO_Queued_Message : public TAO_LF_Invocation_Event 00075 { 00076 public: 00077 /// Constructor 00078 TAO_Queued_Message (TAO_ORB_Core *oc, 00079 ACE_Allocator *alloc = 0, 00080 bool is_heap_allocated = false); 00081 00082 /// Destructor 00083 virtual ~TAO_Queued_Message (void); 00084 00085 /** @name Intrusive list manipulation 00086 * 00087 * The messages are put in a doubled linked list (for easy insertion 00088 * and removal). To minimize memory allocations the list is 00089 * intrusive, i.e. each element in the list contains the pointers 00090 * for the next and previous element. 00091 * 00092 * The following methods are used to manipulate this implicit list. 00093 * 00094 * @todo We should implement this as a base template, something 00095 * like:<BR> 00096 * template<class T> Intrusive_Node {<BR> 00097 * public:<BR><BR> 00098 * void next (T *);<BR> 00099 * T* next () const;<BR><BR> 00100 * private:<BR> 00101 * T* next_;<BR> 00102 * };<BR> 00103 * and use it as follows:<BR> 00104 * class TAO_Queued_Message : public Intrusive_Node<TAO_Queued_Message><BR> 00105 * {<BR> 00106 * };<BR> 00107 * 00108 */ 00109 //@{ 00110 /// Set/get the next element in the list 00111 virtual TAO_Queued_Message *next (void) const; 00112 00113 /// Set/get the previous element in the list 00114 virtual TAO_Queued_Message *prev (void) const; 00115 00116 /// Remove this element from the list 00117 virtual void remove_from_list (TAO_Queued_Message *&head, 00118 TAO_Queued_Message *&tail); 00119 00120 /// Insert the current element at the tail of the queue. 00121 virtual void push_back (TAO_Queued_Message *&head, 00122 TAO_Queued_Message *&tail); 00123 00124 /// Insert the current element at the head of the queue. 00125 virtual void push_front (TAO_Queued_Message *&head, 00126 TAO_Queued_Message *&tail); 00127 //@} 00128 00129 /** @name Template Methods 00130 */ 00131 //@{ 00132 00133 /// Return the length of the message 00134 /** 00135 * If the message has been partially sent it returns the number of 00136 * bytes that are still not sent. 00137 */ 00138 virtual size_t message_length (void) const = 0; 00139 00140 /// Return 1 if all the data has been sent 00141 virtual int all_data_sent (void) const = 0; 00142 00143 /// Fill up an io vector using the connects of the message 00144 /** 00145 * Different versions of this class represent the message using 00146 * either a single buffer, or a message block. 00147 * This method allows a derived class to fill up the contents of an 00148 * io vector, the TAO_Transport class uses this method to group as 00149 * many messages as possible in an iovector before sending them to 00150 * the OS I/O subsystem. 00151 * 00152 * @param iovcnt_max The number of elements in iov 00153 * @param iovcnt The number of elements already used by iov, this 00154 * method should update this counter 00155 * @param iov The io vector 00156 */ 00157 virtual void fill_iov (int iovcnt_max, 00158 int &iovcnt, 00159 iovec iov[]) const = 0; 00160 00161 /// Update the internal state, data has been sent. 00162 /** 00163 * After the TAO_Transport class completes a successful (or 00164 * partially successful) I/O operation it must update the state of 00165 * all the messages queued. This callback method is used by each 00166 * message to update its state and determine if all the data has 00167 * been sent already. 00168 * 00169 * @param byte_count The number of bytes succesfully sent. The 00170 * TAO_Queued_Message should decrement this value 00171 * by the number of bytes that must still be sent. 00172 * @return Returns 1 if the TAO_Queued_Message has any more data to 00173 * send. 00174 */ 00175 virtual void bytes_transferred (size_t &byte_count) = 0; 00176 00177 /// Clone this element 00178 /* 00179 * Clone the element and return a pointer to the cloned element on 00180 * the heap. 00181 * 00182 * @param allocator Use the allocator for creating the new element 00183 * on the heap. Remember, that the allocator will 00184 * not be used allocate the data contained in this 00185 * element. 00186 */ 00187 virtual TAO_Queued_Message *clone (ACE_Allocator *allocator) = 0; 00188 00189 /// Reclaim resources 00190 /** 00191 * Reliable messages are allocated from the stack, thus they do not 00192 * be deallocated. 00193 * Asynchronous (SYNC_NONE) messages are allocated from the heap (or 00194 * a pool), they need to be reclaimed explicitly. 00195 */ 00196 virtual void destroy (void) = 0; 00197 //@} 00198 00199 protected: 00200 /* 00201 * Allocator that was used to create @c this object on the heap. If the 00202 * allocator is null then @a this is on stack. 00203 */ 00204 ACE_Allocator *allocator_; 00205 00206 /* 00207 * A flag to indicate whether @a this is on stack or heap. A true value 00208 * indicates that @a this was created on heap. 00209 */ 00210 bool is_heap_created_; 00211 00212 /// Cached copy of ORB_Core pointer 00213 TAO_ORB_Core *orb_core_; 00214 00215 private: 00216 /// Implement an intrusive double-linked list for the message queue 00217 TAO_Queued_Message *next_; 00218 TAO_Queued_Message *prev_; 00219 }; 00220 00221 TAO_END_VERSIONED_NAMESPACE_DECL 00222 00223 #include /**/ "ace/post.h" 00224 00225 #endif /* TAO_QUEUED_MESSAGE_H */