Revisão | 90b6f924a1bee5202b076d0dcddb6b7d04aca26c (tree) |
---|---|
Hora | 2010-11-08 21:25:41 |
Autor | 0809216 <0809216@1ed6...> |
Commiter | 0809216 |
change tcp_session
git-svn-id: http://10.144.169.20/repos/um/branches/l7vsd-3.x-ramiel-epoll-cond@10426 1ed66053-1c2d-0410-8867-f7571e6e31d3
@@ -57,7 +57,7 @@ tcp_session::tcp_session( | ||
57 | 57 | : |
58 | 58 | io(session_io), |
59 | 59 | parent_service(vs), |
60 | - exit_flag(false), | |
60 | + exit_flag(0), | |
61 | 61 | upthread_status(UPTHREAD_SLEEP), |
62 | 62 | downthread_status(DOWNTHREAD_SLEEP), |
63 | 63 | realserver_connect_status(false), |
@@ -342,7 +342,7 @@ session_result_message tcp_session::initialize() | ||
342 | 342 | session_result_message msg; |
343 | 343 | msg.flag = false; |
344 | 344 | msg.message = ""; |
345 | - exit_flag = false; | |
345 | + exit_flag = 0; | |
346 | 346 | up_thread_id = boost::thread::id(); |
347 | 347 | down_thread_id = boost::thread::id(); |
348 | 348 | ssl_handshake_timer_flag = false; |
@@ -843,7 +843,7 @@ void tcp_session::up_thread_run() | ||
843 | 843 | Logger::putLogError(LOG_CAT_L7VSD_SESSION, 9, buf.str(), __FILE__, __LINE__); |
844 | 844 | { |
845 | 845 | rw_scoped_lock scoped_lock(exit_flag_update_mutex); |
846 | - exit_flag = true; | |
846 | + __sync_bool_compare_and_swap(&exit_flag, 0, 1); | |
847 | 847 | } |
848 | 848 | } |
849 | 849 | } |
@@ -865,7 +865,7 @@ void tcp_session::up_thread_run() | ||
865 | 865 | Logger::putLogError(LOG_CAT_L7VSD_SESSION, 10, buf.str(), __FILE__, __LINE__); |
866 | 866 | { |
867 | 867 | rw_scoped_lock scoped_lock(exit_flag_update_mutex); |
868 | - exit_flag = true; | |
868 | + __sync_bool_compare_and_swap(&exit_flag, 0, 1); | |
869 | 869 | } |
870 | 870 | } |
871 | 871 | } |
@@ -881,7 +881,7 @@ void tcp_session::up_thread_run() | ||
881 | 881 | Logger::putLogError(LOG_CAT_L7VSD_SESSION, 11, buf.str(), __FILE__, __LINE__); |
882 | 882 | { |
883 | 883 | rw_scoped_lock scoped_lock(exit_flag_update_mutex); |
884 | - exit_flag = true; | |
884 | + __sync_bool_compare_and_swap(&exit_flag, 0, 1); | |
885 | 885 | } |
886 | 886 | } |
887 | 887 | } |
@@ -904,7 +904,7 @@ void tcp_session::up_thread_run() | ||
904 | 904 | Logger::putLogError(LOG_CAT_L7VSD_SESSION, 12, buf.str(), __FILE__, __LINE__); |
905 | 905 | { |
906 | 906 | rw_scoped_lock scoped_lock(exit_flag_update_mutex); |
907 | - exit_flag = true; | |
907 | + __sync_bool_compare_and_swap(&exit_flag, 0, 1); | |
908 | 908 | } |
909 | 909 | } |
910 | 910 | } |
@@ -928,7 +928,7 @@ void tcp_session::up_thread_run() | ||
928 | 928 | Logger::putLogError(LOG_CAT_L7VSD_SESSION, 13, buf.str(), __FILE__, __LINE__); |
929 | 929 | { |
930 | 930 | rw_scoped_lock scoped_lock(exit_flag_update_mutex); |
931 | - exit_flag = true; | |
931 | + __sync_bool_compare_and_swap(&exit_flag, 0, 1); | |
932 | 932 | } |
933 | 933 | } |
934 | 934 | } |
@@ -1044,7 +1044,7 @@ void tcp_session::up_thread_run() | ||
1044 | 1044 | } |
1045 | 1045 | { |
1046 | 1046 | rw_scoped_lock scoped_lock(exit_flag_update_mutex); |
1047 | - if( !__sync_bool_compare_and_swap( &exit_flag, true, 2 ) ){ | |
1047 | + if( !__sync_bool_compare_and_swap( &exit_flag, 1, 2 ) ){ | |
1048 | 1048 | parent_service.release_session(this); |
1049 | 1049 | } |
1050 | 1050 | } |
@@ -1175,7 +1175,7 @@ void tcp_session::down_thread_run() | ||
1175 | 1175 | |
1176 | 1176 | { |
1177 | 1177 | rw_scoped_lock scoped_lock(exit_flag_update_mutex); |
1178 | - if( !__sync_bool_compare_and_swap( &exit_flag, true, 2 ) ){ | |
1178 | + if( !__sync_bool_compare_and_swap( &exit_flag, 1, 2 ) ){ | |
1179 | 1179 | parent_service.release_session(this); |
1180 | 1180 | } |
1181 | 1181 | } |
@@ -1399,6 +1399,11 @@ void tcp_session::up_thread_client_receive(const TCP_PROCESS_TYPE_TAG process_ty | ||
1399 | 1399 | event.data.fd = !ssl_flag ? client_socket.get_socket().native() |
1400 | 1400 | : client_ssl_socket.get_socket().lowest_layer().native(); |
1401 | 1401 | |
1402 | + if (event.data.fd == -1) { | |
1403 | + up_thread_next_call_function = up_thread_function_array[UP_FUNC_CLIENT_DISCONNECT]; | |
1404 | + return; | |
1405 | + } | |
1406 | + | |
1402 | 1407 | // epoll wait codes |
1403 | 1408 | if (is_epoll_edge_trigger) { |
1404 | 1409 | event.events = EPOLLIN | EPOLLHUP | EPOLLET; |
@@ -1429,6 +1434,7 @@ void tcp_session::up_thread_client_receive(const TCP_PROCESS_TYPE_TAG process_ty | ||
1429 | 1434 | return; |
1430 | 1435 | } |
1431 | 1436 | } |
1437 | + | |
1432 | 1438 | int ret_fds = epoll_wait(up_client_epollfd, up_client_events, EVENT_NUM, epoll_timeout); |
1433 | 1439 | if (ret_fds == 0) { |
1434 | 1440 | //----Debug log---------------------------------------------------------------------- |
@@ -1500,10 +1506,7 @@ void tcp_session::up_thread_client_receive(const TCP_PROCESS_TYPE_TAG process_ty | ||
1500 | 1506 | } |
1501 | 1507 | func_tag = func_type->second; |
1502 | 1508 | } else { |
1503 | - boost::format formatter("Thread ID[%d] client read error. recv_size: %d"); | |
1504 | - formatter % boost::this_thread::get_id() % recv_size; | |
1505 | - Logger::putLogError(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__); | |
1506 | - func_tag = UP_FUNC_CLIENT_RECEIVE; | |
1509 | + func_tag = UP_FUNC_CLIENT_DISCONNECT; | |
1507 | 1510 | } |
1508 | 1511 | } else { |
1509 | 1512 | if (ec == boost::asio::error::eof) { |
@@ -2606,7 +2609,7 @@ void tcp_session::up_thread_exit(const TCP_PROCESS_TYPE_TAG process_type) | ||
2606 | 2609 | upthread_status_cond.notify_one(); |
2607 | 2610 | realserver_connect_cond.notify_one(); |
2608 | 2611 | realserver_connect_status = true; |
2609 | - exit_flag = true; | |
2612 | + __sync_bool_compare_and_swap(&exit_flag, 0, 1); | |
2610 | 2613 | |
2611 | 2614 | if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) { |
2612 | 2615 | boost::format formatter("Thread ID[%d] FUNC OUT func up_thread_client_disconnect"); |
@@ -2780,13 +2783,11 @@ void tcp_session::down_thread_realserver_receive(const TCP_PROCESS_TYPE_TAG proc | ||
2780 | 2783 | std::map<protocol_module_base::EVENT_TAG, DOWN_THREAD_FUNC_TYPE_TAG>::iterator func_type = down_thread_module_event_map.find(module_event); |
2781 | 2784 | func_tag = func_type->second; |
2782 | 2785 | } else { |
2783 | - func_tag = DOWN_FUNC_REALSERVER_RECEIVE; | |
2784 | - //boost::this_thread::yield(); | |
2786 | + func_tag = DOWN_FUNC_REALSERVER_DISCONNECT; | |
2785 | 2787 | } |
2786 | 2788 | } else { |
2787 | 2789 | if (ec == boost::asio::error::try_again) { |
2788 | 2790 | func_tag = DOWN_FUNC_REALSERVER_RECEIVE; |
2789 | - //boost::this_thread::yield(); | |
2790 | 2791 | } else { |
2791 | 2792 | func_tag = DOWN_FUNC_REALSERVER_DISCONNECT; |
2792 | 2793 | } |
@@ -3104,7 +3105,6 @@ void tcp_session::down_thread_client_send(const TCP_PROCESS_TYPE_TAG process_typ | ||
3104 | 3105 | //----Debug log---------------------------------------------------------------------- |
3105 | 3106 | if (data_size > send_data_size) { |
3106 | 3107 | func_tag = DOWN_FUNC_CLIENT_SEND; |
3107 | - //down_send_wait.reset(); | |
3108 | 3108 | } else { |
3109 | 3109 | protocol_module_base::EVENT_TAG module_event = protocol_module->handle_client_send(down_thread_id); |
3110 | 3110 | std::map<protocol_module_base::EVENT_TAG, DOWN_THREAD_FUNC_TYPE_TAG>::iterator func_type = down_thread_module_event_map.find(module_event); |
@@ -3304,7 +3304,7 @@ void tcp_session::down_thread_sorryserver_receive(const TCP_PROCESS_TYPE_TAG pro | ||
3304 | 3304 | std::map<protocol_module_base::EVENT_TAG, DOWN_THREAD_FUNC_TYPE_TAG>::iterator func_type = down_thread_module_event_map.find(module_event); |
3305 | 3305 | func_tag = func_type->second; |
3306 | 3306 | } else { |
3307 | - func_tag = DOWN_FUNC_SORRYSERVER_RECEIVE; | |
3307 | + func_tag = DOWN_FUNC_SORRYSERVER_DISCONNECT; | |
3308 | 3308 | } |
3309 | 3309 | } else { |
3310 | 3310 | if (ec == boost::asio::error::try_again) { |
@@ -3492,7 +3492,7 @@ void tcp_session::down_thread_exit(const TCP_PROCESS_TYPE_TAG process_type) | ||
3492 | 3492 | rw_scoped_lock scoped_lock(exit_flag_update_mutex); |
3493 | 3493 | boost::mutex::scoped_lock status_scoped_lock(downthread_status_mutex); |
3494 | 3494 | downthread_status_cond.notify_one(); |
3495 | - exit_flag = true; | |
3495 | + __sync_bool_compare_and_swap(&exit_flag, 0, 1); | |
3496 | 3496 | |
3497 | 3497 | if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) { |
3498 | 3498 | boost::format formatter("Thread ID[%d] FUNC OUT down_thread_exit"); |
@@ -1721,11 +1721,11 @@ void l7vs::virtualservice_tcp::release_session(const tcp_session *session_ptr) | ||
1721 | 1721 | |
1722 | 1722 | session_thread_control *stc_ptr = active_sessions.find(session_ptr); |
1723 | 1723 | if (unlikely(NULL == stc_ptr)) { |
1724 | + boost::format fmt("session release fail: " | |
1725 | + "active_sessions.find( const tcp_session* session_ptr = %d )"); | |
1726 | + fmt % session_ptr; | |
1727 | + Logger::putLogError(LOG_CAT_L7VSD_VIRTUALSERVICE, /*XXX*/999, fmt.str(), __FILE__, __LINE__); | |
1724 | 1728 | if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_VIRTUALSERVICE))) { |
1725 | - boost::format fmt("session release fail: " | |
1726 | - "active_sessions.find( const tcp_session* session_ptr = %d )"); | |
1727 | - fmt % session_ptr; | |
1728 | - Logger::putLogDebug(LOG_CAT_L7VSD_VIRTUALSERVICE, 87, fmt.str(), __FILE__, __LINE__); | |
1729 | 1729 | Logger::putLogDebug(LOG_CAT_L7VSD_VIRTUALSERVICE, 88, "out_function: " |
1730 | 1730 | "void virtualservice_tcp::release_session( " |
1731 | 1731 | "const boost::thread::id thread_id )", __FILE__, __LINE__); |