Index: Connection_Handler.cpp =================================================================== RCS file: /project/cvs-repository/ACE_wrappers-repository/TAO/tao/Connection_Handler.cpp,v retrieving revision 1.25 diff -u -r1.25 Connection_Handler.cpp --- Connection_Handler.cpp 10 Nov 2002 14:26:34 -0000 1.25 +++ Connection_Handler.cpp 11 Nov 2002 22:32:14 -0000 @@ -188,6 +188,12 @@ } ACE_ASSERT(this->reference_count_ == 0); + // Close the socket, implicitly this makes: + // get_handle() == ACE_INVALID_HANDLE + // At this point any further calls to handle_close() or + // close_connection() become no-ops + this->release_os_resources (); + delete this; return 0; @@ -386,7 +392,7 @@ ACE_DEBUG ((LM_DEBUG, "TAO (%P|%t) - Connection_Handler[%d]::" "close_connection, purging entry from cache\n", - id)); + handle)); } this->transport ()->purge_entry (); @@ -411,7 +417,7 @@ ACE_DEBUG ((LM_DEBUG, "TAO (%P|%t) - Connection_Handler[%d]::" "close_connection, removing from the reactor\n", - id)); + handle)); } int r = reactor->remove_handler (handle, @@ -422,7 +428,7 @@ ACE_ERROR ((LM_ERROR, "TAO (%P|%t) - Connection_Handler[%d]::" "close_connection, error in remove_handler (%d)\n", - id, r)); + handle, r)); } // Also cancel any timers, we may create those for time-limited @@ -431,8 +437,8 @@ { ACE_DEBUG ((LM_DEBUG, "TAO (%P|%t) - Connection_Handler[%d]::" - "close_connection, cancel all timers\n", - id)); + "close_connection, cancel all timers and refcount [%d]\n", + handle, reference_count_)); } r = reactor->cancel_timer (eh); if (r == -1 && TAO_debug_level) @@ -440,27 +446,22 @@ ACE_ERROR ((LM_ERROR, "TAO (%P|%t) - Connection_Handler[%d]::" "close_connection, error cancelling timers\n", - id)); + handle)); } // @@ This seems silly, the reactor is a much better authority to // find out if a handle is registered... this->transport ()->wait_strategy ()->is_registered (0); - // Close the socket, implicitly this makes: - // get_handle() == ACE_INVALID_HANDLE - // At this point any further calls to handle_close() or - // close_connection() become no-ops - r = this->release_os_resources (); - if (r == -1 && TAO_debug_level) + /*if (r == -1 && TAO_debug_level) { ACE_ERROR ((LM_ERROR, "TAO (%P|%t) - Connection_Handler[%d]::" "close_connection, release_os_resources() failed %p\n", - id, "")); - } + handle, "")); + } */ - ACE_ASSERT(eh->get_handle() == ACE_INVALID_HANDLE); + /*ACE_ASSERT(eh->get_handle() == ACE_INVALID_HANDLE); */ } ACE_ASSERT(this->transport () != 0); Index: Connection_Handler.h =================================================================== RCS file: /project/cvs-repository/ACE_wrappers-repository/TAO/tao/Connection_Handler.h,v retrieving revision 1.26 diff -u -r1.26 Connection_Handler.h --- Connection_Handler.h 22 Oct 2002 04:05:54 -0000 1.26 +++ Connection_Handler.h 11 Nov 2002 22:32:15 -0000 @@ -16,7 +16,7 @@ #include "ace/pre.h" -#include "LF_Event.h" +#include "LF_CH_Event.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once @@ -41,7 +41,7 @@ * right protocol. This way, most of the common code for the * different protocols would be in this implementation. */ -class TAO_Export TAO_Connection_Handler : public TAO_LF_Event +class TAO_Export TAO_Connection_Handler : public TAO_LF_CH_Event { public: @@ -104,15 +104,16 @@ /// Object. int svc_i (void); - /// Increment and decrement the number of upcalls that have gone - /// through this handler. Returns the upcall count. The calls are - /// thread safe.. - int incr_pending_upcalls (void); - - int decr_pending_upcalls (void); - - /// Query the upcall count - int pending_upcalls (void) const; + /**** + * Not sure where they are defined and used.. Looks legacy. + * + * Increment and decrement the number of upcalls that have gone + * this handler. Returns the upcall count. The calls are + * safe.. + * int incr_pending_upcalls (void); + * int decr_pending_upcalls (void); + * int pending_upcalls (void) const; + */ //@{ /** Index: IIOP_Connector.cpp =================================================================== RCS file: /project/cvs-repository/ACE_wrappers-repository/TAO/tao/IIOP_Connector.cpp,v retrieving revision 1.116 diff -u -r1.116 IIOP_Connector.cpp --- IIOP_Connector.cpp 10 Nov 2002 14:26:34 -0000 1.116 +++ IIOP_Connector.cpp 11 Nov 2002 22:32:15 -0000 @@ -194,8 +194,10 @@ // the refcount whether the connection is successful ot not. // REFCNT: Matches with TAO_Connect_Strategy<>::make_svc_handler() - svc_handler->decr_refcount (); + long refcount = svc_handler->decr_refcount (); + ACE_ASSERT (refcount >= 0); + if (result == -1) { // Give users a clue to the problem. Index: LF_Event.cpp =================================================================== RCS file: /project/cvs-repository/ACE_wrappers-repository/TAO/tao/LF_Event.cpp,v retrieving revision 1.4 diff -u -r1.4 LF_Event.cpp --- LF_Event.cpp 27 Apr 2002 21:49:58 -0000 1.4 +++ LF_Event.cpp 11 Nov 2002 22:32:16 -0000 @@ -1,9 +1,8 @@ // -*- C++ -*- // $Id: LF_Event.cpp,v 1.4 2002/04/27 21:49:58 bala Exp $ - #include "tao/LF_Event.h" -#include "tao/LF_Follower.h" -#include "tao/Leader_Follower.h" +#include "LF_Follower.h" +#include "Leader_Follower.h" #if !defined (__ACE_INLINE__) # include "tao/LF_Event.inl" @@ -35,91 +34,20 @@ ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, leader_follower.lock ()); - if (is_state_final ()== 0 && - this->follower_ != 0) + if (this->is_state_final () == 0) { this->state_changed_i (new_state); - this->follower_->signal (); + /// Sort of double-checked optimization.. + if (this->follower_ != 0) + this->follower_->signal (); } } } -void -TAO_LF_Event::state_changed_i (int new_state) -{ - if (this->state_ == new_state) - return; - // Validate the state change - if (this->state_ == TAO_LF_Event::LFS_IDLE) - { - // From the LFS_IDLE state we can only become active. - if (new_state == TAO_LF_Event::LFS_ACTIVE - || new_state == TAO_LF_Event::LFS_CONNECTION_WAIT - || new_state == TAO_LF_Event::LFS_CONNECTION_CLOSED) - this->state_ = new_state; - return; - } - else if (this->state_ == TAO_LF_Event::LFS_ACTIVE) - { - // From LFS_ACTIVE we can only move to a few states - if (new_state != TAO_LF_Event::LFS_IDLE) - { - if (new_state == TAO_LF_Event::LFS_CONNECTION_CLOSED) - { - this->state_ = TAO_LF_Event::LFS_FAILURE; - } - else - { - this->state_ = new_state; - } - } - return; - } - else if (this->state_ == TAO_LF_Event::LFS_CONNECTION_WAIT) - { - // From LFS_CONNECTION_WAIT we can only move to a few states - if (new_state != TAO_LF_Event::LFS_IDLE) - { - if (new_state == TAO_LF_Event::LFS_CONNECTION_CLOSED) - { - this->state_ = TAO_LF_Event::LFS_FAILURE; - } - else - { - this->state_ = new_state; - } - } - return; - } - else if (this->state_ == TAO_LF_Event::LFS_SUCCESS - || this->state_ == TAO_LF_Event::LFS_CONNECTION_CLOSED) - { - // From the two states above we can go back to ACTIVE, as when a - // request is restarted. - if (new_state == TAO_LF_Event::LFS_ACTIVE) - { - this->state_ = new_state; - } - return; - } - else /* if (this->state_ == TAO_LF_Event::LFS_TIMEOUT || FAILURE ) */ - { - // Other states are final... - } -} - -int -TAO_LF_Event::successful (void) const -{ - return this->state_ == TAO_LF_Event::LFS_SUCCESS; -} - -int -TAO_LF_Event::error_detected (void) const +void +TAO_LF_Event::set_state (int new_state) { - return (this->state_ == TAO_LF_Event::LFS_FAILURE - || this->state_ == TAO_LF_Event::LFS_TIMEOUT - || this->state_ == TAO_LF_Event::LFS_CONNECTION_CLOSED); + this->state_ = new_state; } Index: LF_Event.h =================================================================== RCS file: /project/cvs-repository/ACE_wrappers-repository/TAO/tao/LF_Event.h,v retrieving revision 1.6 diff -u -r1.6 LF_Event.h --- LF_Event.h 23 May 2002 22:34:10 -0000 1.6 +++ LF_Event.h 11 Nov 2002 22:32:17 -0000 @@ -31,7 +31,7 @@ * responses, as well as to wait for all the data to be flushed. * This class encapsulates this event loop. It uses Template Method to * parametrize the 'waited for' predicate (i.e. reply received or - * message sent.) + * message sent or connection establishment etc.) * * @todo Implementing the Leader/Followers loop in this class, as * well as the callbacks to communicate that an event has completed @@ -71,19 +71,17 @@ * * A Leader/Followers event goes through several states during its * lifetime. We use an enum to represent those states and state - * changes are validated according to the rules below. - * + * changes are validated according to the rules defined in the + * concrete classes. We treat the states as finite states in a + * FSM. The possible sequence of states through which the FSM + * migrates is defined in the concrete classes. */ enum { - /// The event is created, initial state can only move to - /// LFS_ACTIVE or LFS_CONNECTION_WAIT - LFS_IDLE, - /// The event is active, can change to any of the following - /// states, each of them is a final state + /// The event is created, and is in initial state + LFS_IDLE = 0, + /// The event is active LFS_ACTIVE, - /// The event is waiting for connection completion. It can change - /// to the any of the following states, each of them being a final - /// state. + /// The event is waiting for connection completion. LFS_CONNECTION_WAIT, /// The event has completed successfully LFS_SUCCESS, @@ -91,45 +89,50 @@ LFS_FAILURE, /// The event has timed out LFS_TIMEOUT, - /// The connection was closed while the state was active + /// The connection was closed. LFS_CONNECTION_CLOSED }; - /// Change the state + /** + * Virtual methods for this class hierarchy.. + */ + /// Accessor to change the state. The state isnt changed unless + /// certain conditions are satisfied. void state_changed (int new_state); /// Return 1 if the condition was satisfied successfully, 0 if it /// has not - int successful (void) const; + virtual int successful (void) const = 0 ; /// Return 1 if an error was detected while waiting for the /// event - int error_detected (void) const; - //@} + virtual int error_detected (void) const = 0; /// Check if we should keep waiting. int keep_waiting (void); + //@} /// Reset the state, irrespective of the previous states void reset_state (int new_state); protected: - /// Validate the state change - void state_changed_i (int new_state); -private: + /// Validate the state change + virtual void state_changed_i (int new_state) = 0; /// Check whether we have reached the final state.. - int is_state_final (void); - - /// Set the state. - void set_state (int new_state); + virtual int is_state_final (void) = 0; private: + + /// Set the state irrespective of anything. + virtual void set_state (int new_state); + +protected: /// The current state int state_; - /// The bound follower thread + /// The bounded follower TAO_LF_Follower *follower_; }; Index: LF_Event.inl =================================================================== RCS file: /project/cvs-repository/ACE_wrappers-repository/TAO/tao/LF_Event.inl,v retrieving revision 1.4 diff -u -r1.4 LF_Event.inl --- LF_Event.inl 2 Nov 2001 13:10:40 -0000 1.4 +++ LF_Event.inl 11 Nov 2002 22:32:18 -0000 @@ -1,11 +1,6 @@ +// -*- C++ -*- // $Id: LF_Event.inl,v 1.4 2001/11/02 13:10:40 bala Exp $ -ACE_INLINE void -TAO_LF_Event::reset_state (int new_state) -{ - this->state_ = new_state; -} - ACE_INLINE int TAO_LF_Event::bind (TAO_LF_Follower *follower) { @@ -16,28 +11,18 @@ } ACE_INLINE int -TAO_LF_Event::is_state_final (void) +TAO_LF_Event::unbind (void) { - if (this->state_ == TAO_LF_Event::LFS_TIMEOUT || - this->state_ == TAO_LF_Event::LFS_FAILURE) - return 1; - + if (this->follower_ == 0) + return -1; + this->follower_ = 0; return 0; } ACE_INLINE void -TAO_LF_Event::set_state (int new_state) +TAO_LF_Event::reset_state (int new_state) { this->state_ = new_state; -} - -ACE_INLINE int -TAO_LF_Event::unbind (void) -{ - if (this->follower_ == 0) - return -1; - this->follower_ = 0; - return 0; } ACE_INLINE int Index: Leader_Follower.cpp =================================================================== RCS file: /project/cvs-repository/ACE_wrappers-repository/TAO/tao/Leader_Follower.cpp,v retrieving revision 1.19 diff -u -r1.19 Leader_Follower.cpp --- Leader_Follower.cpp 18 Jun 2002 18:33:47 -0000 1.19 +++ Leader_Follower.cpp 11 Nov 2002 22:32:19 -0000 @@ -262,7 +262,7 @@ tv += *max_wait_time; if (follower->wait (&tv) == -1) { - if (TAO_debug_level >= 5) + // if (TAO_debug_level >= 5) ACE_DEBUG ((LM_DEBUG, "TAO (%P|%t) - Leader_Follower[%d]::wait, " "(follower) [has timer, follower failed]\n", @@ -316,9 +316,10 @@ if (TAO_debug_level >= 5) ACE_DEBUG ((LM_DEBUG, "TAO (%P|%t) - Leader_Follower[%d]::wait_for_event," - " done (follower), successful %d\n", + " done (follower), successful %d , errors %d\n", transport->id (), - event->successful ())); + event->successful (), + event->error_detected ())); // Now somebody woke us up to become a leader or to handle our // input. We are already removed from the follower queue. Index: Queued_Message.h =================================================================== RCS file: /project/cvs-repository/ACE_wrappers-repository/TAO/tao/Queued_Message.h,v retrieving revision 1.6 diff -u -r1.6 Queued_Message.h --- Queued_Message.h 28 Jul 2002 14:11:49 -0000 1.6 +++ Queued_Message.h 11 Nov 2002 22:32:19 -0000 @@ -20,7 +20,7 @@ # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ -#include "LF_Event.h" +#include "LF_Invocation_Event.h" class ACE_Message_Block; class ACE_Allocator; @@ -62,7 +62,7 @@ * allocating the memory? * */ -class TAO_Export TAO_Queued_Message : public TAO_LF_Event +class TAO_Export TAO_Queued_Message : public TAO_LF_Invocation_Event { public: /// Constructor Index: Synch_Reply_Dispatcher.h =================================================================== RCS file: /project/cvs-repository/ACE_wrappers-repository/TAO/tao/Synch_Reply_Dispatcher.h,v retrieving revision 1.10 diff -u -r1.10 Synch_Reply_Dispatcher.h --- Synch_Reply_Dispatcher.h 8 Feb 2002 01:07:35 -0000 1.10 +++ Synch_Reply_Dispatcher.h 11 Nov 2002 22:32:20 -0000 @@ -20,14 +20,15 @@ #include "ace/pre.h" #include "tao/Reply_Dispatcher.h" -#include "tao/LF_Event.h" -#include "tao/GIOP_Message_Version.h" -#include "tao/CDR.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ +#include "tao/LF_Invocation_Event.h" +#include "tao/GIOP_Message_Version.h" +#include "tao/CDR.h" + class TAO_Pluggable_Reply_Params; /** @@ -38,7 +39,7 @@ */ class TAO_Export TAO_Synch_Reply_Dispatcher : public TAO_Reply_Dispatcher - , public TAO_LF_Event + , public TAO_LF_Invocation_Event { public: Index: Transport.cpp =================================================================== RCS file: /project/cvs-repository/ACE_wrappers-repository/TAO/tao/Transport.cpp,v retrieving revision 1.69 diff -u -r1.69 Transport.cpp --- Transport.cpp 22 Oct 2002 04:05:54 -0000 1.69 +++ Transport.cpp 11 Nov 2002 22:32:21 -0000 @@ -5,6 +5,7 @@ #include "Exception.h" #include "ORB_Core.h" +#include "Leader_Follower.h" #include "Client_Strategy_Factory.h" #include "Wait_Strategy.h" #include "Transport_Mux_Strategy.h" @@ -692,7 +693,15 @@ return; } - eh->close_connection (); + // eh->close_connection (); + ACE_Time_Value tv (5, 0); + + int retval = + this->orb_core_->leader_follower ().wait_for_event (eh, + this, + &tv); + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) ********************* \n")); this->send_connection_closed_notifications ();