ACE_MESSAGE_BLOCK class
ACE_MESSAGE_BLOCK is used to encapsulate data between network hosts; and manage dynamic memory allocation.
Each ACE_MESSAGE_BLOCK object includes a "ACE_DATA_BLOCK pointer member with reference count", which points to actual data.
If multiple ACE_MESSAGE_BLOCKs are connected together (via the Composite mode), the "composite message" structure is formed.
Connect the plurality of messages to form a double-linked list, constitute the ACE_MESSAGE_QUEUE class, which is described later.
The member function of this class: RD_PTR () and WR_PTR () points to the head and tail of the movable portion of the data storage space, respectively.
Example: The program reads all the data in the standard input device to a single-linked list and is displayed on the standard output device.
#include "ace / OS.h" #include "ace / Message_Block.h" int main (int argc, char * argv []} {ACE_Message_Block * head = new ACE_Message_Block (BUFSIZ); ACE_Message_Block * mblk = head; for (; ;) {SSIZE_T NBYTES = ACE :: READ_N (ACE_STDIN, MBLK-> WR_PTR (), MBLK-> Size ()); if (nbytes <= 0) Break; // Break Out At Eof Or Error. // Advance THE Write pointer to the end of the buffer. mblk-> wr_ptr (nbytes); // allocate message block and chain it at the end of list. mblk-> cont (New ace_message_block (bufsiz)); MBLK = MBLK-> CONT );
// print the content, for (mblk = head; mblk! = 0; MBLK = MBLK-> Cont ()) ACE: Write_n (Acej3Tdout, MBLK-> RD_PTR (), MBLK-> Length ()); Head-> Release (); // this Release All the memory in the chain, returnograph;}
Where the cop () method is used to "connect the composite message".
NEXT () and prev () methods are used to set and get poins that point to the two-way linked list in "ACE_MESSAGE_QUEUE".
Simply: cont () uses with composite data, next () for ace_message_queue linked list (there is a bit not allowed to be, please enlighten)
ACE: READ_N and ACE :: Write_n encloses C "input / output stream" and the class has a platform-independent. If CIN and COUT are used, due to the "internal buffer" reason, additional data replication will be triggered.