• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

UltraMonkey-L7 V3(multi-thread implementation)


コミットメタ情報

リビジョンa7ed71adab167d1ac77d3b2bebfe45bcf316c3d7 (tree)
日時2011-12-28 15:28:55
作者takeda kenji <takeda@n026...>
コミッターtakeda kenji

ログメッセージ

・データ構造を変更
パターンとendpointのペアをpairで管理していたところをmapに変更。
それにともない、array-sregexの変換mapをlist< pair< array, sregex > >に変更。

・handle_realserver_slectの処理を一部変更
接続先のReal Serverが落ちていた場合に、Sorryフラグをオンにするように変更。

変更サマリ

差分

--- a/l7vsd/module/protocol/protocol_module_url.cpp
+++ b/l7vsd/module/protocol/protocol_module_url.cpp
@@ -34,11 +34,9 @@
3434 #include "protocol_module_url.h"
3535 #include "utility.h"
3636
37-
3837 #include <boost/lambda/lambda.hpp>
3938 #include <boost/lambda/if.hpp>
4039
41-
4240 namespace l7vs
4341 {
4442 #ifdef DEBUG
@@ -412,9 +410,11 @@ protocol_module_base::check_message_result protocol_module_url::check_parameter(
412410 try {
413411 vec_str_it it = args.begin();
414412 vec_str_it it_end = args.end();
415- pattern_endpoint_pairlist ptn_ep_pairlist_for_check;
416- pattern_endpoint_pairlist_it ptn_ep_pairlist_it;
417- pattern_endpoint_pairlist_it ptn_ep_pairlist_it_end;
413+
414+ pattern_endpointlist_map ptn_eplist_map_for_check;
415+ pattern_endpointlist_map_it ptn_eplist_map_it;
416+ pattern_endpointlist_map_it ptn_eplist_map_it_end;
417+
418418 boost::lambda::placeholder1_type X;
419419
420420 //loop option strings
@@ -562,11 +562,10 @@ protocol_module_base::check_message_result protocol_module_url::check_parameter(
562562 boost::array<char,MAX_OPTION_SIZE> ary_buf;
563563 strcpy( ary_buf.begin(), it->c_str() );
564564
565- ptn_ep_pairlist_it_end = ptn_ep_pairlist_for_check.end();
566- ptn_ep_pairlist_it = std::find_if( ptn_ep_pairlist_for_check.begin(), ptn_ep_pairlist_it_end,
567- ( &X->*( &pattern_endpoint_pair::first ) == ary_buf ) );
568-
569- if( ptn_ep_pairlist_it != ptn_ep_pairlist_it_end ){
565+ ptn_eplist_map_it_end = ptn_eplist_map_for_check.end();
566+ ptn_eplist_map_it = ptn_eplist_map_for_check.find( ary_buf );
567+
568+ if( ptn_eplist_map_it != ptn_eplist_map_it_end ){
570569 check_result.flag = false;
571570 std::ostringstream ostr;
572571 ostr << "Pattern '" << *it << "' is already set.";
@@ -583,7 +582,7 @@ protocol_module_base::check_message_result protocol_module_url::check_parameter(
583582 }else{
584583 check_result.flag = false;
585584 std::ostringstream ostr;
586- ostr << "You have to set option '-RS/--end-point' after '-P/--pattern-match'.(デバッグ用01)";
585+ ostr << "You have to set option '-RS/--end-point' after '-P/--pattern-match'.";
587586 check_result.message = ostr.str();
588587 putLogError(9999, check_result.message, __FILE__, __LINE__);
589588 break;
@@ -596,17 +595,17 @@ protocol_module_base::check_message_result protocol_module_url::check_parameter(
596595 } else {
597596 check_result.flag = false;
598597 std::ostringstream ostr;
599- ostr << "You have to set option '-RS/--end-point' after '-P/--pattern-match'.(デバッグ用02)";
598+ ostr << "You have to set option '-RS/--end-point' after '-P/--pattern-match'.";
600599 check_result.message = ostr.str();
601600 putLogError(9999, check_result.message, __FILE__, __LINE__);
602601 break;
603602 }
604603
605- ptn_ep_pairlist_for_check.push_back(
606- std::pair<
604+ ptn_eplist_map_for_check.insert(
605+ std::map<
607606 boost::array< char, MAX_OPTION_SIZE >,
608607 std::list< tcp_type::endpoint >
609- >( ary_buf, temp_endpoint_list )
608+ >::value_type( ary_buf, temp_endpoint_list )
610609 );
611610
612611 }
@@ -766,9 +765,9 @@ protocol_module_base::check_message_result protocol_module_url::set_parameter(co
766765 try {
767766 vec_str_it it = args.begin();
768767 vec_str_it it_end = args.end();
769- pattern_endpoint_pairlist_it ptn_ep_pairlist_it;
770- pattern_endpoint_pairlist_it ptn_ep_pairlist_it_end;
771- boost::lambda::placeholder1_type X;
768+
769+ pattern_endpointlist_map_it ptn_eplist_map_it;
770+ pattern_endpointlist_map_it ptn_eplist_map_it_end;
772771
773772 //loop option strings
774773 while( it != it_end ){
@@ -920,16 +919,15 @@ protocol_module_base::check_message_result protocol_module_url::set_parameter(co
920919 boost::array<char,MAX_OPTION_SIZE> ary_buf;
921920 strcpy( ary_buf.begin(), it->c_str() );
922921
923- ptn_ep_pairlist_it_end = ptn_ep_pairlist.end();
924- ptn_ep_pairlist_it = std::find_if( ptn_ep_pairlist.begin(), ptn_ep_pairlist_it_end,
925- ( &X->*( &pattern_endpoint_pair::first ) == ary_buf ) );
926-
927- if( ptn_ep_pairlist_it != ptn_ep_pairlist_it_end ){
922+ ptn_eplist_map_it = ptn_eplist_map.find( ary_buf );
923+ ptn_eplist_map_it_end = ptn_eplist_map.end();
924+
925+ if( ptn_eplist_map_it != ptn_eplist_map_it_end ){
928926 check_result.flag = false;
929927 std::ostringstream ostr;
930928 ostr << "Pattern '" << *it << "' is already set.";
931929 check_result.message = ostr.str();
932- putLogError(9999, check_result.message, __FILE__, __LINE__);
930+ putLogError( 9999, check_result.message, __FILE__, __LINE__);
933931 break;
934932 }
935933
@@ -941,7 +939,7 @@ protocol_module_base::check_message_result protocol_module_url::set_parameter(co
941939 }else{
942940 check_result.flag = false;
943941 std::ostringstream ostr;
944- ostr << "You have to set option '-RS/--end-point' after '-P/--pattern-match'.(デバッグ用01)";
942+ ostr << "You have to set option '-RS/--end-point' after '-P/--pattern-match'.";
945943 check_result.message = ostr.str();
946944 putLogError(9999, check_result.message, __FILE__, __LINE__);
947945 break;
@@ -954,25 +952,25 @@ protocol_module_base::check_message_result protocol_module_url::set_parameter(co
954952 } else {
955953 check_result.flag = false;
956954 std::ostringstream ostr;
957- ostr << "You have to set option '-RS/--end-point' after '-P/--pattern-match'.(デバッグ用02)";
955+ ostr << "You have to set option '-RS/--end-point' after '-P/--pattern-match'.";
958956 check_result.message = ostr.str();
959957 putLogError(9999, check_result.message, __FILE__, __LINE__);
960958 break;
961959 }
962960
963- ptn_ep_pairlist.push_back(
964- std::pair<
961+ ptn_eplist_map.insert(
962+ std::map<
965963 boost::array< char, MAX_OPTION_SIZE >,
966964 std::list< tcp_type::endpoint >
967- >( ary_buf, temp_endpoint_list )
965+ >::value_type( ary_buf, temp_endpoint_list )
966+ );
967+
968+ ptnsrgx_converter_pairlist.push_back(
969+ std::pair<
970+ boost::array< char, MAX_OPTION_SIZE >,
971+ sregex
972+ >( ary_buf, sregex::compile( ary_buf.data() ) )
968973 );
969-
970- keyary_sregex_converter_map.insert(
971- std::map<
972- boost::array< char, MAX_OPTION_SIZE >,
973- sregex
974- >::value_type( ary_buf, sregex::compile( ary_buf.data() ) )
975- );
976974
977975 }
978976 //next item not exist
@@ -1050,7 +1048,7 @@ protocol_module_base::check_message_result protocol_module_url::set_parameter(co
10501048 formatter % check_result.flag % check_result.message;
10511049 putLogDebug(100016, formatter.str(), __FILE__, __LINE__);
10521050 }
1053-
1051+
10541052 return check_result;
10551053
10561054 }
@@ -2552,12 +2550,11 @@ protocol_module_base::EVENT_TAG protocol_module_url::handle_realserver_select(
25522550 }
25532551
25542552 //endpoint check
2555- receive_data_it = session_data->receive_data_map.find(session_data->client_endpoint_tcp);
2553+ receive_data_it = session_data->receive_data_map.find( session_data->client_endpoint_tcp );
25562554 if (unlikely(receive_data_it == session_data->receive_data_map.end())) {
25572555 boost::format formatter("Invalid endpoint. thread id : %d.");
25582556 formatter % boost::this_thread::get_id();
25592557 putLogError(100043, formatter.str(), __FILE__, __LINE__);
2560- session_thread_data_map_mutex.unlock();
25612558 throw - 1;
25622559 }
25632560
@@ -2567,7 +2564,7 @@ protocol_module_base::EVENT_TAG protocol_module_url::handle_realserver_select(
25672564 send_status_it it_end = recv_data.send_status_list.end();
25682565
25692566 //status list check
2570- it = std::find_if(it, it_end, data_send_ok());
2567+ it = std::find_if( it, it_end, data_send_ok() );
25712568 if (unlikely(it == it_end)) {
25722569 boost::format formatter("Sending possible data is not existed. thread id : %d.");
25732570 formatter % boost::this_thread::get_id();
@@ -2576,40 +2573,47 @@ protocol_module_base::EVENT_TAG protocol_module_url::handle_realserver_select(
25762573 }
25772574
25782575 // endpoint decide
2579- ret = find_uri(recv_data.receive_buffer + it->send_offset, it->send_possible_size, url_offset, url_offset_len);
2576+ ret = find_uri( recv_data.receive_buffer + it->send_offset, it->send_possible_size, url_offset, url_offset_len );
25802577 if( ret ){
25812578 std::string tempstr = recv_data.receive_buffer;
2582- pattern_endpoint_pairlist_it ptn_ep_pairlist_it = ptn_ep_pairlist.begin();
2583- pattern_endpoint_pairlist_it ptn_ep_pairlist_it_end = ptn_ep_pairlist.end();
2579+
2580+ pattern_sregex_converter_pairlist_it ptnsrgx_cvt_pairlist_it = ptnsrgx_converter_pairlist.begin();
2581+ pattern_sregex_converter_pairlist_it ptnsrgx_cvt_pairlist_it_end = ptnsrgx_converter_pairlist.end();
25842582
25852583 sregex reg;
2586- // indicate Real Server found or not found.
2587- bool is_match = false;
2584+ // indicate client sends URL is matched
2585+ bool is_regex_match = false;
2586+ // indicate Real Server found
2587+ bool is_realserver_match = false;
25882588
25892589 // search URL pattern
2590- while( ptn_ep_pairlist_it != ptn_ep_pairlist_it_end ){
2590+ while( ptnsrgx_cvt_pairlist_it != ptnsrgx_cvt_pairlist_it_end ){
25912591
2592- reg = keyary_sregex_converter_map[ ptn_ep_pairlist_it->first ];
2592+ reg = ptnsrgx_cvt_pairlist_it->second;
2593+ is_regex_match = regex_match( tempstr.substr( url_offset, url_offset_len ), reg );
25932594
2594- if( regex_match( tempstr.substr( url_offset, url_offset_len ), reg ) ){
2595+ if( is_regex_match ){
2596+ std::list< boost::asio::ip::tcp::endpoint >::iterator ep_list_it
2597+ = ( ptn_eplist_map.find( ptnsrgx_cvt_pairlist_it->first ) )->second.begin();
2598+ std::list< boost::asio::ip::tcp::endpoint >::iterator ep_list_it_end
2599+ = ( ptn_eplist_map.find( ptnsrgx_cvt_pairlist_it->first ) )->second.end();
25952600 // find the rs_endpoint in the rs_list
25962601 {
25972602 rs_list_scoped_lock scoped_lock(rs_list_lock, rs_list_unlock);
2598- std::list< boost::asio::ip::tcp::endpoint >::iterator ep_list_it = ptn_ep_pairlist_it->second.begin();
2599-
2600- while( ep_list_it != ptn_ep_pairlist_it->second.end() ){
26012603
2602- // check endpoint ( set by '-RS/--end-point' option and already set at Virtual Service )
2604+ // while( ep_list_it != ptn_ep_pairlist_it->second.end() ){
2605+ while( ep_list_it != ep_list_it_end ){
2606+ // check endpoint ( set by '-RS/--end-point' option and exist Real Server )
26032607 for( rs_list_itr = rs_list_begin(); rs_list_itr != rs_list_end(); rs_list_itr = rs_list_next( rs_list_itr ) ){
26042608 if ( *ep_list_it == rs_list_itr->tcp_endpoint && rs_list_itr->weight != 0 ) {
26052609 rslist_it_list.push_back( rs_list_itr );
2606- is_match = true;
2610+ is_realserver_match = true;
26072611 break;
26082612 }
26092613 }
26102614 ++ep_list_it;
26112615 }
2612- if( is_match ){
2616+ if( is_realserver_match ){
26132617 // "rs_list_end()" is rslist_it_list's sentinel
26142618 rslist_it_list.push_back( rs_list_end() );
26152619 // call Schedule Module in this function.
@@ -2618,44 +2622,62 @@ protocol_module_base::EVENT_TAG protocol_module_url::handle_realserver_select(
26182622 }
26192623 rslist_it_list.clear();
26202624 }
2621- if( is_match ){
2625+
2626+ if( is_realserver_match ){
26222627 break;
26232628 }
26242629
2625- ++ptn_ep_pairlist_it;
2630+ ++ptnsrgx_cvt_pairlist_it;
26262631 }
26272632
2628- if( is_match && rs_endpoint != tmp_endpoint ){
2629- // get the endpoint successfullyi
2630- session_data->target_endpoint = rs_endpoint;
2631- status = REALSERVER_CONNECT;
2633+ if( is_regex_match ){
2634+ if( is_realserver_match && rs_endpoint != tmp_endpoint ){
2635+ // get the endpoint successfullyi
2636+ session_data->target_endpoint = rs_endpoint;
2637+ status = REALSERVER_CONNECT;
2638+ }else{
2639+ // no endpoint found
2640+ // set sorry flag on
2641+ session_data->sorry_flag = SORRY_FLAG_ON;
2642+ /*-------- DEBUG LOG --------*/
2643+ if (unlikely(LOG_LV_DEBUG == getloglevel())) {
2644+ boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_url::"
2645+ "handle_realserver_select() : SORRY_FLAG_ON. thread id : %d.");
2646+ formatter % boost::this_thread::get_id();
2647+ putLogDebug(100076, formatter.str(), __FILE__, __LINE__);
2648+ }
2649+ /*------DEBUG LOG END------*/
2650+ status = SORRYSERVER_SELECT;
2651+ }
26322652 }else{
2633- // No endpoint matched keyword.
2634- //set end flag on
2635- session_data->sorry_flag = SORRY_FLAG_ON;
2636- /*-------- DEBUG LOG --------*/
2637- if (unlikely(LOG_LV_DEBUG == getloglevel())) {
2638- boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_url::"
2639- "handle_realserver_select() : SORRY_FLAG_ON. thread id : %d.");
2640- formatter % boost::this_thread::get_id();
2641- putLogDebug(100076, formatter.str(), __FILE__, __LINE__);
2642- }
2643- /*------DEBUG LOG END------*/
2644- status = SORRYSERVER_SELECT;
2653+ // client sends URL is no matched
2654+ // set end flag on
2655+ session_data->end_flag = END_FLAG_ON;
2656+ /*-------- DEBUG LOG --------*/
2657+ if (unlikely(LOG_LV_DEBUG == getloglevel())) {
2658+ boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_url::"
2659+ "handle_realserver_select() : END_FLAG_ON. thread id : %d.");
2660+ formatter % boost::this_thread::get_id();
2661+ putLogDebug(100229, formatter.str(), __FILE__, __LINE__);
2662+ }
2663+ /*------DEBUG LOG END------*/
2664+ status = FINALIZE;
26452665 }
2666+
26462667 }
2647- // URL Not found.
2668+ // URL Not found
26482669 else{
2649- session_data->sorry_flag = SORRY_FLAG_ON;
2650- /*-------- DEBUG LOG --------*/
2651- if (unlikely(LOG_LV_DEBUG == getloglevel())) {
2652- boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_url::"
2653- "handle_realserver_select() : SORRY_FLAG_ON. thread id : %d.");
2654- formatter % boost::this_thread::get_id();
2655- putLogDebug(100076, formatter.str(), __FILE__, __LINE__);
2656- }
2657- /*------DEBUG LOG END------*/
2658- status = SORRYSERVER_SELECT;
2670+ // set end flag on
2671+ session_data->end_flag = END_FLAG_ON;
2672+ /*-------- DEBUG LOG --------*/
2673+ if (unlikely(LOG_LV_DEBUG == getloglevel())) {
2674+ boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_url::"
2675+ "handle_realserver_select() : END_FLAG_ON. thread id : %d.");
2676+ formatter % boost::this_thread::get_id();
2677+ putLogDebug(100229, formatter.str(), __FILE__, __LINE__);
2678+ }
2679+ /*------DEBUG LOG END------*/
2680+ status = FINALIZE;
26592681 }
26602682
26612683 } catch (int e) {
@@ -7819,7 +7841,7 @@ std::list< realserver >::iterator protocol_module_url::next_rslist_it( std::list
78197841 return *rslist_it_list_it;
78207842 }
78217843
7822-//! @takeda:schedule_tcpを無理やり使うための関数.この方法はひどいと思うが他の方法がわからない...
7844+//! @takeda:schedule_tcpを無理やり使うための関数...
78237845 //! @param[in] thread_id
78247846 //! @param[in] in_rslist_it_list : registered Real Servers ( This parameter is substantially 'const' in this function. )
78257847 //! @param[out] rs_endpoint[out] : addressee Real Server
@@ -7847,8 +7869,8 @@ void protocol_module_url::useScheduleTCP(
78477869 void protocol_module_url::dumpKeyary_endpointlist( int num )
78487870 {
78497871
7850- pattern_endpoint_pairlist_it it = ptn_ep_pairlist.begin();
7851- pattern_endpoint_pairlist_it it_end = ptn_ep_pairlist.end();
7872+ pattern_endpointlist_map_it it = ptn_eplist_map.begin();
7873+ pattern_endpointlist_map_it it_end = ptn_eplist_map.end();
78527874
78537875 typedef std::list<boost::asio::ip::tcp::endpoint> eplist;
78547876
@@ -7921,22 +7943,22 @@ void protocol_module_url::dumpOptionString( const std::vector<std::string>& args
79217943
79227944 }
79237945
7924-void protocol_module_url::dumpKeyary_sregex_converter_map( void )
7946+void protocol_module_url::dumpPtnsrgx_converter_pairlist( void )
79257947 {
7926- putLogFatal(9999, "-------dumpKeyary_sregex_converter_map---------", __FILE__, __LINE__);
7927-
7928- std::string str;
7929-
7930- std::map< boost::array<char,MAX_OPTION_SIZE>, boost::xpressive::sregex >::iterator it = keyary_sregex_converter_map.begin();
7931- std::map< boost::array<char,MAX_OPTION_SIZE>, boost::xpressive::sregex >::iterator end = keyary_sregex_converter_map.end();
7932-
7933- while( it != end ){
7934- str = it->first.data();
7935- putLogFatal( 29290, "[ " + str + " ]", __FILE__, __LINE__ );
7936- ++it;
7937- }
7938-
7939- putLogFatal(9999, "----------------------------------------------", __FILE__, __LINE__);
7948+// putLogFatal(9999, "-------dumpPtnsrgx_converter_pairlist---------", __FILE__, __LINE__);
7949+//
7950+// std::string str;
7951+//
7952+// std::map< boost::array<char,MAX_OPTION_SIZE>, boost::xpressive::sregex >::iterator it = keyary_sregex_converter_map.begin();
7953+// std::map< boost::array<char,MAX_OPTION_SIZE>, boost::xpressive::sregex >::iterator end = keyary_sregex_converter_map.end();
7954+//
7955+// while( it != end ){
7956+// str = it->first.data();
7957+// putLogFatal( 29290, "[ " + str + " ]", __FILE__, __LINE__ );
7958+// ++it;
7959+// }
7960+//
7961+// putLogFatal(9999, "----------------------------------------------", __FILE__, __LINE__);
79407962 }
79417963
79427964 void protocol_module_url::testVolume( void )
--- a/l7vsd/module/protocol/protocol_module_url.h
+++ b/l7vsd/module/protocol/protocol_module_url.h
@@ -128,12 +128,14 @@ protected:
128128 std::map<boost::thread::id, thread_data_ptr> session_thread_data_map;
129129 boost::mutex session_thread_data_map_mutex;
130130
131- typedef std::pair< boost::array<char,MAX_OPTION_SIZE>, std::list<boost::asio::ip::tcp::endpoint> > pattern_endpoint_pair;
132- typedef std::list< pattern_endpoint_pair > pattern_endpoint_pairlist;
133- typedef std::list< pattern_endpoint_pair >::iterator pattern_endpoint_pairlist_it;
134-
135- pattern_endpoint_pairlist ptn_ep_pairlist;
136- std::map< boost::array<char,MAX_OPTION_SIZE>, boost::xpressive::sregex > keyary_sregex_converter_map;
131+ typedef std::map< boost::array< char, MAX_OPTION_SIZE >, std::list< boost::asio::ip::tcp::endpoint > > pattern_endpointlist_map;
132+ typedef std::map< boost::array< char, MAX_OPTION_SIZE >, std::list< boost::asio::ip::tcp::endpoint > >::iterator pattern_endpointlist_map_it;
133+ pattern_endpointlist_map ptn_eplist_map;
134+ // for keep order '-P/--pattern-match' option value set & convert pattern to sregex
135+ typedef std::pair< boost::array< char, MAX_OPTION_SIZE >, boost::xpressive::sregex > pattern_sregex_converter_pair;
136+ typedef std::list< pattern_sregex_converter_pair > pattern_sregex_converter_pairlist;
137+ typedef std::list< pattern_sregex_converter_pair >::iterator pattern_sregex_converter_pairlist_it;
138+ pattern_sregex_converter_pairlist ptnsrgx_converter_pairlist;
137139
138140 private:
139141 template < class T >typename T::endpoint stringtoEndpoint( const std::string &str, error_code &err );
@@ -158,7 +160,7 @@ private:
158160 void dumpKeyary_endpointlist( int num );
159161 void dumpRslist_it_list( void );
160162 void dumpOptionString( const std::vector<std::string>& args );
161- void dumpKeyary_sregex_converter_map( void );
163+ void dumpPtnsrgx_converter_pairlist( void );
162164 void testVolume( void );
163165 public:
164166 static const std::string MODULE_NAME;