示例#1
0
void
Sender::handle_read_stream (const TRB_Asynch_Read_Stream::Result &result)
{
    this->trace_read_completion (result);

    {
        ACE_GUARD (ACE_SYNCH_MUTEX, monitor, this->mutex ());

        this->ref_cnt_r_--;

        ACE_Message_Block & mb = result.message_block ();

        if (result.error () == 0 && result.bytes_transferred () > 0)
        {
            this->initiate_read_stream (&mb);
            this->initiate_write_stream (0);
        }
        else
        {
            this->stream_.cancel_and_close ();
            mb.release ();
        }
        
        if (!is_safe_to_delete())
            return;
    }
    this->manager()->destroy_session(this);
}
示例#2
0
void
AIO_SSL_Client_Session::handle_read_stream(const TRB_Asynch_Read_Stream::Result& result)
{
	if ( ssl_ )
	{
		{
			ACE_GUARD(ACE_SYNCH_MUTEX, monitor, this->lock_);

			--n_op_r_;

			ACE_Message_Block& mb = result.message_block();

			// on read done
			if ( result.error() == 0 )
			{
				update_last_time();
				if ( result.bytes_transferred() == 0 )
				{
					mb.release(); ssl_stream_.close();
				}
				else
				{
					int rc = this->on_read_complete(mb, result);
					if ( rc < 1 ) 
					{
						mb.release();
						if ( rc < 0 && !is_cancelling_ ) { is_cancelling_ = 1; ssl_stream_.cancel(); }
					}
				}
			}
			// on read error, close session
			else
			{
				mb.release();
				if ( !is_cancelling_ ) { is_cancelling_ = 1; ssl_stream_.cancel(); }
			}
			
			if ( this->has_pending_io() ) return;
			if ( this->is_safe_to_delete_ == 0 ) { ssl_stream_.close(); return; }
			this->on_close();
		}
		
		manager_->destroy_session(this);
	}
	else
	{
		AIO_Session::handle_read_stream(result);
	}
}
示例#3
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);
    }

}