UltraMonkey-L7 V3(multi-thread implementation)
リビジョン | 7132b467e1d718a052b301189b6a502f557d1d81 (tree) |
---|---|
日時 | 2014-11-26 17:27:04 |
作者 | Michiro Hibari <l05102@shib...> |
コミッター | Michiro Hibari |
Modify ssl shutdown.(Add async shutdown)
Ticket #34416
@@ -546,6 +546,7 @@ protected: | ||
546 | 546 | virtual void down_thread_sorryserver_async_read_some_handler(const boost::system::error_code &error_code, std::size_t len); |
547 | 547 | virtual void down_thread_sorryserver_handle_async_read_some(const TCP_PROCESS_TYPE_TAG); |
548 | 548 | virtual void up_thread_client_ssl_socket_clear_socket_handler(); |
549 | + virtual void up_thread_client_disconnect_handler(const boost::system::error_code &error_code); | |
549 | 550 | |
550 | 551 | //! down thread receive from realserver and raise module event of handle_realserver_recv |
551 | 552 | //! @param[in] process_type is process type |
@@ -38,6 +38,7 @@ class tcp_ssl_socket : public basic_tcp_socket< ssl_socket > | ||
38 | 38 | public: |
39 | 39 | // typedef |
40 | 40 | typedef boost::function< void (const boost::system::error_code &) > async_handshake_handler_t; |
41 | + typedef boost::function< void (const boost::system::error_code &) > async_shutdown_handler_t; | |
41 | 42 | |
42 | 43 | // constructor |
43 | 44 | tcp_ssl_socket( |
@@ -124,6 +125,14 @@ public: | ||
124 | 125 | return error_code ? false : true; |
125 | 126 | } |
126 | 127 | |
128 | + virtual void async_shutdown(async_handshake_handler_t handler) { | |
129 | + boost::mutex::scoped_lock lock(ssl_mutex); | |
130 | + boost::system::error_code error_code; | |
131 | + shutdown_con++; | |
132 | + my_socket->lowest_layer().cancel(error_code); | |
133 | + my_socket->async_shutdown(ssl_strand.wrap(handler)); | |
134 | + } | |
135 | + | |
127 | 136 | virtual std::size_t read_some(const boost::asio::mutable_buffers_1 &buffers, boost::system::error_code &error_code) { |
128 | 137 | boost::mutex::scoped_lock lock(ssl_mutex); |
129 | 138 | if (write_con > 0 || handshake_con > 0) { |
@@ -203,9 +212,19 @@ public: | ||
203 | 212 | return write_con; |
204 | 213 | } |
205 | 214 | |
215 | + void decrement_shutdown_con() { | |
216 | + boost::mutex::scoped_lock lock(ssl_mutex); | |
217 | + shutdown_con--; | |
218 | + ssl_cond.notify_one(); | |
219 | + } | |
220 | + | |
221 | + int get_shutdown_con() { | |
222 | + return shutdown_con; | |
223 | + } | |
224 | + | |
206 | 225 | void wait_async_event_all_end() { |
207 | 226 | boost::mutex::scoped_lock lock(ssl_mutex); |
208 | - while (handshake_con > 0 || read_con > 0 || write_con > 0) { | |
227 | + while (handshake_con > 0 || read_con > 0 || write_con > 0 || shutdown_con > 0) { | |
209 | 228 | boost::format fmt("handshake_con : %d read_con = %d write_con = %d "); |
210 | 229 | fmt % handshake_con % read_con % write_con ; |
211 | 230 | Logger::putLogInfo(LOG_CAT_L7VSD_SESSION, 999, fmt.str(), __FILE__, __LINE__); |
@@ -225,6 +244,7 @@ protected: | ||
225 | 244 | int handshake_con; |
226 | 245 | int read_con; |
227 | 246 | int write_con; |
247 | + int shutdown_con; | |
228 | 248 | |
229 | 249 | virtual void set_quickack(boost::system::error_code &error_code) { |
230 | 250 | int err = ::setsockopt(my_socket->lowest_layer().native(), IPPROTO_TCP, TCP_QUICKACK, &opt_info.quickack_val, sizeof(opt_info.quickack_val)); |
@@ -1494,7 +1494,12 @@ void tcp_session::up_thread_client_disconnect(const TCP_PROCESS_TYPE_TAG process | ||
1494 | 1494 | fmt % boost::this_thread::get_id() % ec.message(); |
1495 | 1495 | Logger::putLogInfo(LOG_CAT_L7VSD_SESSION, 999, fmt.str(), __FILE__, __LINE__); |
1496 | 1496 | #endif |
1497 | - func_tag = UP_FUNC_CLIENT_DISCONNECT; | |
1497 | + upthread_status = UPTHREAD_LOCK; | |
1498 | + tcp_ssl_socket::async_shutdown_handler_t handler; | |
1499 | + handler = boost::bind(&tcp_session::up_thread_client_disconnect_handler, this, boost::asio::placeholders::error); | |
1500 | + client_ssl_socket.async_shutdown(handler); | |
1501 | + up_thread_next_call_function = up_thread_function_array[UP_FUNC_CLIENT_DISCONNECT_EVENT]; | |
1502 | + return; | |
1498 | 1503 | } else if (ec == boost::asio::error::eof) { |
1499 | 1504 | #ifdef DEBUG |
1500 | 1505 | 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 | ||
4121 | 4126 | downthread_status_cond.notify_one(); |
4122 | 4127 | } |
4123 | 4128 | |
4129 | +void tcp_session::up_thread_client_disconnect_handler(const boost::system::error_code &error_code) | |
4130 | +{ | |
4131 | + if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) { | |
4132 | + boost::format fmt("Thread ID[%d] FUNC IN up_thread_client_disconnect_handler"); | |
4133 | + fmt % boost::this_thread::get_id(); | |
4134 | + Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 999, fmt.str(), __FILE__, __LINE__); | |
4135 | + } | |
4136 | + | |
4137 | + client_ssl_socket.decrement_shutdown_con(); | |
4138 | + | |
4139 | + tcp_thread_message *up_msg = new tcp_thread_message(); | |
4140 | + if (error_code == boost::asio::error::try_again) { | |
4141 | + tcp_ssl_socket::async_shutdown_handler_t handler; | |
4142 | + handler = boost::bind(&tcp_session::up_thread_client_disconnect_handler, this, boost::asio::placeholders::error); | |
4143 | + client_ssl_socket.async_shutdown(handler); | |
4144 | + up_thread_next_call_function = up_thread_function_array[UP_FUNC_CLIENT_DISCONNECT_EVENT]; | |
4145 | + return; | |
4146 | + } else { | |
4147 | + up_msg->message = up_que_function_map[UP_FUNC_CLIENT_DISCONNECT_EVENT]; | |
4148 | + while (!up_thread_message_que.push(up_msg)) {} | |
4149 | + } | |
4150 | + | |
4151 | + upthread_status_cond.notify_one(); | |
4152 | + | |
4153 | + if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) { | |
4154 | + boost::format fmt("Thread ID[%d] FUNC OUT up_thread_client_disconnect_handler"); | |
4155 | + fmt % boost::this_thread::get_id() ; | |
4156 | + Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 999, fmt.str(), __FILE__, __LINE__); | |
4157 | + } | |
4158 | +} | |
4159 | + | |
4124 | 4160 | void tcp_session::up_thread_client_ssl_socket_clear_socket_handler() |
4125 | 4161 | { |
4126 | 4162 | if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) { |