当前位置: 首页>>代码示例>>C++>>正文


C++ ACE_InputCDR::reset_byte_order方法代码示例

本文整理汇总了C++中ACE_InputCDR::reset_byte_order方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_InputCDR::reset_byte_order方法的具体用法?C++ ACE_InputCDR::reset_byte_order怎么用?C++ ACE_InputCDR::reset_byte_order使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ACE_InputCDR的用法示例。


在下文中一共展示了ACE_InputCDR::reset_byte_order方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: recv_log_record

int Logging_Handler::recv_log_record (ACE_Message_Block *&mblk)
{
  // Put <logging_peer>'s hostname in new message block.
  ACE_INET_Addr peer_addr;
  logging_peer_.get_remote_addr (peer_addr);
  mblk = new ACE_Message_Block (MAXHOSTNAMELEN + 1);
  peer_addr.get_host_name (mblk->wr_ptr (), MAXHOSTNAMELEN);
  mblk->wr_ptr (ACE_OS::strlen (mblk->wr_ptr ()) + 1); // Go past name

  // Allocate a message block for the payload; initially at least
  // large enough to hold the header, but needs some room for
  // alignment.
  ACE_Message_Block *payload =
    new ACE_Message_Block (ACE_DEFAULT_CDR_BUFSIZE);
  // Align the Message Block for a CDR stream
  ACE_CDR::mb_align (payload);
  if (logging_peer_.recv_n (payload->wr_ptr (), 8) == 8) {
    payload->wr_ptr (8);               // Reflect addition of 8 bytes

    // Create a CDR stream to parse the 8-byte header.
    ACE_InputCDR cdr (payload);

    // Extract the byte-order and use helper methods to
    // disambiguate octet, booleans, and chars.
    ACE_CDR::Boolean byte_order;
    cdr >> ACE_InputCDR::to_boolean (byte_order);

    // Set the byte-order on the stream...
    cdr.reset_byte_order (byte_order);

    // Extract the length
    ACE_CDR::ULong length;
    cdr >> length;

    // Ensure there's sufficient room for log record payload.
    ACE_CDR::grow (payload, 8 + ACE_CDR::MAX_ALIGNMENT + length);

    // Use <recv_n> to obtain the contents.
    if (logging_peer_.recv_n (payload->wr_ptr (), length) > 0) {
      payload->wr_ptr (length);   // Reflect additional bytes
      // Chain the payload to mblk via the contination field.
      mblk->cont (payload);
      return length;
    }
  }
开发者ID:CCJY,项目名称:ACE,代码行数:45,代码来源:Logging_Handler.cpp

示例2: if

void AIO_Input_Handler::handle_read_stream
    (const ACE_Asynch_Read_Stream::Result &result) {
  if (!result.success () || result.bytes_transferred () == 0)
    delete this;
  else if (result.bytes_transferred () < result.bytes_to_read ())
    reader_.read (*mblk_, result.bytes_to_read () -
                  result.bytes_transferred ());
  else if (mblk_->length () == LOG_HEADER_SIZE) {
    ACE_InputCDR cdr (mblk_);

    ACE_CDR::Boolean byte_order;
    cdr >> ACE_InputCDR::to_boolean (byte_order);
    cdr.reset_byte_order (byte_order);

    ACE_CDR::ULong length;
    cdr >> length;

    mblk_->size (length + LOG_HEADER_SIZE);
    reader_.read (*mblk_, length);
  }
开发者ID:DOCGroup,项目名称:ACE_TAO,代码行数:20,代码来源:AIO_Client_Logging_Daemon.cpp

示例3: svc

  virtual int svc () {
    const size_t FileReadSize = 8 * 1024;
    ACE_Message_Block mblk (FileReadSize);

    for (;; mblk.crunch ()) {
      // Read as much as will fit in the message block.
      ssize_t bytes_read = logfile_.recv (mblk.wr_ptr (),
                                          mblk.space ());
      if (bytes_read <= 0)
        break;
      mblk.wr_ptr (static_cast<size_t> (bytes_read));

      // We have a bunch of data from the log file. The data is
      // arranged like so:
      //    hostname\0
      //    CDR-encoded log record
      // So, first we scan for the end of the host name, then
      // initialize another ACE_Message_Block aligned for CDR
      // demarshaling and copy the remainder of the block into it. We
      // can't use duplicate() because we need to be sure the data
      // pointer is aligned properly for CDR demarshaling.  If at any
      // point, there's not enough data left in the message block to
      // extract what's needed, crunch the block to move all remaining
      // data to the beginning and read more from the file.
      for (;;) {
        size_t name_len = ACE_OS::strnlen
                             (mblk.rd_ptr (), mblk.length ());
        if (name_len == mblk.length ()) break;

        char *name_p = mblk.rd_ptr ();
        ACE_Message_Block *rec, *head, *temp;
        ACE_NEW_RETURN
          (head, ACE_Message_Block (name_len, MB_CLIENT), 0);
        head->copy (name_p, name_len);
        mblk.rd_ptr (name_len + 1);   // Skip nul also

        size_t need = mblk.length () + ACE_CDR::MAX_ALIGNMENT;
        ACE_NEW_RETURN (rec, ACE_Message_Block (need), 0);
        ACE_CDR::mb_align (rec);
        rec->copy (mblk.rd_ptr (), mblk.length ());

        // Now rec contains the remaining data we've read so far from
        // the file. Create an ACE_InputCDR to start demarshaling the
        // log record, header first to find the length, then the data.
        // Since the ACE_InputCDR constructor increases the reference count
        // on rec, we release it upon return to prevent leaks.
        // The cdr 'read' methods return 0 on failure, 1 on success.
        ACE_InputCDR cdr (rec); rec->release ();
        ACE_CDR::Boolean byte_order;
        if (!cdr.read_boolean (byte_order)) {
          head->release (); rec->release (); break;
        }
        cdr.reset_byte_order (byte_order);

        // Now read the length of the record. From there, we'll know
        // if rec contains the complete record or not.
        ACE_CDR::ULong length;
        if (!cdr.read_ulong (length)) {
          head->release (); mblk.rd_ptr (name_p); break;
        }
        if (length > cdr.length ()) {
          head->release (); mblk.rd_ptr (name_p); break;
        }

        // The complete record is in rec... grab all the fields into
        // separate, chained message blocks.
        ACE_NEW_RETURN (temp,
                        ACE_Message_Block (length, MB_TEXT),
                        0);
        ACE_NEW_RETURN
          (temp,
           ACE_Message_Block (2 * sizeof (ACE_CDR::Long),
                              MB_TIME, temp),
           0);
        ACE_NEW_RETURN
          (temp,
           ACE_Message_Block (sizeof (ACE_CDR::Long),
                              MB_PID, temp),
           0);
        ACE_NEW_RETURN
          (temp,
           ACE_Message_Block (sizeof (ACE_CDR::Long),
                              MB_TYPE, temp),
           0);
        head->cont (temp);

        // Extract the type
        ACE_CDR::Long *lp;
        lp = reinterpret_cast<ACE_CDR::Long*> (temp->wr_ptr ());
        cdr >> *lp;
        temp->wr_ptr (sizeof (ACE_CDR::Long));
        temp = temp->cont ();

        // Extract the pid
        lp = reinterpret_cast<ACE_CDR::Long*> (temp->wr_ptr ());
        cdr >> *lp;
        temp->wr_ptr (sizeof (ACE_CDR::Long));
        temp = temp->cont ();

        // Extract the timestamp (2 Longs)
//.........这里部分代码省略.........
开发者ID:CCJY,项目名称:ACE,代码行数:101,代码来源:display_logfile.cpp

示例4: cdr

void
UDPGenerator::handle_read_dgram (const ACE_Asynch_Read_Dgram::Result &result)
{
    ACE_DEBUG ((LM_DEBUG, "handle_read_dgram called\n"));

    ACE_DEBUG ((LM_DEBUG, "********************\n"));/*{{{*/
    ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_to_read", result.bytes_to_read ()));
    ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "handle", result.handle ()));
    ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_transfered", result.bytes_transferred ()));
    ACE_INET_Addr peerAddr;
    result.remote_address (peerAddr);
    ACE_DEBUG ((LM_DEBUG, "%s = %s:%d\n", "peer_address", peerAddr.get_host_addr (), peerAddr.get_port_number ()));
    ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "flags", result.flags ()));
    ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "act", result.act ()));
    ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "success", result.success ()));
    ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "completion_key", result.completion_key ()));
    ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "error", result.error ()));
    ACE_DEBUG ((LM_DEBUG, "********************\n"));/*}}}*/

    if (result.success () && result.bytes_transferred () != 0)
    {
        const ACE_Message_Block * msg = result.message_block();

        ACE_InputCDR cdr (msg->cont());

        ACE_CDR::Boolean byte_order;
        cdr >> ACE_InputCDR::to_boolean (byte_order);
        cdr.reset_byte_order(byte_order);
        ACE_CDR::ULong length;
        cdr >> length;

        ACE_InputCDR cdrpayload(msg->cont());
        cdrpayload.reset_byte_order(byte_order);
        DataGloveData glovedata;
        cdrpayload >> glovedata;

        // loop through our message block and print out the contents/*{{{*/
        //for (const ACE_Message_Block* msg = result.message_block(); msg != 0; msg = msg->cont ())
        //  { // use msg->length() to get the number of bytes written to the message
        // block.
        //if (msg->length() == 8)
        //{
        //    ACE_InputCDR cdr (msg);

        //    ACE_CDR::Boolean byte_order;
        //    cdr >> ACE_InputCDR::to_boolean (byte_order);
        //    cdr.reset_byte_order(byte_order);
        //    ACE_CDR::ULong length;
        //    cdr >> length;

        //    ACE_InputCDR cdrpayload(msg->cont());
        //    cdrpayload.reset_byte_order(byte_order);
        //    DataGloveData glovedata;
        //    cdrpayload >> glovedata;
        //    continue;
        //}
        //else
        //{
        //       ACE_DEBUG ((LM_DEBUG, "Buf=[size=<%d>", msg->length ()));
        //      for (u_long i = 0; i < msg->length(); ++i)
        //         ACE_DEBUG ((LM_DEBUG, "%c", (msg->rd_ptr())[i]));
        //    ACE_DEBUG ((LM_DEBUG, "]\n"));
        //}/*}}}*/
        //}
    }

    ACE_DEBUG ((LM_DEBUG, "Receive completed\n"));

    // No need for this message block anymore.
    result.message_block ()->release ();
    readdatagram(4);

    // Note that we are done with the test.
    done++;
}
开发者ID:robotology-legacy,项目名称:yarp1,代码行数:75,代码来源:UDPGenerator.cpp


注:本文中的ACE_InputCDR::reset_byte_order方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。