OSDN Git Service

#443 fix
authortanuma <tanuma@1ed66053-1c2d-0410-8867-f7571e6e31d3>
Thu, 28 Jan 2010 11:20:42 +0000 (11:20 +0000)
committertanuma <tanuma@1ed66053-1c2d-0410-8867-f7571e6e31d3>
Thu, 28 Jan 2010 11:20:42 +0000 (11:20 +0000)
git-svn-id: http://10.144.169.20/repos/um/branches/l7vsd-3.x-ramiel@9940 1ed66053-1c2d-0410-8867-f7571e6e31d3

l7vsd/include/virtualservice.h
l7vsd/src/virtualservice_base.cpp
l7vsd/src/virtualservice_tcp.cpp

index 06fd6e9..e30444c 100644 (file)
@@ -128,6 +128,8 @@ public:
                                     tcp_schedule_func_type;
 
     typedef l7vs::atomic<unsigned long long> AUUL;
+       //typedef l7vs::atomic<unsigned int> AUI;
+
 
     //!    @struct    replication_header replication header structure
     struct    replication_header{
@@ -212,6 +214,9 @@ protected:
     AUUL wait_count_up;         //! upstream recv wait count
     AUUL wait_count_down;       //! downstream recv wait count
 
+       AUUL    ir_running;
+       AUUL    stop_flag;
+
     // protocol module option string
     std::string             protocol_module_for_indication_options;
 
@@ -264,7 +269,7 @@ public:
     explicit virtualservice_base( const l7vsd&,
                                   const replication&,
                                   const virtualservice_element& );
-    virtual ~virtualservice_base(){};
+    virtual ~virtualservice_base(){ dispatcher.reset();dispatcher.stop(); };
 
     virtual void initialize( error_code& ) = 0;
     virtual void finalize( error_code& ) = 0;
index dba86f9..67eae2e 100644 (file)
@@ -63,6 +63,9 @@ l7vs::virtualservice_base::virtualservice_base(    const l7vs::l7vsd& invsd,
     wait_count_up    = 0;
     wait_count_down    = 0;
 
+       ir_running = 0;
+       stop_flag = 0;
+
     calc_bps_timer.reset( new boost::asio::deadline_timer( dispatcher ) );
     replication_timer.reset( new boost::asio::deadline_timer( dispatcher ) );
     protomod_rep_timer.reset( new boost::asio::deadline_timer( dispatcher ) );
@@ -158,11 +161,18 @@ void    l7vs::virtualservice_base::handle_protomod_replication( const boost::sys
     }
     if( likely( !err ) ){
         if( likely( NULL != protomod ) ){
+
+               ir_running++;
+
             protomod->replication_interrupt();
+               if(0!=stop_flag.get()){
             //register handle_protomod_replication
             protomod_rep_timer->expires_from_now( boost::posix_time::milliseconds( param_data.rep_interval ) );
             protomod_rep_timer->async_wait( boost::bind( &l7vs::virtualservice_tcp::handle_protomod_replication, 
                                                     this, boost::asio::placeholders::error ) );
+               }
+               ir_running--;
+
         }else{
             l7vs::Logger::putLogError( l7vs::LOG_CAT_L7VSD_VIRTUALSERVICE_THREAD, 1, PROTOMOD_NOTLOAD_ERROR_MSG, __FILE__, __LINE__ );
         }
@@ -190,11 +200,20 @@ void    l7vs::virtualservice_base::handle_schedmod_replication( const boost::sys
     }
     if( likely( !err ) ){
         if( likely( NULL != schedmod ) ){
+
+               //si_runnig
+               ir_running++;
+
+               if(0!=stop_flag.get()){
             schedmod->replication_interrupt();
             //register handle_schedmod_replication
             schedmod_rep_timer->expires_from_now( boost::posix_time::milliseconds( param_data.rep_interval ) );
             schedmod_rep_timer->async_wait( boost::bind( &l7vs::virtualservice_tcp::handle_schedmod_replication, 
                                                     this, boost::asio::placeholders::error ) );
+
+               }
+               ir_running--;
+
         }else{
             l7vs::Logger::putLogError( l7vs::LOG_CAT_L7VSD_VIRTUALSERVICE_THREAD, 3, SCHEDMOD_NOTLOAD_ERROR_MSG, __FILE__, __LINE__ );
         }
@@ -276,9 +295,11 @@ void    l7vs::virtualservice_base::handle_throughput_update( const boost::system
         }
 
         //register timer event
+       if(0!=stop_flag.get()){
         calc_bps_timer->expires_from_now( boost::posix_time::milliseconds( param_data.bps_interval ) );
         calc_bps_timer->async_wait( boost::bind( &l7vs::virtualservice_tcp::handle_throughput_update, 
                                                 this, boost::asio::placeholders::error ) );
+       }
         if( unlikely( LOG_LV_DEBUG == l7vs::Logger::getLogLevel( l7vs::LOG_CAT_L7VSD_VIRTUALSERVICE_THREAD ) ) ){
             boost::format formatter1("throughput(upstream) dump   : %d, wait_count_up dump  : %d");
             formatter1 % throughput_up.get() % wait_count_up.get();
index e2a2ff0..47611db 100644 (file)
@@ -175,9 +175,12 @@ void    l7vs::virtualservice_tcp::handle_replication_interrupt( const boost::sys
     rep_noconst.unlock( REP_AREA_NAME );
 
     //register handle_replication_interrupt
+
+       if(0!=stop_flag.get()){
     replication_timer->expires_from_now( boost::posix_time::milliseconds( param_data.rep_interval ) );
     replication_timer->async_wait( boost::bind( &virtualservice_tcp::handle_replication_interrupt, 
                                             this, boost::asio::placeholders::error ) );
+       }
 
     if( unlikely( LOG_LV_DEBUG == Logger::getLogLevel( LOG_CAT_L7VSD_VIRTUALSERVICE ) ) ){
         Logger::putLogDebug( LOG_CAT_L7VSD_VIRTUALSERVICE, 21, "out_function : void virtualservice_tcp::handle_replication_interrupt( const boost::system::error_code& err )", __FILE__, __LINE__ );
@@ -726,6 +729,14 @@ void    l7vs::virtualservice_tcp::initialize( l7vs::error_code& err ){
                 }
                 return;
             }
+            catch( ... ){
+                Logger::putLogFatal( 
+                    LOG_CAT_L7VSD_VIRTUALSERVICE, 999, "unknown error, create session.", __FILE__, __LINE__ );
+                if( unlikely( LOG_LV_DEBUG == Logger::getLogLevel( LOG_CAT_L7VSD_VIRTUALSERVICE ) ) ){
+                    Logger::putLogDebug( LOG_CAT_L7VSD_VIRTUALSERVICE, 999, "out_function : void virtualservice_tcp::initialize( l7vs::error_code& err ) : unknown error.", __FILE__, __LINE__ );
+                }
+                return;
+            }
         }
         if( unlikely( LOG_LV_DEBUG == Logger::getLogLevel( LOG_CAT_L7VSD_VIRTUALSERVICE ) ) ){
             boost::format    fmt1( "pool_session.size   = %d" );
@@ -768,7 +779,7 @@ void        l7vs::virtualservice_tcp::finalize( l7vs::error_code& err ){
     }
 
     //stop main loop
-    stop();
+    //stop();
 
     while(active_sessions.size()){
         boost::this_thread::yield();
@@ -861,7 +872,7 @@ void        l7vs::virtualservice_tcp::finalize( l7vs::error_code& err ){
         }
     }
 
-    vsd.release_virtual_service( element );
+    //vsd.release_virtual_service( element );
 
     if( access_log_file_name != "" ) {
         // erase access log instance.
@@ -874,6 +885,8 @@ void        l7vs::virtualservice_tcp::finalize( l7vs::error_code& err ){
                                    __FILE__, __LINE__ );
         }
     }
+
+    vsd.release_virtual_service( element );
     
     err.setter( false, "" );
 
@@ -1464,12 +1477,26 @@ void    l7vs::virtualservice_tcp::stop(){
 
     boost::system::error_code    err;
 
+       stop_flag++;
+
+       while(ir_running.get()){
+               boost::this_thread::yield();
+       }
+
     acceptor_.close( err );
     if( err ){
         Logger::putLogError( LOG_CAT_L7VSD_VIRTUALSERVICE, 18, err.message(), __FILE__, __LINE__ );
     }
 
     //stop dispatcher
+
+       size_t ret1 = calc_bps_timer->cancel();
+       size_t ret2 = replication_timer->cancel();
+       size_t ret3 = protomod_rep_timer->cancel();
+       size_t ret4 = schedmod_rep_timer->cancel();
+
+        Logger::putLogError( LOG_CAT_L7VSD_VIRTUALSERVICE, 18, (boost::format("ret1=%d,ret2=%d,ret3=%d,ret4=%d") % ret1 % ret2 % ret3 % ret4).str(), __FILE__, __LINE__ );
+       dispatcher.reset();
     dispatcher.stop();
 }