peakzhang 发表于 2008-7-15 22:22:54

Reator退出的问题

在服务器关闭后,客户端在delete this的时候发生错误,内存引用的错误,怎么解决呀?

int Client::open (void *p)
{
if (super::open (p) == -1)
return -1;
ACE_Time_Value iter_delay (10);
ACE_Time_Value init_delay (10);
this->notifier_.reactor (this->reactor ());
this->msg_queue ()->notification_strategy (&this->notifier_);
return this->reactor ()->schedule_timer(this, 0, init_delay, iter_delay);

//this->reactor()->register_handler(this, ACE_Event_Handler::WRITE_MASK);
//ACE_Reactor::instance()->register_handler(this, ACE_Event_Handler::WRITE_MASK);
//this->msg_queue ()->notification_strategy (&this->notifier_);
//return 0;
}
int Client::handle_input (ACE_HANDLE fd)
{
char recv_data;
memset(recv_data, 0, 40960);
ssize_t recv_cnt = 0;
int index = 0;
int stamp = -1;
BOOL bData = TRUE;
recv_cnt = this->peer().recv (recv_data, 40960);
count --;
if (recv_cnt != -1)
{
......
}

if (recv_cnt == 0 || ACE_OS::last_error () != EWOULDBLOCK)
{
this->reactor()->end_reactor_event_loop();
return -1;
}
return 0;
}
int Client::handle_timeout(const ACE_Time_Value &, const void *)
{
/*int ilen = 0;
BYTE *send_data = NULL;
ACE_Message_Block *mb;
ACE_NEW_RETURN (mb, ACE_Message_Block (128), -1);
titan.MakeBeatingTest(&send_data, ilen);
mb->copy((const char*)send_data, ilen);
ACE_ASSERT (ilen > 0);
this->putq (mb);*/
if (++this->iterations_ >= ITERATIONS)
{
this->peer().close_writer();
return 0;
}
ACE_Message_Block *mb;
ACE_NEW_RETURN(mb, ACE_Message_Block(128), -1);
char msg;
ACE_OS::sprintf(msg, "Iteration %d\n", this->iterations_);
this->putq(mb);
return 0;
}
int Client::handle_output (ACE_HANDLE fd)
{
char *aa = "fafda";
this->peer().send(aa, strlen(aa));
count ++;
ACE_Message_Block *mb;
ACE_Time_Value nowait (ACE_OS::gettimeofday ());
while (-1 != this->getq (mb, &nowait))
{
ssize_t send_cnt = this->peer ().send (mb->rd_ptr (), mb->length ());
if (send_cnt != -1)
   mb->rd_ptr (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);
else
this->reactor ()->schedule_wakeup(this, ACE_Event_Handler::DONT_CALL);
return 0;
}

我实在是找不到在问题在那了

peakzhang 发表于 2008-7-15 22:23:03

你没控制好内存操作,导致在delete this后,仍然有引用此对象的操作,导致了崩溃。

peakzhang 发表于 2008-7-15 22:23:23

找到问题出现在那了,我在handle_input()里面用到了,COM组件,是由用COM组件没有释放完全,引起的错误
页: [1]
查看完整版本: Reator退出的问题