找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 4436|回复: 2

Reator退出的问题

[复制链接]
发表于 2008-7-15 22:22:54 | 显示全部楼层 |阅读模式
在服务器关闭后,客户端在delete this的时候发生错误,内存引用的错误,怎么解决呀?
  1. int Client::open (void *p)
  2. {
  3. if (super::open (p) == -1)
  4.   return -1;
  5. ACE_Time_Value iter_delay (10);
  6. ACE_Time_Value init_delay (10);
  7. this->notifier_.reactor (this->reactor ());
  8. this->msg_queue ()->notification_strategy (&this->notifier_);
  9. return this->reactor ()->schedule_timer(this, 0, init_delay, iter_delay);
  10. //this->reactor()->register_handler(this, ACE_Event_Handler::WRITE_MASK);
  11. //ACE_Reactor::instance()->register_handler(this, ACE_Event_Handler::WRITE_MASK);
  12. //this->msg_queue ()->notification_strategy (&this->notifier_);
  13. //return 0;
  14. }
  15. int Client::handle_input (ACE_HANDLE fd)
  16. {
  17. char recv_data[40960];
  18. memset(recv_data, 0, 40960);
  19. ssize_t recv_cnt = 0;
  20. int index = 0;
  21. int stamp = -1;
  22. BOOL bData = TRUE;
  23. recv_cnt = this->peer().recv (recv_data, 40960);
  24. count --;
  25. if (recv_cnt != -1)
  26. {
  27.   ......
  28. }
  29. if (recv_cnt == 0 || ACE_OS::last_error () != EWOULDBLOCK)
  30. {
  31.   this->reactor()->end_reactor_event_loop();
  32.   return -1;
  33. }
  34. return 0;
  35. }
  36. int Client::handle_timeout(const ACE_Time_Value &, const void *)
  37. {
  38. /*int ilen = 0;
  39. BYTE *send_data = NULL;
  40. ACE_Message_Block *mb;
  41. ACE_NEW_RETURN (mb, ACE_Message_Block (128), -1);
  42. titan.MakeBeatingTest(&send_data, ilen);
  43. mb->copy((const char*)send_data, ilen);
  44. ACE_ASSERT (ilen > 0);
  45. this->putq (mb);*/
  46. if (++this->iterations_ >= ITERATIONS)
  47. {
  48.   this->peer().close_writer();
  49.   return 0;
  50. }
  51. ACE_Message_Block *mb;
  52. ACE_NEW_RETURN(mb, ACE_Message_Block(128), -1);
  53. char msg[128];
  54. ACE_OS::sprintf(msg, "Iteration %d\n", this->iterations_);
  55. this->putq(mb);
  56. return 0;
  57. }
  58. int Client::handle_output (ACE_HANDLE fd)
  59. {
  60. char *aa = "fafda";
  61. this->peer().send(aa, strlen(aa));
  62. count ++;
  63. ACE_Message_Block *mb;
  64. ACE_Time_Value nowait (ACE_OS::gettimeofday ());
  65. while (-1 != this->getq (mb, &nowait))
  66. {
  67.   ssize_t send_cnt = this->peer ().send (mb->rd_ptr (), mb->length ());
  68.   if (send_cnt != -1)
  69.    mb->rd_ptr (static_cast<size_t> (send_cnt));
  70.   if (mb->length () > 0)
  71.   {
  72.    this->ungetq (mb);
  73.    break;
  74.   }
  75.   mb->release ();
  76. }
  77. if (this->msg_queue ()->is_empty ())
  78.   this->reactor ()->cancel_wakeup(this, ACE_Event_Handler::WRITE_MASK);
  79. else
  80.   this->reactor ()->schedule_wakeup(this, ACE_Event_Handler::DONT_CALL);
  81. return 0;
  82. }
复制代码
我实在是找不到在问题在那了
 楼主| 发表于 2008-7-15 22:23:03 | 显示全部楼层
你没控制好内存操作,导致在delete this后,仍然有引用此对象的操作,导致了崩溃。
 楼主| 发表于 2008-7-15 22:23:23 | 显示全部楼层
找到问题出现在那了,我在handle_input()里面用到了,COM组件,是由用COM组件没有释放完全,引起的错误
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

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

GMT+8, 2024-5-8 14:43 , Processed in 0.012746 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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