ACE_Svc_Handler的子类应该如何处理网络异常的情况?
目前我遇到的情况是在handle_output的send_n时有时候会出现Timer expired(长时间断开网络会出现这种情况)的错误,导致程序异常退出,我估计是我在处理上有不对的地方,那么出现这种错误之后我应该怎么处理呢?大家谁有没有好的建议,讨论一下吧。
//源码如下
int gkClient::handle_output (ACE_HANDLE)
{
TRACE(ACE_TEXT("gkClient::handle_output"));
ACE_Message_Block *mb;
ACE_Time_Value nowait (ACE_OS::gettimeofday ());
ACE_Time_Value wait;
wait.sec(5);
while (-1 != this->msg_queue()->dequeue_prio(mb, &nowait))
{
ssize_t send_cnt = this->peer ().send_n (mb->rd_ptr (), mb->length (),&wait);
ACE_DEBUG((LM_DEBUG,ACE_TEXT("%I(%D)(%P|%t) mb length:%d!\n"),mb- >length()));
mb->release ();
if (send_cnt <=0)
{
ACE_DEBUG((LM_DEBUG,ACE_TEXT("%I(%D)(%P|%t) send msg to SocketServer failed!\n")));
ACE_ERROR((LM_ERROR,ACE_TEXT("%I(%D)(%P|%t) %p\n"),ACE_TEXT ("send")));
//remove WRITE_MASK
this->reactor()->cancel_wakeup(this,ACE_Event_Handler::WRITE_MASK);
this->msg_queue ()->notification_strategy (0);
//call back handle_close
TRACE_RETURN(-1);
}
}
TRACE_RETURN(0);
}
按理说我在send失败的时候就cancle掉了WRITE_MASK,这样应该就不会再回调handle_output,可是我的日志上
显示此后又调用了一次handle_output还是Timer experid的错误,此时程序就掉了。
日志信息:
(Wed Jul4 2007 12:01:43.997264)(4195|49544096) mb length:495!
(Wed Jul4 2007 12:01:43.997502)(4195|49544096) send msg to SocketServer failed!
(Wed Jul4 2007 12:01:43.997617)(4195|49544096) send: Timer expired
(Wed Jul4 2007 12:01:43.998079)handle_close! // 回调handle_close的日志
(Wed Jul4 2007 12:01:43.998272)handle_close over! //回调handle_close的日志
(Wed Jul4 2007 12:01:43.998383)~gkClient! // 析构
(Wed Jul4 2007 12:01:43.998494)SocketServer 192.168.200.88:2196 handle_close! //析构
(Wed Jul4 2007 12:01:43.999373)~gkClient over! //析构
(Wed Jul4 2007 12:01:44.007225)(4195|126053280) mb length: 495! //又一次发送
(Wed Jul4 2007 12:01:44.007411)(4195|126053280) send msg to SocketServer failed!
(Wed Jul4 2007 12:01:44.007516)(4195|126053280) send: Timer expired //到这里程序掉了
为什么我已经cancle了WRITE_MASK还会调用handle_output呢?大家有经验的帮帮忙吧!谢谢了先! 设置一下断点,看一下调用的堆栈顺序。
页:
[1]