From 613ffa69f8d9a21d66da4fc7f60d5949dcf2cfc3 Mon Sep 17 00:00:00 2001 From: coryan Date: Thu, 3 Aug 2006 21:50:06 +0000 Subject: Thu Aug 3 21:49:27 UTC 2006 Carlos O'Ryan --- ChangeLog | 8 ++++++++ ace/Select_Reactor_T.cpp | 14 ++++++++++---- ace/TP_Reactor.cpp | 14 ++++++++++++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 436605b25ba..b361d555dad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Thu Aug 3 21:49:27 UTC 2006 Carlos O'Ryan + + * ace/TP_Reactor.cpp: + * ace/Select_Reactor_T.cpp: + Avoid the problems described in bug 2540 by detecting the + infinite loop and recomputing the number of active handlers. + Thanks to Jody Hagins for correcting my original "fix." + Thu Aug 3 10:39:12 UTC 2006 Johnny Willemsen * ace/Connector.h: diff --git a/ace/Select_Reactor_T.cpp b/ace/Select_Reactor_T.cpp index 1dd2fc26b2a..50c9eec5dc1 100644 --- a/ace/Select_Reactor_T.cpp +++ b/ace/Select_Reactor_T.cpp @@ -1286,6 +1286,13 @@ ACE_Select_Reactor_T::dispatch do { + // We expect that the loop will decrease the number of active + // handles in each iteration. If it does not, then something is + // inconsistent in the state of the Reactor and we should avoid + // the loop. Please read the comments on bug 2540 for more + // details. + int initial_handle_count = active_handle_count; + // Note that we keep track of changes to our state. If any of // the dispatch_*() methods below return -1 it means that the // state has changed as the result of an @@ -1360,11 +1367,10 @@ ACE_Select_Reactor_T::dispatch // if state changed, we need to re-eval active_handle_count, // so we will not end with an endless loop - if (this->state_changed_) + if (initial_handle_count == active_handle_count + || this->state_changed_) { - active_handle_count = this->dispatch_set_.rd_mask_.num_set () - + this->dispatch_set_.wr_mask_.num_set () - + this->dispatch_set_.ex_mask_.num_set (); + active_handle_count = this->any_ready (dispatch_set); } } while (active_handle_count > 0); diff --git a/ace/TP_Reactor.cpp b/ace/TP_Reactor.cpp index 1207cd7c93b..6773bf72ada 100644 --- a/ace/TP_Reactor.cpp +++ b/ace/TP_Reactor.cpp @@ -255,6 +255,10 @@ ACE_TP_Reactor::dispatch_i (ACE_Time_Value *max_wait_time, int event_count = this->get_event_for_dispatching (max_wait_time); + // We use this count to detect potential infinite loops as described + // in bug 2540. + int initial_event_count = event_count; + int result = 0; // Note: We are passing the around, to have record of @@ -310,8 +314,14 @@ ACE_TP_Reactor::dispatch_i (ACE_Time_Value *max_wait_time, if (event_count > 0) { // Handle socket events - return this->handle_socket_events (event_count, - guard); + result = this->handle_socket_events (event_count, + guard); + } + + if (event_count != 0 + && event_count == initial_event_count) + { + this->state_changed_ = true; } return 0; -- cgit v1.2.1