Ejemplo n.º 1
0
void
Sender::handle_write_stream (const TRB_Asynch_Write_Stream::Result &result)
{
    this->trace_write_completion (result);

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

        this->ref_cnt_w_--;

        ACE_Message_Block & mb = result.message_block ();

        if (result.error () == 0 && result.bytes_transferred () > 0)
        {
            this->initiate_write_stream (&mb);
            this->initiate_read_stream(0);
        }
        else
        {
            mb.release ();
            this->stream_.cancel_and_close ();
        }

        if (!is_safe_to_delete())
            return;
    }
    this->manager()->destroy_session(this);
}
Ejemplo n.º 2
0
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();
    }
}
Ejemplo n.º 3
0
void
AIO_SSL_Client_Session::handle_write_stream(const TRB_Asynch_Write_Stream::Result& result)
{
	if ( ssl_ )
	{
		{
			ACE_GUARD(ACE_SYNCH_MUTEX, monitor, this->lock_);

			--n_op_w_;

			ACE_Message_Block& mb = result.message_block();

			// on write done
			if ( result.error() == 0 && result.bytes_transferred() > 0 )
			{
				update_last_time();
				int rc = this->on_write_complete(mb, result);
				if ( rc < 1 ) 
				{
					mb.release();
					if ( rc < 0 && !is_cancelling_ ) { is_cancelling_ = 1; ssl_stream_.cancel(); }
				}
			}
			// on write 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_write_stream(result);
	}
}
Ejemplo n.º 4
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;
}