void Test_Service_Handler::handle_write_stream(const TRB_Asynch_Write_Stream::Result &result)
{
    ACE_Guard<ACE_Recursive_Thread_Mutex> guard(mtx_);

    if (!result.success() || 0 == result.bytes_transferred())
    {
      // Error
      ACE_DEBUG ((LM_DEBUG, 
          ACE_TEXT("(%t) %s_Handler(%@)::handle_write_stream, disconnected\n"),
          is_caller_ ? "Client" : "Server" ,
          this));

      write_count_--;

      result.message_block().release();

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

    if (result.bytes_transferred() < result.bytes_to_write())
    {
      // More to write...
      ACE_DEBUG ((LM_DEBUG, 
          ACE_TEXT("(%t) %s_Handler(%@)::handle_write_stream, more to write\n"),
          is_caller_ ? "Client" : "Server" ,
          this));

      int ret = writer_.write(result.message_block(), 
                              result.bytes_to_write() - result.bytes_transferred());

      if (ret < 0)
	    {
          write_count_--;
	  
          result.message_block().release();
      
          this->cancel();
	    }
      return;
    }

    // Wrote it all
      ACE_DEBUG ((LM_DEBUG, 
          ACE_TEXT("(%t) %s_Handler(%@)::handle_write_stream, write done ok\n"),
          is_caller_ ? "Client" : "Server" ,
          this));

    write_count_--;

    result.message_block().release();

    if (this->cancel_called_)
    {
        this->delete_if_reqd();
    }
}
Beispiel #2
0
void
PSession::trace_write_completion (const TRB_Asynch_Write_Stream::Result &result)
{
    {
        ACE_GUARD (ACE_SYNCH_MUTEX, monitor, this->mutex ());

        this->update_last_time();

        if (result.success())
            this->total_snd_ += 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.rd_ptr();
    char * first = last - xfer_bytes;

    if (loglevel == 0)
    {
        LogLocker log_lock;

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

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

        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 WRITE %p\n"),
            this->get_name (),
            this->index (),
            ACE_TEXT ("ERROR"));
    }
    else if (loglevel == 1)
    {
        ACE_DEBUG ((LM_DEBUG,
            ACE_TEXT ("(%t) %s=%d write_bytes=%d OK\n"),
            this->get_name (),
            this->index (),
            xfer_bytes));
    }

    return;
}