yjmovice 发表于 2008-8-16 10:57:31

handle_output 如何停下来?handle_output 时间间隔 怎么设?

/**
* Client.cpp,v 1.3 2004/01/07 22:40:16 shuston Exp
*
* A simple client program using ACE_Svc_Handler and ACE_Connector.
*/基于这个改的。
handle_output 触发的时间间隔 怎么设?
开始我就连续发了10条数据,对方也接收到了,关闭程序
handle_output 还在不停触发,要触发10次等10s后才能关闭

后来调用 ACE_Reactor::instance()->close();
会触发 先触发 handle_close 但handle_output 还是不停触发。

int TWSvcHandler::handle_close (ACE_HANDLE handle,
          ACE_Reactor_Mask close_mask)
{
   OutputMsg("TWSvcHandler::handle_close ACE_HANDLE ");
    cast_checkpoint();
   
    if (close_mask == ACE_Event_Handler::WRITE_MASK)
      return 0;
this->reactor()->cancel_timer(this);
    close_mask = ACE_Event_Handler::ALL_EVENTS_MASK |
      ACE_Event_Handler::DONT_CALL;
//this->reactor()->remove_handler(this,)
    this->reactor()->remove_handler (this, close_mask);
    this->peer().close ();
    this->msg_queue()->flush ();
closeflag = 1;
    //delete this;
   
    return 0;
}


int TWSvcHandler::handle_output (ACE_HANDLE)
{
   OutputMsg("TWSvcHandler::handle_output ACE_HANDLE ");
    cast_checkpoint();
    ACE_Message_Block *mb;
    char send_buf;
    ACE_Time_Value timeout_time(ACE_OS::gettimeofday()); //get current time
    ACE_Time_Value one_sec(1);
   
    timeout_time+=one_sec; //timeout_time is 10 seconds from now
int sendcount = 0;
    while (-1 != this->getq (mb, &timeout_time)) //block for at most 1 sec
      {
strncpy(send_buf, mb->rd_ptr (), mb->length ());
//cast_checkpoint();
send_buf='\0';
cast_debug(0,"sending : ");
cast_debug(0,send_buf);
cast_debug(0,"-----------\n");
fflush(NULL);
OutputMsg("Send data sendcount %d %s",++sendcount,send_buf);
ssize_t send_cnt =
   this->peer ().send (mb->rd_ptr (), mb->length ());
if ((send_cnt == -1)&& ACE_OS::last_error () != EWOULDBLOCK)
{
   ACE_ERROR ((LM_ERROR,
      ACE_TEXT ("(%P|%t) %p\n"),
      ACE_TEXT ("send")));
   return -1;
}
else
   mb->rd_ptr (ACE_static_cast (size_t, send_cnt));
if (mb->length () > 0)
   {
   this->ungetq (mb);
   break;
   }
mb->release ();
      }

    if (this->msg_queue ()->is_empty ())
      {
this->reactor ()->cancel_wakeup
   (this, ACE_Event_Handler::WRITE_MASK);
cast_debug(0,"Empty sending queue\n");
OutputMsg("this->msg_queue ()->is_empty ()");
      }
    else
{
      this->reactor ()->schedule_wakeup
(this, ACE_Event_Handler::WRITE_MASK);
   OutputMsg("not is_emptythis->msg_queue ()->()");
}
if (closeflag ==1 )
return -1;

   
    return 0;
}
页: [1]
查看完整版本: handle_output 如何停下来?handle_output 时间间隔 怎么设?