OSDN Git Service

Modify ssl shutdown.(Add async shutdown)
authorMichiro Hibari <l05102@shibaura-it.ac.jp>
Wed, 26 Nov 2014 08:27:04 +0000 (17:27 +0900)
committerMichiro Hibari <l05102@shibaura-it.ac.jp>
Wed, 26 Nov 2014 08:27:04 +0000 (17:27 +0900)
Ticket #34416

l7vsd/include/tcp_session.h
l7vsd/include/tcp_ssl_socket.h
l7vsd/src/tcp_session.cpp

index 9784024..4947def 100644 (file)
@@ -546,6 +546,7 @@ protected:
         virtual void down_thread_sorryserver_async_read_some_handler(const boost::system::error_code &error_code, std::size_t len);
         virtual void down_thread_sorryserver_handle_async_read_some(const TCP_PROCESS_TYPE_TAG);
        virtual void up_thread_client_ssl_socket_clear_socket_handler();
+        virtual void up_thread_client_disconnect_handler(const boost::system::error_code &error_code);
 
         //! down thread receive from realserver and raise module event of handle_realserver_recv
         //! @param[in]        process_type is process type
index be91894..64de5a4 100644 (file)
@@ -38,6 +38,7 @@ class   tcp_ssl_socket : public basic_tcp_socket< ssl_socket >
 public:
         // typedef
         typedef boost::function< void (const boost::system::error_code &) > async_handshake_handler_t;
+        typedef boost::function< void (const boost::system::error_code &) > async_shutdown_handler_t;
 
         // constructor
         tcp_ssl_socket(
@@ -124,6 +125,14 @@ public:
                 return error_code ? false : true;
         }
 
+        virtual void async_shutdown(async_handshake_handler_t  handler) {
+                boost::mutex::scoped_lock       lock(ssl_mutex);
+                boost::system::error_code       error_code;
+                shutdown_con++;
+                my_socket->lowest_layer().cancel(error_code);
+                my_socket->async_shutdown(ssl_strand.wrap(handler));
+        }
+
         virtual std::size_t     read_some(const boost::asio::mutable_buffers_1 &buffers, boost::system::error_code &error_code) {
                 boost::mutex::scoped_lock       lock(ssl_mutex);
                 if (write_con > 0 || handshake_con > 0) {
@@ -203,9 +212,19 @@ public:
                 return write_con;
         }
 
+        void decrement_shutdown_con() {
+                boost::mutex::scoped_lock       lock(ssl_mutex);
+                shutdown_con--;
+                ssl_cond.notify_one();
+        }
+
+        int get_shutdown_con() {
+                return shutdown_con;
+        }
+
         void wait_async_event_all_end() {
                 boost::mutex::scoped_lock       lock(ssl_mutex);
-                while (handshake_con > 0 || read_con > 0 || write_con > 0) {
+                while (handshake_con > 0 || read_con > 0 || write_con > 0 || shutdown_con > 0) {
                         boost::format   fmt("handshake_con : %d read_con = %d write_con = %d ");
                         fmt % handshake_con % read_con % write_con ;
                         Logger::putLogInfo(LOG_CAT_L7VSD_SESSION, 999, fmt.str(), __FILE__, __LINE__);
@@ -225,6 +244,7 @@ protected:
         int handshake_con;
         int read_con;
         int write_con;
+        int shutdown_con;
 
         virtual void set_quickack(boost::system::error_code &error_code) {
                 int err = ::setsockopt(my_socket->lowest_layer().native(), IPPROTO_TCP, TCP_QUICKACK, &opt_info.quickack_val, sizeof(opt_info.quickack_val));
index 1333c88..f7d4bbc 100644 (file)
@@ -1494,7 +1494,12 @@ void tcp_session::up_thread_client_disconnect(const TCP_PROCESS_TYPE_TAG process
                         fmt % boost::this_thread::get_id() % ec.message();
                         Logger::putLogInfo(LOG_CAT_L7VSD_SESSION, 999, fmt.str(), __FILE__, __LINE__);
 #endif
-                        func_tag = UP_FUNC_CLIENT_DISCONNECT;
+                        upthread_status = UPTHREAD_LOCK;
+                        tcp_ssl_socket::async_shutdown_handler_t   handler;
+                        handler = boost::bind(&tcp_session::up_thread_client_disconnect_handler, this, boost::asio::placeholders::error);
+                        client_ssl_socket.async_shutdown(handler);
+                        up_thread_next_call_function = up_thread_function_array[UP_FUNC_CLIENT_DISCONNECT_EVENT];
+                        return;
                 } else if (ec == boost::asio::error::eof) {
 #ifdef  DEBUG
                         boost::format   fmt("Thread ID[%d] ssl_shutdown fail: %s");
@@ -4121,6 +4126,37 @@ void tcp_session::down_thread_sorryserver_async_read_some_handler(const boost::s
         downthread_status_cond.notify_one();
 }
 
+void tcp_session::up_thread_client_disconnect_handler(const boost::system::error_code &error_code)
+{
+        if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
+               boost::format   fmt("Thread ID[%d] FUNC IN up_thread_client_disconnect_handler");
+               fmt % boost::this_thread::get_id();
+               Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 999, fmt.str(), __FILE__, __LINE__);
+        }
+
+        client_ssl_socket.decrement_shutdown_con();
+
+        tcp_thread_message     *up_msg = new tcp_thread_message();
+        if (error_code == boost::asio::error::try_again) {
+               tcp_ssl_socket::async_shutdown_handler_t   handler;
+               handler = boost::bind(&tcp_session::up_thread_client_disconnect_handler, this, boost::asio::placeholders::error);
+               client_ssl_socket.async_shutdown(handler);
+                up_thread_next_call_function = up_thread_function_array[UP_FUNC_CLIENT_DISCONNECT_EVENT];
+               return;
+        } else {
+               up_msg->message = up_que_function_map[UP_FUNC_CLIENT_DISCONNECT_EVENT];
+               while (!up_thread_message_que.push(up_msg)) {}
+        }
+
+        upthread_status_cond.notify_one();
+
+        if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
+               boost::format   fmt("Thread ID[%d] FUNC OUT up_thread_client_disconnect_handler");
+               fmt % boost::this_thread::get_id() ;
+               Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 999, fmt.str(), __FILE__, __LINE__);
+        }
+}
+
 void tcp_session::up_thread_client_ssl_socket_clear_socket_handler()
 {
         if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {