OSDN Git Service

DHA20091221分ソース反映
authormorisita <morisita@1ed66053-1c2d-0410-8867-f7571e6e31d3>
Tue, 22 Dec 2009 02:56:28 +0000 (02:56 +0000)
committermorisita <morisita@1ed66053-1c2d-0410-8867-f7571e6e31d3>
Tue, 22 Dec 2009 02:56:28 +0000 (02:56 +0000)
git-svn-id: http://10.144.169.20/repos/um/branches/l7vsd-3.x-ramiel@9302 1ed66053-1c2d-0410-8867-f7571e6e31d3

l7vsd/module/protocol/protocol_module_ip.cpp
l7vsd/module/protocol/protocol_module_ip.h
l7vsd/module/protocol/protocol_module_sessionless.cpp
l7vsd/module/protocol/protocol_module_sessionless.h
l7vsd/module/protocol/protocol_module_sslid.cpp
l7vsd/module/protocol/protocol_module_sslid.h

index 0b76738..26c51dc 100644 (file)
@@ -2060,25 +2060,25 @@ namespace l7vs
             //endpoint is matched
             if (ret == 0)
             {
-                //find the rs_endpoint in rs_list
-                rs_list_lock();
-
-                rs_list_itr = rs_list_begin();
                 int is_match = 0;
-
-                while ( rs_list_itr != rs_list_end())
+                //find the rs_endpoint in rs_list
                 {
+                    rs_list_scoped_lock scoped_lock(rs_list_lock, rs_list_unlock);
 
-                    if ( rs_list_itr->tcp_endpoint == rs_endpoint )
+                    rs_list_itr = rs_list_begin();
+                
+                    while ( rs_list_itr != rs_list_end())
                     {
-                        is_match = 1;
-                        break;
-                    }
 
-                    rs_list_itr = rs_list_next( rs_list_itr );
-                }
+                        if ( rs_list_itr->tcp_endpoint == rs_endpoint )
+                        {
+                            is_match = 1;
+                            break;
+                        }
 
-                rs_list_unlock();
+                        rs_list_itr = rs_list_next( rs_list_itr );
+                    }
+                }
 
                 //endpoint is matched in the list
                 if (is_match)
@@ -2104,8 +2104,11 @@ namespace l7vs
                     {
                         // init rs_endpoint
                         rs_endpoint = init_endpoint;
+                        {
+                            rs_list_scoped_lock scoped_lock(rs_list_lock, rs_list_unlock);
+                            schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, rs_endpoint);
+                        }
 
-                        schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, rs_endpoint);
                         /*-------- DEBUG LOG --------*/
                         if (unlikely(LOG_LV_DEBUG == getloglevel()))
                         {
@@ -2182,7 +2185,10 @@ namespace l7vs
                 rs_endpoint = init_endpoint;
 
                 //call schedule_module's schedule function, get realserver endpoint
-                schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, rs_endpoint);
+                {
+                    rs_list_scoped_lock scoped_lock(rs_list_lock, rs_list_unlock);
+                    schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, rs_endpoint);
+                }
 
                 /*-------- DEBUG LOG --------*/
                 if (unlikely(LOG_LV_DEBUG == getloglevel()))
index 16b46b7..6858a53 100644 (file)
@@ -105,7 +105,18 @@ namespace l7vs
         }
         return hash >> 32 - HASH_TABLE_BITS;
         }
-
+        class rs_list_scoped_lock {
+            protected: 
+                boost::function< void( void ) >    rs_list_unlock;
+            public:
+                rs_list_scoped_lock(boost::function< void( void ) >    inlist_lock,
+                                    boost::function< void( void ) >    inlist_unlock) 
+                {
+                    inlist_lock();
+                    rs_list_unlock = inlist_unlock; 
+                }
+                ~rs_list_scoped_lock() { rs_list_unlock(); }
+        };
 
     public:
         static const std::string MODULE_NAME;
index f46ee01..483a73a 100644 (file)
@@ -2277,7 +2277,11 @@ namespace l7vs
             }
 
             //call schedule_module's schedule function, get realserver endpoint
-            schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, rs_endpoint);
+            {
+                rs_list_scoped_lock scoped_lock(rs_list_lock, rs_list_unlock);
+                schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, rs_endpoint);
+            }
+
             /*-------- DEBUG LOG --------*/
             if (unlikely(LOG_LV_DEBUG == getloglevel()))
             {
index e3fa98c..24f832c 100644 (file)
@@ -276,6 +276,18 @@ public:
     }
 };
 
+class rs_list_scoped_lock {
+    protected: 
+        boost::function< void( void ) >    rs_list_unlock;
+    public:
+        rs_list_scoped_lock(boost::function< void( void ) >    inlist_lock,
+                            boost::function< void( void ) >    inlist_unlock) 
+        {
+            inlist_lock();
+            rs_list_unlock = inlist_unlock; 
+        }
+        ~rs_list_scoped_lock() { rs_list_unlock(); }
+};
 }
 
 #endif  //PROTOCOL_MODULE_SESSIONLESS_H
index 1212f9b..b037881 100644 (file)
@@ -1805,7 +1805,11 @@ protocol_module_base::EVENT_TAG protocol_module_sslid::handle_realserver_select(
                 // schedule the endpoint
                 boost::asio::ip::tcp::endpoint temp_endpoint;
                 boost::asio::ip::tcp::endpoint comp_endpoint;   // for compare the endpoint
-                schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, temp_endpoint);
+                {
+                    rs_list_scoped_lock scoped_lock(rs_list_lock, rs_list_unlock);
+                    schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, temp_endpoint);
+                }
+                
                 if (temp_endpoint != comp_endpoint)
                 {
                     // success for get the endpoint by reschedule
@@ -1851,21 +1855,23 @@ protocol_module_base::EVENT_TAG protocol_module_sslid::handle_realserver_select(
 
                 if (ret == 0)
                 {
+                    int is_match = 0;
                     //find the rs_endpoint in the rs_list
-                    rs_list_lock();
+                    {
+                        rs_list_scoped_lock scoped_lock(rs_list_lock, rs_list_unlock);
 
-                    rs_list_itr = rs_list_begin();
-                    int is_match = 0;
+                        rs_list_itr = rs_list_begin();
 
-                    while (rs_list_itr != rs_list_end())
-                    {
-                        if (rs_list_itr->tcp_endpoint == threaddata->selected_realserver)
+                        while (rs_list_itr != rs_list_end())
                         {
-                            is_match = 1;
-                            break;
-                        }
+                            if (rs_list_itr->tcp_endpoint == threaddata->selected_realserver)
+                            {
+                                is_match = 1;
+                                break;
+                            }
 
-                        rs_list_itr = rs_list_next(rs_list_itr);
+                            rs_list_itr = rs_list_next(rs_list_itr);
+                        }
                     }
 
                     if (is_match)
@@ -1882,7 +1888,11 @@ protocol_module_base::EVENT_TAG protocol_module_sslid::handle_realserver_select(
                             // reschedule mode
                             boost::asio::ip::tcp::endpoint temp_endpoint;
                             boost::asio::ip::tcp::endpoint comp_endpoint;   // for compare the endpoint
-                            schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, temp_endpoint);
+                            {
+                                rs_list_scoped_lock scoped_lock(rs_list_lock, rs_list_unlock);
+                                schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, temp_endpoint);
+                            }
+
                             if (temp_endpoint != comp_endpoint)
                             {
                             // get the endpoint by reschedule successfully
@@ -1935,7 +1945,11 @@ protocol_module_base::EVENT_TAG protocol_module_sslid::handle_realserver_select(
                         // reschedule mode
                         boost::asio::ip::tcp::endpoint temp_endpoint;
                         boost::asio::ip::tcp::endpoint comp_endpoint;   // for compare the endpoint
-                        schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, temp_endpoint);
+                        {
+                            rs_list_scoped_lock scoped_lock(rs_list_lock, rs_list_unlock);
+                            schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, temp_endpoint);
+                        }
+
                         if (temp_endpoint != comp_endpoint)
                         {
                             // get the endpoint by reschedule successfully
@@ -2398,7 +2412,7 @@ protocol_module_base::EVENT_TAG protocol_module_sslid::handle_realserver_send(
 //! called from after sorryserver select
 //! @param[in] upstream thread id
 //! @param[in] sorryserver endppiont reference
-//! @return session use EVENT mode(STOP).
+//! @return session use EVENT mode.
 protocol_module_base::EVENT_TAG protocol_module_sslid::handle_sorryserver_select(
     const boost::thread::id thread_id,
     boost::asio::ip::tcp::endpoint& sorry_endpoint)
@@ -2495,7 +2509,7 @@ protocol_module_base::EVENT_TAG protocol_module_sslid::handle_sorryserver_select
 //! @param[in] upstream thread id
 //! @param[out] send buffer reference.
 //! @param[out] send length
-//! @return session use EVENT mode(STOP).
+//! @return session use EVENT mode.
 protocol_module_base::EVENT_TAG protocol_module_sslid::handle_sorryserver_connect(
     const boost::thread::id thread_id,
     boost::array<char,MAX_BUFFER_SIZE>& sendbuffer,
@@ -2582,7 +2596,7 @@ protocol_module_base::EVENT_TAG protocol_module_sslid::handle_sorryserver_connec
 //! called from after sorryserver connection fail
 //! @param[in] upstream thread id
 //! @param[in] sorryserver endpoint reference.
-//! @return session use EVENT mode(STOP).
+//! @return session use EVENT mode.
 protocol_module_base::EVENT_TAG protocol_module_sslid::handle_sorryserver_connection_fail(
     const boost::thread::id thread_id,
     const boost::asio::ip::tcp::endpoint& sorry_endpoint)
@@ -2685,7 +2699,7 @@ protocol_module_base::EVENT_TAG protocol_module_sslid::handle_sorryserver_connec
 
 //! called from after sorryserver send
 //! @param[in] upstream thread id
-//! @return session use EVENT mode(STOP).
+//! @return session use EVENT mode.
 protocol_module_base::EVENT_TAG protocol_module_sslid::handle_sorryserver_send(
     const boost::thread::id thread_id)
 {
@@ -3148,7 +3162,7 @@ protocol_module_base::EVENT_TAG protocol_module_sslid::handle_realserver_recv(
 //! @param[in] sorryserver endpoint reference
 //! @param[in] recive from realserver buffer reference.
 //! @param[in] recv data length
-//! @return     session use EVENT mode(STOP).
+//! @return     session use EVENT mode.
 protocol_module_base::EVENT_TAG protocol_module_sslid::handle_sorryserver_recv(
     const boost::thread::id thread_id,
     const boost::asio::ip::tcp::endpoint& sorry_endpoint,
@@ -3944,7 +3958,7 @@ protocol_module_base::EVENT_TAG protocol_module_sslid::handle_client_disconnect(
 
 //! call from sorry mode event. use upstream thread and downstream thread
 //! @param[in] upstream and downstream thread id(check! one thread one event and first time call pattern)
-//! @return     session use EVENT mode(STOP).
+//! @return     session use EVENT mode.
 protocol_module_base::EVENT_TAG protocol_module_sslid::handle_sorry_enable(
     const boost::thread::id thread_id)
 {
@@ -4095,7 +4109,7 @@ protocol_module_base::EVENT_TAG protocol_module_sslid::handle_sorry_enable(
 
 //! call from sorry mode disable. use upstream thread and downstream thread.
 //! @param[in] upstream and downstream thread id(check! one thread one event)
-//! @return     session use EVENT mode(STOP).
+//! @return     session use EVENT mode.
 protocol_module_base::EVENT_TAG protocol_module_sslid::handle_sorry_disable(
     const boost::thread::id thread_id)
 {
index 203228a..a756879 100644 (file)
@@ -200,6 +200,18 @@ class protocol_module_sslid : public ssl_protocol_module_base
                                 const boost::thread::id& thread_id,
                                 boost::array<char, MAX_BUFFER_SIZE>& sendbuffer,
                                 size_t& datalen);
+        class rs_list_scoped_lock {
+            protected: 
+                boost::function< void( void ) >    rs_list_unlock;
+            public:
+                rs_list_scoped_lock(boost::function< void( void ) >    inlist_lock,
+                                    boost::function< void( void ) >    inlist_unlock) 
+                {
+                    inlist_lock();
+                    rs_list_unlock = inlist_unlock; 
+                }
+                ~rs_list_scoped_lock() { rs_list_unlock(); }
+        };
     protected:
         int timeout;
         int maxlist;