Esempio n. 1
0
void
Sender::handle_write_stream (const ACE_Asynch_Write_Stream::Result &result)
{
  ACE_DEBUG ((LM_DEBUG,
              "handle_write_stream called\n"));

  // Reset pointers.
  result.message_block ().rd_ptr (result.message_block ().rd_ptr () - result.bytes_transferred ());

  ACE_DEBUG ((LM_DEBUG, "********************\n"));
  ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_to_write", result.bytes_to_write ()));
  ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "handle", result.handle ()));
  ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_transfered", result.bytes_transferred ()));
  ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "act", (uintptr_t) result.act ()));
  ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "success", result.success ()));
  ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "completion_key", (uintptr_t) result.completion_key ()));
  ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "error", result.error ()));
  ACE_DEBUG ((LM_DEBUG, "********************\n"));
#if 0
  ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "message_block", result.message_block ().rd_ptr ()));
#endif

  if (result.success ())
    {
      // Partial write to socket
      int unsent_data =
        ACE_Utils::truncate_cast<int> (
          result.bytes_to_write () - result.bytes_transferred ());
      
      if (unsent_data != 0)
        {
          // Reset pointers
          result.message_block ().rd_ptr (result.bytes_transferred ());

          // Duplicate the message block and retry remaining data
          if (this->ws_.write (*result.message_block ().duplicate (),
                               unsent_data) == -1)
            {
              ACE_ERROR ((LM_ERROR,
                          "%p\n",
                          "ACE_Asynch_Write_Stream::write"));
              return;
            }
        }
      else if (!(this->file_size_ > this->file_offset_))
        {
          this->stream_write_done_ = 1;
          if (this->transmit_file_done_)
            done = 1;
        }
    }

  // Release message block.
  result.message_block ().release ();
}
Esempio n. 2
0
void
Peer_Handler::handle_write_stream (const ACE_Asynch_Write_Stream::Result &result)
{
  if (result.bytes_transferred () <= 0)
    ACE_DEBUG ((LM_DEBUG, "(%t) %p bytes = %d\n", "Message failed",
                result.bytes_transferred ()));

  // This was allocated by the STDIN_Handler, queued, dequeued, passed
  // to the proactor, and now passed back to us.
  result.message_block ().release ();
}
Esempio n. 3
0
void
Sender::handle_write_stream (const ACE_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 ();
    mb.release ();

    if (result.error () != 0 ||
        result.bytes_transferred () == 0 ||
        this->initiate_write_stream () != 0 ||
        this->initiate_read_stream() != 0)
      {
        this->cancel_i ();
      }

    if (!this->is_safe_to_delete())
      return;

  }
  this->manager()->destroy_session(this);
}
void CProConsoleHandle::handle_write_stream(const ACE_Asynch_Write_Stream::Result &result)
{
	if(!result.success() || result.bytes_transferred()==0)
	{
		//链接断开
		OUR_DEBUG ((LM_DEBUG,"[CConnectHandler::handle_write_stream] Connectid=[%d] begin(%d)...\n",GetConnectID(), errno));

		//AppLogManager::instance()->WriteLog(LOG_SYSTEM_CONNECT, "Close Connection from [%s:%d] RecvSize = %d, RecvCount = %d, SendSize = %d, SendCount = %d.",m_addrRemote.get_host_addr(), m_addrRemote.get_port_number(), m_u4AllRecvSize, m_u4AllRecvCount, m_u4AllSendSize, m_u4AllSendCount);

		OUR_DEBUG((LM_DEBUG,"[CConnectHandler::handle_write_stream] Connectid=[%d] finish ok...\n", GetConnectID()));
		m_atvOutput = ACE_OS::gettimeofday();
		App_MessageBlockManager::instance()->Close(&result.message_block());
		Close();
		return;
	}
	else
	{
		//短读不考虑
		m_blCanWrite = true;
		m_atvOutput = ACE_OS::gettimeofday();
		App_MessageBlockManager::instance()->Close(&result.message_block());
		m_u4AllSendSize += (uint32)result.bytes_to_write();
		Close();
		return;
	}
}
void Sender::handle_write_stream (const ACE_Asynch_Write_Stream::Result
                                  &result)
{
  ACE_DEBUG ((LM_DEBUG,
              "handle_write_stream called\n"));

  // Reset pointers.
  result.message_block ().rd_ptr (result.message_block ().rd_ptr () -
                                  result.bytes_transferred ());


  ACE_DEBUG ((LM_DEBUG, "********************\n"));
  ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_to_write",
              result.bytes_to_write ()));
  ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "handle", result.handle ()));
  ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_transfered",
              result.bytes_transferred ()));
  ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "act", (u_long) result.act ()));
  ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "success", result.success ()));
  ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "completion_key", (u_long)
              result.completion_key ()));
  ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "error", result.error ()));
  ACE_DEBUG ((LM_DEBUG, "********************\n"));
  ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "message_block",
              result.message_block ().rd_ptr ()));

  // Simplify just for Test
  if (result.success () && result.bytes_transferred () != 0)
    {
      if ( duplex != 0 )  // full duplex, continue write
        {
          initiate_write_stream () ;
        }
      else  // half-duplex   read reply, after read we will start
        // write
        {
          initiate_read_stream () ;
        }
    }

  {
    ACE_Guard<MyMutex> locker (m_Mtx) ;
    nIOCount-- ;
  }
}
Esempio n. 6
0
void
PConnection::trace_write_completion (const ACE_Asynch_Write_Stream::Result &result)
{
    int loglevel = this->config().loglevel ();

    size_t xfer_bytes = result.bytes_transferred();

    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 ()));

        trace_buffers (result.get_buffer_info (), xfer_bytes, false);

    }
    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));
    }
}
Esempio n. 7
0
void
Sender::handle_write_stream (const ACE_Asynch_Write_Stream::Result &result)
{
  ACE_Message_Block *mb = &result.message_block ();

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Sender::handle_write_stream - wrote %d bytes\n"),
              result.bytes_transferred ()));

  if (result.error () == 0 && result.bytes_transferred () != 0)
    // verify sent all
    ACE_TEST_ASSERT (0 == mb->total_length ());
  else
    ACE_TEST_ASSERT (0);

  free_chunks_chain (mb);

  --this->io_count_;

  this->check_destroy ();
}
Esempio n. 8
0
void
Client_Service_Handler::handle_write_stream (
  const ACE_Asynch_Write_Stream::Result &result)
{
  ACE_GUARD (ACE_SYNCH_RECURSIVE_MUTEX, guard, this->mtx_);

  this->pending_writes_--;

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

    result.message_block ().release ();

    ACE_DEBUG ((LM_DEBUG, ACE_TEXT (
      "Client_Service_Handler::handle_write_stream: error: %d\n"),
      result.error ()));

    this->cancel_and_close ();
  }
  else if (result.bytes_transferred () < result.bytes_to_write ())
  {
    // More to write...

    if (this->write (result.message_block(),
      result.bytes_to_write () - result.bytes_transferred ()) < 0)
    {
      result.message_block ().release ();

      this->cancel_and_close ();
    }
  }
  else
  {
    // Wrote it all

    result.message_block ().release ();
  }
}
void
Client_Handler::handle_write_stream
  (const ACE_Asynch_Write_Stream::Result &result)
{
  if (!result.success ())
    {
      errno = result.error ();
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("(%t) Client handle %d: %p\n"),
                  this->stream_.handle (),
                  ACE_TEXT ("write")));
      delete this;
      return;
    }
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) Client %@ handle %d sent %B of %B bytes\n"),
              this, this->stream_.handle (),
              result.bytes_transferred (), result.bytes_to_write ()));
  ACE_Message_Block &b = result.message_block ();
  bool send_again = true;
  if (b.length () == 0)
    {
      // All block's data sent; rewind the read pointer and send it again
      // until we've sent the configured number of times.
      ++this->msgs_sent_;
      if (this->msgs_sent_ == cli_req_no)
        send_again = false;   // All done
      else
        b.rd_ptr (b.base ());
    }

  if (send_again)
    {
      if (this->stream_.write (this->block_, this->block_.length ()) == -1)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("(%t) Client_Handler: %p\n"),
                      ACE_TEXT ("initiate write")));
          delete this;
        }
    }
  else
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("(%t) Client handle %d done sending\n"),
                  this->stream_.handle ()));
      delete this;
    }
  return;
}
Esempio n. 10
0
void
Receiver::handle_write_stream (const ACE_Asynch_Write_Stream::Result &result)
{
  if (result.bytes_transferred () == 0 || result.error () != 0)
    {
      ACE_DEBUG ((LM_DEBUG, "handle_write_stream called\n"));

      ACE_DEBUG ((LM_DEBUG, "********************\n"));
      ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_to_write", result.bytes_to_write ()));
      ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "handle", result.handle ()));
      ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_transfered", result.bytes_transferred ()));
      ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "act", (u_long) result.act ()));
      ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "success", result.success ()));
      ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "completion_key", (u_long) result.completion_key ()));
      ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "error", result.error ()));
      ACE_DEBUG ((LM_DEBUG, "********************\n"));
    }

  result.message_block ().release ();

  if (result.success () && result.bytes_transferred () != 0)
    {
      // This code is not robust enough to deal with short file writes
      // (which hardly ever happen);-)
      //	ACE_ASSERT (result.bytes_to_write () == result.bytes_transferred ());

      if (duplex == 0)
        initiate_read_stream ();
    }

  {
    ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_);        
    io_count_--;
  }
  check_destroy ();
}
Esempio n. 11
0
// ************************************************************
//  Internal IO handlers
//  virtual from ACE_Service_Handler
// ************************************************************
void
ACE_SSL_Asynch_Stream::handle_write_stream (
  const ACE_Asynch_Write_Stream::Result &result)
{
  ACE_MT (ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, this->mutex_));

  this->bio_out_flag_ &= ~BF_AIO;

  ACE_Message_Block & mb = result.message_block ();

  size_t bytes_req = result.bytes_to_write ();
  size_t bytes_trn = result.bytes_transferred ();
  u_long errval    = result.error ();
  size_t len       = bytes_req - bytes_trn;

  if (errval != 0)                    // error ?
    this->bio_out_errno_ = errval;    // save err code
  else if (len > 0)                   // TCP/IP overloaded ?
    {                                 // continue, rd_ptr at right place
      if (this->bio_ostream_.write (
            mb,          // message block
            len,         // priority
            0,           // act
            0,           // priority
            ACE_SIGRTMIN // default signal
            ) == 0)
        {
          this->bio_out_flag_ |= BF_AIO;
          return;
        }

      ACELIB_ERROR
        ((LM_ERROR,
          ACE_TEXT ("(%P|%t) ACE_SSL_Asynch_Stream %p\n"),
          ACE_TEXT ("attempt write failed")
          ));

      this->bio_out_errno_ = EINVAL;
    }

  this->do_SSL_state_machine ();

  return;
}
Esempio n. 12
0
void
PConnection::handle_write_stream (const ACE_Asynch_Write_Stream::Result &result)
{
    this->trace_write_completion (result);

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

        this->update_last_time();

        this->ref_cnt_w_--;

        ACE_Message_Block & mb = result.message_block ();
        int              error = result.error();
        size_t      xfer_bytes = result.bytes_transferred ();
        size_t       req_bytes = result.bytes_to_write ();

        // done in initiate_write_stream
        // !!!! this->total_snd_ += xfer_bytes;

        if (error == 0 && this->protocol_ != 0)
        {
            if (xfer_bytes < req_bytes) // Process partial write
            {
                this->do_initiate_write_stream (mb);
            }
            else
            {
                check_out_queue ();
                this->protocol_->on_write_finished (mb, xfer_bytes, error);
            }
        }
        else
        {
            this->free_msg (&mb);
            this->cancel ();
        }

        if (!is_safe_to_delete())
            return;
    }
    this->manager()->destroy_connection(this);
}
Esempio n. 13
0
void
PConnection::handle_write_stream (const ACE_Asynch_Write_Stream::Result &result)
{
  this->trace_write_completion (result);

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

    this->update_last_time();

    this->ref_cnt_w_--;

    int              error = result.error();
    size_t      xfer_bytes = result.bytes_transferred ();
    size_t       req_bytes = result.bytes_to_write ();

    this->total_snd_ += xfer_bytes;

    if (error == 0 && this->protocol_ != 0) 
      {
        char *buf = result.get_buffer ();
        if (xfer_bytes < req_bytes) // Process partial write
          {
            this->initiate_write_stream (buf + xfer_bytes, 
                                         req_bytes - xfer_bytes);
          }
        else  
          {
            this->protocol_->on_write_finished (buf,
                                                xfer_bytes,
                                                error);
          }
      }
    else
      {
        this->cancel ();
      }

    if (!is_safe_to_delete())
      return;
  }
  this->manager()->destroy_connection(this);
}
Esempio n. 14
0
void CProConnectClient::handle_write_stream(const ACE_Asynch_Write_Stream::Result &result)
{
	ACE_Message_Block& mblk = result.message_block();
	if(!result.success() || result.bytes_transferred() == 0)
	{
		//处理数据发送出错
		OUR_DEBUG((LM_DEBUG, "[CProConnectClient::handle_write_stream]Write error(%d).\n", ACE_OS::last_error()));
		mblk.release();
		if(NULL != m_pClientMessage)
		{
			_ClientIPInfo objServerIPInfo;
			sprintf_safe(objServerIPInfo.m_szClientIP, MAX_BUFF_20, "%s", m_AddrRemote.get_host_addr());
			objServerIPInfo.m_nPort = m_AddrRemote.get_port_number();
			m_pClientMessage->ConnectError((int)ACE_OS::last_error(), objServerIPInfo);
		}
		Close();
	}
	else
	{
		mblk.release();
	}
}
Esempio n. 15
0
void
PSession::trace_write_completion (const ACE_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;
}
Esempio n. 16
0
void HttpdPeer::handle_write_stream( const ACE_Asynch_Write_Stream::Result &result )
{
	ACE_Message_Block& mb=result.message_block();
	size_t unsent_data;

	if (result.success())
	{

		unsent_data = result.bytes_to_write() - result.bytes_transferred();
		if (unsent_data != 0) //未写完
		{
			// Reset pointers
			result.message_block ().rd_ptr (result.bytes_transferred ());

			// Duplicate the message block and retry remaining data
			if (writer_.write (*result.message_block ().duplicate (),
				unsent_data) == -1)
			{
				ACE_ERROR ((LM_ERROR,
					"%p ",
					"HttpPeer::Write"));
				ACE_OS::printf("%d\n",ACE_OS::last_error());
				result.message_block().release();
				return;
			}
			result.message_block().release();
		}
		else
		{
			ACE_Guard<ACE_Thread_Mutex> guard(mutex_);
			mb.release();

			if (bIsIniting_)
			{
				if (!delivered_header_ && lpMgr->mhdr_.len_>0)
				{
					//Push Header

					ACE_Message_Block *lpMb = NULL;
					ACE_NEW_NORETURN(lpMb,ACE_Message_Block(lpMgr->mhdr_.data_,lpMgr->mhdr_.len_));
					lpMb->wr_ptr(lpMgr->mhdr_.len_);
					
					putQ(lpMb);
					
					//ACE_Time_Value tv;
					//tv.msec(300);//
					//ACE_OS::sleep(tv);
					delivered_header_ = true;
				}
				else
				{
					
					sentinel_ = lpMgr->buffer_.start_seg_id_;	
					while(lpMgr->buffer_.get_data(sentinel_)!= NULL)
					{
						ACE_Message_Block *mb_ = lpMgr->buffer_.get_data(sentinel_);
						if (mb_!=NULL)
						{
							mq_.push_back(mb_->duplicate());
						}
						
						sentinel_++;
					}
				
					bIsIniting_ = false;
					
				}
			}
			
			init_write();
			
		}
	}   

}