找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 3516|回复: 0

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

[复制链接]
发表于 2008-8-16 10:57:31 | 显示全部楼层 |阅读模式
/**
* 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[4096];
    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[mb->length ()]='\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_empty  this->msg_queue ()->()");
}
if (closeflag ==1 )
  return -1;

   
    return 0;
  }
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-6-18 20:29 , Processed in 0.015107 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表