您的位置:首页 > 编程语言 > PHP开发

ACE_Mesaage_Block,ACE_InputCdr,ACE_OutputCdr的使用

2016-01-01 11:55 681 查看
The ACE_Message_Block class enables efficient manipulation of fixed- and variable-sized messages. ACE_Message_Block implements
the Composite pattern [GHJV95] and provides the following capabilities:

Each ACE_Message_Block contains a pointer to a reference-counted ACE_Data_Block,
which in turn points to the actual data associated with a message. This design allows flexible and efficient sharing of data and minimizes excessive memory copying overhead.

It allows multiple messages to be chained together into a singly linked list to support composite messages, which can be used for polymorphic lists and for layered protocol stacks that require headers/trailers to be inserted/removed efficiently.

It allows multiple messages to be joined together in a doubly linked list that forms the basis of the ACE_Message_Queue class outlined
on page 228 and described in [SH].

It treats synchronization and memory management properties as aspects [Kic97, CE00]
that applications can vary without changing the underlying ACE_Message_Block implementation.

The ACE_Message_Block Class Diagram



照片名称:Two Kinds of ACE_Message_Block



 ACE_Message_Block 
一般和 ACE_InputCdr,ACE_outputCdr 结合使用,以下是使用的一些方法:

//mb = new ACE_Message_Block();

 //ACE_CDR::mb_align(mb);

 /*ACE_OutputCDR cdr(mb->wr_ptr(),ACE_CDR::MAX_ALIGNMENT+8);*/ //这种方法不对

 ACE_OutputCDR cdr(ACE_CDR::MAX_ALIGNMENT+8);

 size_t length1 = cdr.length();

 ACE_Message_Block * mb = NULL;
 mb = new ACE_Message_Block(cdr.begin()->rd_ptr(),cdr.begin()->total_length());

 ACE_ASSERT(cdr.begin()->rd_ptr() == cdr.begin()->wr_ptr() );

 cdr << ACE_CDR::Long(22);

 cdr << ACE_CDR::Long(22);

 size_t length2 = cdr.length();

 /*mb->wr_ptr((cdr.begin())->total_length());*/

 mb->wr_ptr(length2 - length1); // wr_ptr指针要往前移动 length2 - length1个字节,ACE_OutputCDR 不会去更新wr_ptr,只能手工更新

 ACE_Message_Block * payload = NULL;  

 payload = new ACE_Message_Block("11111");  //申请另外一个 ACE_Message_Block

 payload->rd_ptr(5);

 payload->wr_ptr(10);

 mb->cont(payload);  //形成ACE_Message_Block链表
 
ACE_InputCDR 的使用

ACE_Message_Block * mb = new ACE_Message_Block (ACE_DEFAULT_CDR_BUFSIZE);

 if(sock_.recv_n(mb->wr_ptr(),8) == 8)

 {

  mb->wr_ptr(8);

  

  ACE_InputCDR cdr(mb);

  ACE_CDR::Long Type,Type1;

  cdr >> Type;

  cdr >>Type1;

  if(sock_.recv_n(mb->wr_ptr(),3) > 0)

  {

   mb->wr_ptr(3);

  }

关于ACE_Message_block ,ACE_Inputcdr,ACE_OutputCdr的使用的注意事项还有很多,需要一步一步发掘。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息