示例#1
0
void
PSession::trace_read_completion (const TRB_Asynch_Read_Stream::Result &result)
{
    {
        ACE_GUARD (ACE_SYNCH_MUTEX, monitor, this->mutex ());

        this->update_last_time();

        if (result.success())
            this->total_rcv_ += result.bytes_transferred ();
    }

    int loglevel = this->config().loglevel ();

    ACE_Message_Block & mb = result.message_block ();

    size_t xfer_bytes = result.bytes_transferred();
    char * last  = mb.wr_ptr();
    char * first = last - xfer_bytes; 

    if (loglevel == 0)
    {
        LogLocker log_lock;

        ACE_DEBUG ((LM_DEBUG,
            ACE_TEXT ("(%t) **** %s=%d handle_read_stream() ****\n"),
            this->get_name(),
            this->index()));

        ACE_DEBUG ((LM_DEBUG,
            ACE_TEXT ("bytes_to_read = %d\n"),
            result.bytes_to_read ()));

        ACE_DEBUG ((LM_DEBUG,
            ACE_TEXT ("handle = %d\n"),
            result.handle ()));

        ACE_DEBUG ((LM_DEBUG,
            ACE_TEXT ("bytes_transfered = %d\n"),
            xfer_bytes));

        ACE_DEBUG ((LM_DEBUG,
            ACE_TEXT ("error = %d\n"),
            result.error ()));

        ACE_DEBUG ((LM_DEBUG,
            ACE_TEXT ("message_block:\n")));

        ACE_HEX_DUMP ((LM_DEBUG, first, xfer_bytes));


        ACE_DEBUG ((LM_DEBUG,
            ACE_TEXT ("**** end of message ****************\n")));
    }
    else if (result.error () != 0 )
    {
        LogLocker log_lock;

        //ACE_Log_Msg::instance ()->errnum (result.error ());
        ACE_OS::last_error (result.error ());
        ACE_Log_Msg::instance ()->log (LM_ERROR,
            ACE_TEXT ("(%t) %s=%d READ %p\n"),
            this->get_name (),
            this->index (),
            ACE_TEXT ("ERROR"));
    }
    else if (loglevel == 1)
    {
        ACE_DEBUG ((LM_DEBUG,
            ACE_TEXT ("(%t) %s=%d read_bytes=%d OK\n"),
            this->get_name (),
            this->index (),
            xfer_bytes));
    }

    return;
}
void Test_Service_Handler::handle_read_stream(const TRB_Asynch_Read_Stream::Result &result)
{
    ACE_Guard<ACE_Recursive_Thread_Mutex> guard(mtx_);

    if (!result.success() || result.bytes_transferred() == 0)
    {
      // Error or remote disconnect

      ACE_DEBUG ((LM_DEBUG, 
          ACE_TEXT("(%t) %s_Handler(%@)::handle_read_stream - disconnected\n"),
          is_caller_ ? "Client" : "Server" ,
          this));

      read_count_--;

      result.message_block().release();

      //AL: delete_if_reqd();
      this->cancel();
      return;
    }


    if (result.bytes_transferred() < result.bytes_to_read())
    {
      // More to read...

      ACE_DEBUG ((LM_DEBUG, 
          ACE_TEXT("(%t) %s_Handler(%@)::handle_read_stream, more to read\n"),
          is_caller_ ? "Client" : "Server" ,
          this));

      int ret = reader_.read(result.message_block(), 
                             result.bytes_to_read() - result.bytes_transferred());
      if (ret < 0)
	    {
          ACE_DEBUG ((LM_DEBUG, 
              ACE_TEXT("(%t) %s_Handler(%@)::handle_read_stream, failed to the remainder\n"),
              is_caller_ ? "Client" : "Server" ,
              this));

          read_count_--;

          result.message_block().release();
          
          //AL: delete_if_reqd();
          this->cancel();
	    }
      return;
    }

    if (current_read_pkt_.length() == 0)
    {
      // The header has been read

      current_read_pkt_ = std::string(result.message_block().base(), 
                                      result.message_block().length());

      // Read the payload

      result.message_block().size(ACE_OS::strlen(pkt_payload));
      result.message_block().reset();

      int ret = reader_.read(result.message_block(), ACE_OS::strlen(pkt_payload));

      if (ret < 0)
    	{
          read_count_--;

          result.message_block().release();

          this->cancel();
	    }
      return;
    }

    // The payload has been read

    ++received_;

    ACE_DEBUG ((LM_DEBUG, 
          ACE_TEXT("(%t) %s_Handler(%@)::handle_read_stream, read data item: %d\n"),
          is_caller_ ? "Client" : "Server" ,
          this,
          received_));

    current_read_pkt_ += std::string(result.message_block().base(), 
                                     result.message_block().size());
    
    current_read_pkt_.clear();

    read_count_--;

    if (received_ >= receive_expected_)
    {
          ACE_DEBUG ((LM_DEBUG, 
              ACE_TEXT("(%t) %s_Handler(%@)::handle_read_stream, received all data\n"), 
              is_caller_ ? "Client" : "Server" ,
              this));
          event_pkt_recv_.signal();
    }
    else
    {
          Send_Request *req;
          ACE_NEW_NORETURN(req, Send_Request(this));
          TEST_QUEUE->perform(req);
    }

}