示例#1
0
void
Receiver::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)
    {
      // 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.
          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,
              "Receiver completed\n"));

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

  // Note that we are done with the test.
  done++;
}
示例#2
0
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++;
}