2 * @file protocol_module_sessionless.cpp
3 * @brief protocol module of any protocol.
4 * @brief this module never keep session persistence.
6 * L7VSD: Linux Virtual Server for Layer7 Load Balancing
7 * Copyright (C) 2009 NTT COMWARE Corporation.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 **********************************************************************/
25 #include <boost/xpressive/xpressive.hpp>
30 #include <boost/asio/ip/tcp.hpp>
31 #include <boost/format.hpp>
32 #include "protocol_module_sessionless.h"
38 const std::string protocol_module_sessionless::MODULE_NAME = "sessionless";
39 const int protocol_module_sessionless::THREAD_DIVISION_UP_STREAM = 0;
40 const int protocol_module_sessionless::THREAD_DIVISION_DOWN_STREAM = 1;
42 const int protocol_module_sessionless::END_FLAG_OFF = 0;
43 const int protocol_module_sessionless::END_FLAG_ON = 1;
45 const int protocol_module_sessionless::ACCEPT_END_FLAG_OFF = 0;
46 const int protocol_module_sessionless::ACCEPT_END_FLAG_ON = 1;
48 const int protocol_module_sessionless::SORRY_FLAG_ON = 1;
49 const int protocol_module_sessionless::SORRY_FLAG_OFF = 0;
51 const int protocol_module_sessionless::SORRYSERVER_SWITCH_FLAG_OFF = 0;
52 const int protocol_module_sessionless::SORRYSERVER_SWITCH_FLAG_ON = 1;
54 const int protocol_module_sessionless::REALSERVER_SWITCH_FLAG_OFF = 0;
55 const int protocol_module_sessionless::REALSERVER_SWITCH_FLAG_ON = 1;
57 const int protocol_module_sessionless::EDIT_DIVISION_NO_EDIT = 0;
58 const int protocol_module_sessionless::EDIT_DIVISION_EDIT = 1;
60 const int protocol_module_sessionless::FORWARDED_FOR_OFF = 0;
61 const int protocol_module_sessionless::FORWARDED_FOR_ON = 1;
63 protocol_module_sessionless::protocol_module_sessionless() :
64 http_protocol_module_base(MODULE_NAME), forwarded_for(FORWARDED_FOR_OFF)
66 sorry_uri.assign('\0');
70 protocol_module_sessionless::~protocol_module_sessionless()
73 //! tcp protocol support check
74 //! @return tcp support is true
75 //! @return tcp not-support is false
76 bool protocol_module_sessionless::is_tcp()
78 /*-------- DEBUG LOG --------*/
79 if (unlikely(LOG_LV_DEBUG == getloglevel()))
81 putLogDebug(100000, "in/out_function : bool protocol_module_sessionless::is_tcp() : "
82 "return_value = true.", __FILE__, __LINE__ );
84 /*------DEBUG LOG END------*/
88 //! udp protocol support check
89 //! @return udp support is true
90 //! @return udp not-support is false
91 bool protocol_module_sessionless::is_udp()
93 /*-------- DEBUG LOG --------*/
94 if (unlikely(LOG_LV_DEBUG == getloglevel()))
96 putLogDebug(100001, "in/out_function : bool protocol_module_sessionless::is_udp() : "
97 "return_value = false.", __FILE__, __LINE__ );
99 /*------DEBUG LOG END------*/
103 //! replication interval interrrupt
104 //! timer thread call this function. from virtualservice.
105 void protocol_module_sessionless::replication_interrupt()
107 /*-------- DEBUG LOG --------*/
108 if (unlikely(LOG_LV_DEBUG == getloglevel()))
110 putLogDebug(100002, "in/out_function : void protocol_module_sessionless::"
111 "replication_interrupt().", __FILE__, __LINE__ );
113 /*------DEBUG LOG END------*/
115 //! initialize function. called from module control. module loaded call
116 //! @param[in] realserver list iterator begin function object type
117 //! @param[in] realserver list iterator end function object type
118 //! @param[in] realserver list iterator next function object type
119 //! @param[in] realserver list mutex lock function object type.
120 //! @param[in] realserver list mutex unlock function object type
121 void protocol_module_sessionless::initialize(rs_list_itr_func_type inlist_begin,
122 rs_list_itr_func_type inlist_end,
123 rs_list_itr_next_func_type inlist_next,
124 boost::function< void( void ) > inlist_lock,
125 boost::function< void( void ) > inlist_unlock)
127 /*-------- DEBUG LOG --------*/
128 if (unlikely(LOG_LV_DEBUG == getloglevel()))
130 putLogDebug(100003, "in_function : void protocol_module_sessionless::initialize("
131 "rs_list_itr_func_type inlist_begin, rs_list_itr_func_type inlist_end, "
132 "rs_list_itr_next_func_type inlist_next, boost::function< void( void ) > "
133 "inlist_lock, boost::function< void( void ) > inlist_unlock).", __FILE__, __LINE__ );
135 /*------DEBUG LOG END------*/
137 //RealServer list begin function
138 rs_list_begin = inlist_begin;
139 //RealServer list end function
140 rs_list_end = inlist_end;
141 //RealServer list next function
142 rs_list_next = inlist_next;
143 //RealServer list lock funtion
144 rs_list_lock = inlist_lock;
145 //RealServer list unlock funtion
146 rs_list_unlock = inlist_unlock;
148 /*-------- DEBUG LOG --------*/
149 if (unlikely(LOG_LV_DEBUG == getloglevel()))
151 putLogDebug(100004, "out_function : void protocol_module_sessionless::initialize("
152 "rs_list_itr_func_type inlist_begin, rs_list_itr_func_type inlist_end, "
153 "rs_list_itr_next_func_type inlist_next, boost::function< void( void ) > "
154 "inlist_lock, boost::function< void( void ) > inlist_unlock).", __FILE__, __LINE__ );
156 /*-------- DEBUG LOG --------*/
159 //! finalize called from module control. module unloaded call.
160 void protocol_module_sessionless::finalize()
162 /*-------- DEBUG LOG --------*/
163 if (unlikely(LOG_LV_DEBUG == getloglevel()))
165 putLogDebug(100005, "in_function : void protocol_module_sessionless::finalize().", __FILE__,
168 /*------DEBUG LOG END------*/
170 //RealServer list functions initializtion
171 //RealServer list begin function
172 rs_list_begin.clear();
173 //RealServer list end function
175 //RealServer list next function
176 rs_list_next.clear();
177 //RealServer list lock function
178 rs_list_lock.clear();
179 //RealServer list unlock function
180 rs_list_unlock.clear();
182 /*-------- DEBUG LOG --------*/
183 if (unlikely(LOG_LV_DEBUG == getloglevel()))
185 putLogDebug(100006, "function : void protocol_module_sessionless::finalize() : "
186 "rs_list_begin.clear(), rs_list_end.clear(), rs_list_next.clear(), rs_list_lock.clear(), rs_list_unlock.clear() end.", __FILE__,
189 /*------DEBUG LOG END------*/
191 //Replication functions initializtion
192 //component memory allcate function
193 replication_pay_memory.clear();
194 //component memory lock function
195 replication_area_lock.clear();
196 //component memory unlock function
197 replication_area_unlock.clear();
199 /*-------- DEBUG LOG --------*/
200 if (unlikely(LOG_LV_DEBUG == getloglevel()))
202 putLogDebug(100007, "function : void protocol_module_sessionless::finalize() : "
203 "replication_pay_memory.clear(), replication_area_lock.clear(), replication_area_unlock.clear() end.", __FILE__,
206 /*------DEBUG LOG END------*/
208 //ScheduleModule's functions initializtion
209 schedule_tcp.clear();
211 /*-------- DEBUG LOG --------*/
212 if (unlikely(LOG_LV_DEBUG == getloglevel()))
214 putLogDebug(100008, "function : void protocol_module_sessionless::finalize() : "
215 "schedule_tcp.clear(), schedule_udp.clear() end.", __FILE__,
218 /*------DEBUG LOG END------*/
220 //Module's option initializtion
222 forwarded_for = FORWARDED_FOR_OFF;
224 sorry_uri.assign('\0');
225 /*-------- DEBUG LOG --------*/
226 if (unlikely(LOG_LV_DEBUG == getloglevel()))
228 putLogDebug(100009, "function : void protocol_module_sessionless::finalize() : "
229 "forwarded_for = 0, sorry_uri.assign('\\0') end.", __FILE__,
232 /*------DEBUG LOG END------*/
233 /*-------- DEBUG LOG --------*/
234 if (unlikely(LOG_LV_DEBUG == getloglevel()))
236 putLogDebug(100010, "out_function : void protocol_module_sessionless::finalize().", __FILE__,
239 /*------DEBUG LOG END------*/
242 //logger functions initializtion
243 //log level getting function
257 //! sorry support check
258 //! @return true sorry mode is supported.
259 //! @return false sorry mode is unsupported.
260 bool protocol_module_sessionless::is_use_sorry()
262 /*-------- DEBUG LOG --------*/
263 if (unlikely(LOG_LV_DEBUG == getloglevel()))
265 putLogDebug(100011, "in/out_function : bool protocol_module_sessionless::is_use_sorry() : "
266 "return_value = true.", __FILE__, __LINE__ );
268 /*------DEBUG LOG END------*/
272 //! realserver list update event
273 void protocol_module_sessionless::handle_rslist_update()
275 /*-------- DEBUG LOG --------*/
276 if (unlikely(LOG_LV_DEBUG == getloglevel()))
278 putLogDebug(100012, "in/out_function : void protocol_module_sessionless::handle_rslist_update().", __FILE__,
281 /*------DEBUG LOG END------*/
284 //! module parameter check.used by l7vsadm
285 //! @param[in] module paramter string list
286 //! @return result.flag true is parameter is noproblem.
287 //! @return result.flag false is paramter is problem.
288 protocol_module_base::check_message_result protocol_module_sessionless::check_parameter(const std::vector<
291 /*-------- DEBUG LOG --------*/
292 if (unlikely(LOG_LV_DEBUG == getloglevel()))
294 boost::format formatter("in_function : protocol_module_base::check_message_result "
295 "protocol_module_sessionless::check_parameter("
296 "const std::vector<std::string>& args) : args = %s.");
297 std::string argsdump;
298 for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
303 formatter % argsdump;
304 putLogDebug(100013, formatter.str(), __FILE__, __LINE__ );
306 /*------DEBUG LOG END------*/
307 using namespace boost::xpressive;
308 //set check result true
309 check_message_result check_result;
310 check_result.flag = true;
311 bool forward_checked = false;
312 bool sorryuri_checked = false;
313 sregex sorry_uri_regex
317 ( set = ';', ':', '@', '&', '=' ) |
318 ( set = '$', '-', '_', '.', '+' ) |
319 ( set = '!', '*', '\'', '\(', ')', ',' ) |
320 '%' >> repeat<2>(xdigit)));
321 typedef std::vector<std::string>::const_iterator vec_str_it;
325 vec_str_it it = args.begin();
326 vec_str_it it_end = args.end();
327 //loop option strings
328 for (; it != it_end; ++it)
330 //option string = "-F"
331 if (*it == "-F" || *it == "--forwarded-for")
333 //set forward flag ON
334 forward_checked = true;
336 //option string = "-S"
337 else if (*it == "-S" || *it == "--sorry-uri")
339 //set sorryURI flag OFF
340 if (!sorryuri_checked)
345 if (!it->empty() && (it->substr(0, 1) == "-" || it->substr(0, 2) == "--"))
347 //set check result flag false
348 check_result.flag = false;
349 //set check result message
350 check_result.message = "You have to set option value '-S/--sorry-uri'.";
351 putLogError(100000, check_result.message, __FILE__, __LINE__ );
355 //next option string's length > 127
356 if (it->size() > MAX_OPTION_SIZE - 1)
358 std::ostringstream ostr;
359 ostr << "'-S/--sorry-uri' option value '" << *it << "' is too long.";
361 //set check result flag false
362 check_result.flag = false;
363 //set check result message
364 check_result.message = ostr.str();
366 putLogError(100001, check_result.message, __FILE__, __LINE__ );
370 //next option string's length <= 127
374 if (regex_match(*it, sorry_uri_regex ))
377 //set sorryURI flag ON
378 sorryuri_checked = true;
383 std::ostringstream ostr;
384 ostr << "'-S/--sorry-uri' option value '" << *it << "' is not a valid URI.";
386 //set check result flag false
387 check_result.flag = false;
388 //set check result message
389 check_result.message = ostr.str();
390 putLogError(100002, check_result.message, __FILE__, __LINE__ );
396 //next item is not exist
399 //set check flag false
400 check_result.flag = false;
401 //set check result message
402 check_result.message = "You have to set option value '-S/--sorry-uri'.";
403 putLogError(100003, check_result.message, __FILE__,
412 //set check result flag false
413 check_result.flag = false;
414 //set check result message
415 check_result.message = "Cannot set multiple option '-S/--sorry-uri'.";
416 putLogError(100004, check_result.message, __FILE__,
422 //other option string
425 //set check result flag false
426 check_result.flag = false;
427 //set check result message
428 check_result.message = "Option error.";
429 putLogError(100005, check_result.message, __FILE__, __LINE__ );
435 catch (const std::exception& ex)
437 check_result.flag = false;
438 std::cerr << "protocol_module_sessionless::check_parameter() : exception : error = " << ex.what() << "." << std::endl;
439 boost::format formatter("function : protocol_module_base::check_message_result "
440 "protocol_module_sessionless::check_parameter() exception : "
442 formatter % ex.what();
443 putLogError(100006, formatter.str(), __FILE__, __LINE__ );
447 check_result.flag = false;
448 std::cerr << "protocol_module_sessionless::check_parameter() : Unknown exception." << std::endl;
449 putLogError(100007, "function : protocol_module_base::check_message_result "
450 "protocol_module_sessionless::check_parameter() : "
451 "Unknown exception.", __FILE__, __LINE__ );
454 /*-------- DEBUG LOG --------*/
455 if (unlikely(LOG_LV_DEBUG == getloglevel()))
457 boost::format formatter("out_function : protocol_module_base::check_message_result "
458 "protocol_module_sessionless::check_parameter("
459 "const std::vector<std::string>& args) : return_value = ("
460 "check_message_result.flag = %d, check_message_result.message = %s).");
461 formatter % check_result.flag % check_result.message;
462 putLogDebug(100014, formatter.str(), __FILE__, __LINE__ );
464 /*------DEBUG LOG END------*/
469 //! @param[in] module paramter string list
470 //! @return result.flag true is parameter is noproblem.
471 //! @return result.flag false is paramter is problem.
472 protocol_module_base::check_message_result protocol_module_sessionless::set_parameter(const std::vector<
475 /*-------- DEBUG LOG --------*/
476 if (unlikely(LOG_LV_DEBUG == getloglevel()))
478 boost::format formatter("in_function : protocol_module_base::check_message_result "
479 "protocol_module_sessionless::set_parameter("
480 "const std::vector<std::string>& args) : args = %s.");
481 std::string argsdump;
482 for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
487 formatter % argsdump;
488 putLogDebug(100015, formatter.str(), __FILE__, __LINE__ );
490 /*------DEBUG LOG END------*/
491 using namespace boost::xpressive;
492 //set check result flag true
493 check_message_result check_result;
494 check_result.flag = true;
495 bool forward_checked = false;
496 bool sorryuri_checked = false;
497 sregex sorry_uri_regex
501 ( set = ';', ':', '@', '&', '=' ) |
502 ( set = '$', '-', '_', '.', '+' ) |
503 ( set = '!', '*', '\'', '\(', ')', ',' ) |
504 '%' >> repeat<2>(xdigit)));
506 typedef std::vector<std::string>::const_iterator vec_str_it;
508 //set forwarded flag true
513 vec_str_it it = args.begin();
514 vec_str_it it_end = args.end();
515 for (; it != it_end; ++it)
517 //option string = "-F"
518 if (*it == "-F" || *it == "--forwarded-for")
520 //set forwarded flag ON
521 forward_checked = true;
523 //option string = "-S"
524 else if (*it == "-S" || *it == "--sorry-uri")
526 //sorryURI flag = OFF
527 if (!sorryuri_checked)
532 if (!it->empty() && (it->substr(0, 1) == "-" || it->substr(0, 2) == "--"))
534 //set check result flag false
535 check_result.flag = false;
536 //set check result message
537 check_result.message = "You have to set option value '-S/--sorry-uri'.";
538 putLogError(100008, check_result.message, __FILE__,
543 //next option string's length > 127
544 if (it->size() > MAX_OPTION_SIZE - 1)
546 std::ostringstream ostr;
547 ostr << "'-S/--sorry-uri' option value '" << *it << "' is too long.";
549 //set check result flag false
550 check_result.flag = false;
551 //set check result message
552 check_result.message = ostr.str();
553 putLogError(100009, check_result.message, __FILE__,
558 //next option string's length <= 127
563 if (regex_match(*it, sorry_uri_regex))
565 sorryuri_checked = true;
566 strcpy(sorry_uri.data(), it->c_str());
571 std::ostringstream ostr;
572 ostr << "'-S/--sorry-uri' option value '" << *it << "' is not a valid URI.";
574 //set check result flag false
575 check_result.flag = false;
576 //set check result message
577 check_result.message = ostr.str();
578 putLogError(100010, check_result.message, __FILE__,
585 //next item not exist
588 //set check result flag false
589 check_result.flag = false;
590 //set check result message
591 check_result.message = "You have to set option value '-S/--sorry-uri'.";
592 putLogError(100011, check_result.message, __FILE__,
601 //set check result flag false
602 check_result.flag = false;
603 //set check result message
604 check_result.message = "Cannot set multiple option '-S/--sorry-uri'.";
605 putLogError(100012, check_result.message, __FILE__,
614 //set check result flag false
615 check_result.flag = false;
616 //set check result message
617 check_result.message = "Option error.";
619 putLogError(100013, check_result.message, __FILE__,
626 if (check_result.flag == true)
629 if (!forward_checked)
636 catch (const std::exception& ex)
638 check_result.flag = false;
639 std::cerr << "protocol_module_sessionless::set_parameter() : exception : error = " << ex.what() << "." << std::endl;
640 boost::format formatter("function : protocol_module_base::check_message_result "
641 "protocol_module_sessionless::set_parameter() : exception : "
643 formatter % ex.what();
644 putLogError(100014, formatter.str(), __FILE__, __LINE__ );
648 check_result.flag = false;
649 std::cerr << "protocol_module_sessionless::set_parameter() : Unknown exception." << std::endl;
650 putLogError(100015, "function : protocol_module_base::check_message_result "
651 "protocol_module_sessionless::set_parameter() : "
652 "Unknown exception.", __FILE__, __LINE__ );
655 /*-------- DEBUG LOG --------*/
656 if (unlikely(LOG_LV_DEBUG == getloglevel()))
658 boost::format formatter("out_function : protocol_module_base::check_message_result "
659 "protocol_module_sessionless::set_parameter("
660 "const std::vector<std::string>& args) : return_value = ("
661 "check_message_result.flag = %d, check_message_result.message = %s).");
662 formatter % check_result.flag % check_result.message;
663 putLogDebug(100016, formatter.str(), __FILE__, __LINE__ );
665 /*-------- DEBUG LOG END--------*/
671 //! @param[in] module paramter string list
672 //! @return result.flag true is parameter is noproblem.
673 //! @return result.flag false is paramter is problem.
674 protocol_module_base::check_message_result protocol_module_sessionless::add_parameter(const std::vector<
677 /*-------- DEBUG LOG --------*/
678 if (unlikely(LOG_LV_DEBUG == getloglevel()))
680 boost::format formatter("in_function : protocol_module_base::check_message_result "
681 "protocol_module_sessionless::add_parameter("
682 "const std::vector<std::string>& args) : args = %s.");
683 std::string argsdump;
684 for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
689 formatter % argsdump;
690 putLogDebug(100017, formatter.str(), __FILE__, __LINE__ );
692 /*------DEBUG LOG END------*/
693 check_message_result check_result;
694 //set check result flag true
695 check_result.flag = true;
697 //param list is not empty
700 //set check result flag false
701 check_result.flag = false;
702 //set check result message
703 check_result.message = "Cannot add option.";
704 putLogError(100016, check_result.message, __FILE__, __LINE__ );
707 /*-------- DEBUG LOG --------*/
708 if (unlikely(LOG_LV_DEBUG == getloglevel()))
710 boost::format formatter("out_function : protocol_module_base::check_message_result "
711 "protocol_module_sessionless::add_parameter("
712 "const std::vector<std::string>& args) : return_value = ("
713 "check_message_result.flag = %d, check_message_result.message = %s).");
714 formatter % check_result.flag % check_result.message;
715 putLogDebug(100018, formatter.str(), __FILE__, __LINE__ );
717 /*-------- DEBUG LOG --------*/
723 //! @param[out] module paramter string
724 void protocol_module_sessionless::get_option_info(std::string& option)
726 /*-------- DEBUG LOG --------*/
727 if (unlikely(LOG_LV_DEBUG == getloglevel()))
729 putLogDebug(100019, "in_function : void protocol_module_sessionless::get_option_info("
730 "std::string& option).", __FILE__, __LINE__);
732 /*------DEBUG LOG END------*/
734 boost::format option_formatter("%s--sorry-uri '%s'");
735 option_formatter % (forwarded_for ? "--forwarded-for " : "") % sorry_uri.c_array();
736 option.assign(option_formatter.str());
738 /*-------- DEBUG LOG --------*/
739 if (unlikely(LOG_LV_DEBUG == getloglevel()))
741 boost::format formatter("out_function : void protocol_module_sessionless::get_option_info("
742 "std::string& option) : option = %s.");
744 putLogDebug(100020, formatter.str(), __FILE__, __LINE__);
746 /*------DEBUG LOG END------*/
749 //! TCP/IP scheduled function registation.
750 //! @param[in] schedule module TCP/IP scheduled function object type
751 void protocol_module_sessionless::register_schedule(tcp_schedule_func_type inschedule)
753 /*-------- DEBUG LOG --------*/
754 if (unlikely(LOG_LV_DEBUG == getloglevel()))
756 putLogDebug(100021, "in_function : void protocol_module_sessionless::register_schedule("
757 "tcp_schedule_func_type inschedule).", __FILE__, __LINE__ );
759 /*------DEBUG LOG END------*/
760 schedule_tcp = inschedule;
761 /*-------- DEBUG LOG --------*/
762 if (unlikely(LOG_LV_DEBUG == getloglevel()))
764 putLogDebug(100022, "out_function : void protocol_module_sessionless::register_schedule("
765 "tcp_schedule_func_type inschedule).", __FILE__, __LINE__ );
767 /*------DEBUG LOG END------*/
770 //! UDP scheduled function registation
771 //! @param[in] schedule module UDP scheduled funtion object type
772 void protocol_module_sessionless::register_schedule(udp_schedule_func_type inschedule)
774 /*-------- DEBUG LOG --------*/
775 if (unlikely(LOG_LV_DEBUG == getloglevel()))
778 "in/out_function : void protocol_module_sessionless::register_schedule(udp_schedule_func_type inschedule).",
779 __FILE__, __LINE__ );
781 /*------DEBUG LOG END------*/
784 //! called from session initialzie use in upstream_thread
785 //! @param[in] upstream thread id.
786 //! @param[in] downstream thread id
787 //! @return session use EVENT mode.
788 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_session_initialize(
789 const boost::thread::id up_thread_id, const boost::thread::id down_thread_id,
790 const boost::asio::ip::tcp::endpoint& client_endpoint_tcp,
791 const boost::asio::ip::udp::endpoint& client_endpoint_udp)
793 /*-------- DEBUG LOG --------*/
794 if (unlikely(LOG_LV_DEBUG == getloglevel()))
796 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
797 "handle_session_initialize(const boost::thread::id up_thread_id, "
798 "const boost::thread::id down_thread_id, const boost::asio::ip::tcp::endpoint& client_endpoint_tcp, "
799 "const boost::asio::ip::udp::endpoint& client_endpoint_udp) : "
800 "up_thread_id = %d, down_thread_id = %d, client_endpoint_tcp = [%s]:%d.");
801 formatter % up_thread_id % down_thread_id % client_endpoint_tcp.address().to_string() % client_endpoint_tcp.port() ;
802 putLogDebug(100024, formatter.str(), __FILE__, __LINE__ );
804 /*------DEBUG LOG END------*/
805 EVENT_TAG status = FINALIZE;
807 //session thread initialization
810 thread_data_ptr p_up(new session_thread_data_sessionless);
811 /*-------- DEBUG LOG --------*/
812 if (unlikely(LOG_LV_DEBUG == getloglevel()))
814 boost::format formatter("new : address = &(%d), size = %lu.");
815 formatter % static_cast<void*>(p_up.get()) % sizeof(session_thread_data_sessionless);
816 putLogDebug(100025, formatter.str(), __FILE__, __LINE__ );
818 /*------DEBUG LOG END------*/
819 p_up->thread_id = up_thread_id;
820 p_up->thread_division = THREAD_DIVISION_UP_STREAM;
821 p_up->pair_thread_id = down_thread_id;
822 p_up->accept_end_flag = ACCEPT_END_FLAG_OFF;
823 p_up->end_flag = END_FLAG_OFF;
824 p_up->sorry_flag = SORRY_FLAG_OFF;
825 p_up->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_OFF;
826 p_up->realserver_switch_flag = REALSERVER_SWITCH_FLAG_OFF;
827 p_up->last_status = INITIALIZE;
828 p_up->client_endpoint_tcp = client_endpoint_tcp;
830 recive_data recv_data;
831 p_up->recive_data_map[client_endpoint_tcp] = recv_data;
833 /*-------- DEBUG LOG --------*/
834 if (unlikely(LOG_LV_DEBUG == getloglevel()))
838 formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
839 "handle_session_initialize() : session_thread_data_sessionless(up_thread_id) : "
840 "thread_id = %d, thread_division = %d, "
841 "pair_thread_id = %d, accept_end_flag = %d, end_flag = %d, "
842 "sorry_flag = %d, sorryserver_switch_flag = %d, realserver_switch_flag = %d, last_status = %d, client_endpoint_tcp = [%s]:%d.");
843 formatter % p_up->thread_id % p_up->thread_division % p_up->pair_thread_id % p_up->accept_end_flag
844 % p_up->end_flag % p_up->sorry_flag % p_up->sorryserver_switch_flag % p_up->realserver_switch_flag
845 % p_up->last_status % client_endpoint_tcp.address().to_string() % client_endpoint_tcp.port();
846 putLogDebug(100026, formatter.str(), __FILE__, __LINE__ );
848 /*------DEBUG LOG END------*/
850 thread_data_ptr p_down(new session_thread_data_sessionless);
851 /*-------- DEBUG LOG --------*/
852 if (unlikely(LOG_LV_DEBUG == getloglevel()))
854 boost::format formatter("new : address = &(%d), size = %lu.");
855 formatter % static_cast<void*>(p_down.get()) % sizeof(session_thread_data_sessionless);
856 putLogDebug(100027, formatter.str(), __FILE__, __LINE__ );
858 /*------DEBUG LOG END------*/
859 p_down->thread_id = down_thread_id;
860 p_down->thread_division = THREAD_DIVISION_DOWN_STREAM;
861 p_down->pair_thread_id = up_thread_id;
862 p_down->accept_end_flag = ACCEPT_END_FLAG_OFF;
863 p_down->end_flag = END_FLAG_OFF;
864 p_down->sorry_flag = SORRY_FLAG_OFF;
865 p_down->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_OFF;
866 p_down->realserver_switch_flag = REALSERVER_SWITCH_FLAG_OFF;
867 p_down->last_status = INITIALIZE;
868 p_down->client_endpoint_tcp = client_endpoint_tcp;
869 /*-------- DEBUG LOG --------*/
870 if (unlikely(LOG_LV_DEBUG == getloglevel()))
873 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
874 "handle_session_initialize() : session_thread_data_sessionless(down_thread_id) : "
875 "thread_id = %d, thread_division = %d, pair_thread_id = %d, accept_end_flag = %d, end_flag = %d, "
876 "sorry_flag = %d, sorryserver_switch_flag = %d, realserver_switch_flag = %d, "
877 "last_status = %d, client_endpoint_tcp = [%s]:%d.");
878 formatter % p_down->thread_id % p_down->thread_division % p_down->pair_thread_id % p_down->accept_end_flag
879 % p_down->end_flag % p_down->sorry_flag % p_down->sorryserver_switch_flag
880 % p_down->realserver_switch_flag % p_down->last_status % client_endpoint_tcp.address().to_string() % client_endpoint_tcp.port();
881 putLogDebug(100028, formatter.str(), __FILE__, __LINE__ );
883 /*------DEBUG LOG END------*/
885 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
887 session_thread_data_map[up_thread_id] = p_up;
888 session_thread_data_map[down_thread_id] = p_down;
892 catch (const std::bad_alloc&)
894 std::cerr << "protocol_module_sessionless::handle_session_initialize() : exception : Could not allocate memory." << std::endl;
895 boost::format formatter("Could not allocate memory. thread id : %d.");
896 formatter % boost::this_thread::get_id();
897 putLogError(100017, formatter.str(), __FILE__, __LINE__ );
900 catch (const std::exception& ex)
902 std::cerr << "protocol_module_sessionless::handle_session_initialize() : exception : error = " << ex.what() << "." << std::endl;
903 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
904 "handle_session_initialize() : exception : error = %s. thread id : %d.");
905 formatter % ex.what() % boost::this_thread::get_id();
906 putLogError(100018, formatter.str(), __FILE__, __LINE__ );
911 std::cerr << "protocol_module_sessionless::handle_session_initialize() : Unknown exception." << std::endl;
912 boost::format formatter("function : protocol_module_base::check_message_result "
913 "protocol_module_sessionless::handle_session_initialize() : "
914 "Unknown exception. thread id : %d.");
915 formatter % boost::this_thread::get_id();
916 putLogError(100019, formatter.str(), __FILE__, __LINE__ );
921 /*-------- DEBUG LOG --------*/
922 if (unlikely(LOG_LV_DEBUG == getloglevel()))
924 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
925 "handle_session_initialize(const boost::thread::id up_thread_id, "
926 "const boost::thread::id down_thread_id, const boost::asio::ip::tcp::endpoint& client_endpoint_tcp, "
927 "const boost::asio::ip::udp::endpoint& client_endpoint_udp) : return_value = %d. thread id : %d.");
928 formatter % status % boost::this_thread::get_id();
929 putLogDebug(100029, formatter.str(), __FILE__, __LINE__ );
931 /*------DEBUG LOG END------*/
935 //! called from session finalize use in upstream thread.
936 //! @param[in] upstream thread id.
937 //! @param[in] downstream thread id
938 //! @return session use EVENT mode.
939 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_session_finalize(
940 const boost::thread::id up_thread_id, const boost::thread::id down_thread_id)
943 /*-------- DEBUG LOG --------*/
944 if (unlikely(LOG_LV_DEBUG == getloglevel()))
946 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
947 "handle_session_finalize(const boost::thread::id up_thread_id, "
948 "const boost::thread::id down_thread_id) : "
949 "up_thread_id = %d, down_thread_id = %d.");
950 formatter % up_thread_id % down_thread_id;
951 putLogDebug(100030, formatter.str(), __FILE__, __LINE__ );
953 /*------DEBUG LOG END------*/
954 EVENT_TAG status = STOP;
955 thread_data_ptr p_up;
956 thread_data_ptr p_down;
957 session_thread_data_map_it session_thread_data_it;
958 recive_data_map_it recive_data_it;
960 //session thread free
963 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
965 session_thread_data_it = session_thread_data_map.find(up_thread_id);
966 if (session_thread_data_it != session_thread_data_map.end())
968 p_up = session_thread_data_it->second;
969 /*-------- DEBUG LOG --------*/
970 if (unlikely(LOG_LV_DEBUG == getloglevel()))
972 boost::format formatter("delete : address = &(%d).");
973 formatter % static_cast<void*>(p_up.get());
974 putLogDebug(100031, formatter.str(), __FILE__, __LINE__ );
976 /*------DEBUG LOG END------*/
977 session_thread_data_map.erase(up_thread_id);
980 session_thread_data_it = session_thread_data_map.find(down_thread_id);
981 if (session_thread_data_it != session_thread_data_map.end())
983 /*-------- DEBUG LOG --------*/
984 if (unlikely(LOG_LV_DEBUG == getloglevel()))
986 boost::format formatter("delete : address = &(%d).");
987 formatter % static_cast<void*>(p_down.get());
988 putLogDebug(100032, formatter.str(), __FILE__,
991 /*------DEBUG LOG END------*/
992 session_thread_data_map.erase(down_thread_id);
997 catch (const std::exception& ex)
999 std::cerr << "protocol_module_sessionless::handle_session_finalize() : exception : error = " << ex.what() << "." << std::endl;
1000 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1001 "handle_session_finalize() : exception : error = %s. thread id : %d.");
1002 formatter % ex.what() % boost::this_thread::get_id();
1003 putLogError(100020, formatter.str(), __FILE__, __LINE__ );
1008 std::cerr << "protocol_module_sessionless::handle_session_finalize() : Unknown exception." << std::endl;
1009 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1010 "handle_session_finalize() : "
1011 "Unknown exception. thread id : %d.");
1012 formatter % boost::this_thread::get_id();
1013 putLogError(100021, formatter.str(), __FILE__, __LINE__ );
1017 /*-------- DEBUG LOG --------*/
1018 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1020 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1021 "handle_session_finalize(const boost::thread::id up_thread_id, "
1022 "const boost::thread::id down_thread_id) : return_value = %d. thread id : %d.");
1023 formatter % status % boost::this_thread::get_id();
1024 putLogDebug(100033, formatter.str(), __FILE__, __LINE__ );
1026 /*------DEBUG LOG END------*/
1030 //! called from after session accept.in client socket use in upstream thread.
1031 //! @param[in] upstream thread id.
1032 //! @return session use EVENT mode.
1033 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_accept(const boost::thread::id thread_id)
1036 /*-------- DEBUG LOG --------*/
1037 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1039 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1040 "handle_accept(const boost::thread::id thread_id) : thread_id = %d.");
1041 formatter % thread_id;
1042 putLogDebug(100034, formatter.str(), __FILE__, __LINE__ );
1044 /*------DEBUG LOG END------*/
1046 EVENT_TAG status = FINALIZE;
1047 thread_data_ptr session_data;
1048 session_thread_data_map_it session_thread_it;
1052 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
1054 session_thread_it = session_thread_data_map.find(thread_id);
1055 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
1057 boost::format formatter("Invalid thread id. thread id : %d.");
1058 formatter % boost::this_thread::get_id();
1059 putLogError(100022, formatter.str(), __FILE__, __LINE__ );
1063 session_data = session_thread_it->second;
1065 //set accept end flag ON
1066 session_data->accept_end_flag = ACCEPT_END_FLAG_ON;
1067 /*-------- DEBUG LOG --------*/
1068 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1070 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1071 "handle_accept(const boost::thread::id thread_id) : ACCEPT_END_FLAG_ON. thread id : %d.");
1072 formatter % boost::this_thread::get_id();
1073 putLogDebug(100035, formatter.str(), __FILE__, __LINE__ );
1075 /*------DEBUG LOG END------*/
1078 if (session_data->sorry_flag == SORRY_FLAG_ON)
1081 status = SORRYSERVER_SELECT;
1087 status = REALSERVER_SELECT;
1092 /*-------- DEBUG LOG --------*/
1093 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1095 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1096 "handle_accept() : catch exception e = %d. thread id : %d.");
1097 formatter % e % boost::this_thread::get_id();
1098 putLogDebug(100036, formatter.str(), __FILE__, __LINE__ );
1101 /*------DEBUG LOG END------*/
1103 catch (const std::exception& ex)
1105 std::cerr << "protocol_module_sessionless::handle_accept() : exception : error = " << ex.what() << "." << std::endl;
1106 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1107 "handle_accept() : exception : error = %s. thread id : %d.");
1108 formatter % ex.what() % boost::this_thread::get_id();
1109 putLogError(100023, formatter.str(), __FILE__, __LINE__ );
1115 std::cerr << "protocol_module_sessionless::handle_accept() : Unknown exception." << std::endl;
1116 boost::format formatter("function : protocol_module_base::EVENT_TAG "
1117 "protocol_module_sessionless::handle_accept() : "
1118 "Unknown exception. thread id : %d.");
1119 formatter % boost::this_thread::get_id();
1120 putLogError(100024, formatter.str(), __FILE__, __LINE__ );
1124 /*-------- DEBUG LOG --------*/
1125 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1127 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1128 "handle_accept(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
1129 formatter % status % boost::this_thread::get_id();
1130 putLogDebug(100037, formatter.str(), __FILE__, __LINE__ );
1132 /*------DEBUG LOG END------*/
1136 //! called from after session recv in client socket. use in upstream thread.
1137 //! @param[in] upstream thread id
1138 //! @param[in] recive buffer refarence.
1139 //! @param[in] recive length
1140 //! @return session use EVENT mode.
1141 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_recv(const boost::thread::id thread_id,
1142 const boost::array<char, MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
1144 /*-------- DEBUG LOG --------*/
1145 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1147 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
1149 dump_memory(recvbuffer.data(), buffer_size, buffer);
1150 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1151 "handle_client_recv(const boost::thread::id thread_id, "
1152 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1153 "const size_t recvlen) : thread_id = %d, recvbuffer = %s, recvlen = %d.");
1154 formatter % thread_id % buffer % recvlen;
1155 putLogDebug(100038, formatter.str(), __FILE__, __LINE__ );
1157 /*------DEBUG LOG END------*/
1159 EVENT_TAG status = FINALIZE;
1160 size_t data_remain_start = 0;
1161 size_t data_remain_size = 0;
1162 size_t request_data_remain_size = 0;
1163 size_t header_offset = 0;
1164 size_t header_offset_len = 0;
1165 size_t content_length_header_offset = 0;
1166 size_t content_length_header_len = 0;
1167 size_t content_len_value = 0;
1169 size_t buffer_size = 0;
1170 const size_t cr_lf_len = strlen("\r\n\r\n");
1171 std::string str_value;
1172 const std::string http_header = "";
1173 const std::string content_header = "Content-Length";
1174 thread_data_ptr session_data;
1175 char* buffer1 = NULL;
1176 char* buffer2 = NULL;
1178 CHECK_RESULT_TAG check_result;
1179 session_thread_data_map_it session_thread_it;
1180 recive_data_map_it recive_data_it;
1183 if (recvlen > recvbuffer.size())
1185 std::cerr << "protocol_module_sessionless::handle_client_recv() : Data size bigger than buffer size." << std::endl;
1186 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
1187 formatter % boost::this_thread::get_id();
1188 putLogError(100025, formatter.str(), __FILE__, __LINE__ );
1189 /*-------- DEBUG LOG --------*/
1190 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1192 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1193 "handle_client_recv(const boost::thread::id thread_id, "
1194 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1195 "const size_t recvlen) : return_value = %d. thread id : %d.");
1196 formatter % FINALIZE % boost::this_thread::get_id();
1197 putLogDebug(100039, formatter.str(), __FILE__, __LINE__ );
1199 /*------DEBUG LOG END------*/
1206 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
1208 session_thread_it = session_thread_data_map.find(thread_id);
1209 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
1211 boost::format formatter("Invalid thread id. thread id : %d.");
1212 formatter % boost::this_thread::get_id();
1213 putLogError(100026, formatter.str(), __FILE__, __LINE__ );
1217 session_data = session_thread_it->second;
1221 if (session_data->end_flag == END_FLAG_ON)
1223 status = CLIENT_RECV;
1228 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
1229 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
1231 boost::format formatter("Invalid endpoint. thread id : %d.");
1232 formatter % boost::this_thread::get_id();
1233 putLogError(100027, formatter.str(), __FILE__, __LINE__ );
1237 recive_data& recv_data = recive_data_it->second;
1239 send_status_it it = recv_data.send_status_list.begin();
1240 send_status_it it_end = recv_data.send_status_list.end();
1243 it = std::find_if(it, it_end, data_send_ok());
1244 if (unlikely(it != it_end))
1246 boost::format formatter("Sending data is not correct. thread id : %d.");
1247 formatter % boost::this_thread::get_id();
1248 putLogError(100028, formatter.str(), __FILE__, __LINE__ );
1253 it = recv_data.send_status_list.begin();
1254 it = std::adjacent_find(it, it_end, data_send_repeated());
1255 if (unlikely(it != it_end))
1257 boost::format formatter("Sending data is not correct. thread id : %d.");
1258 formatter % boost::this_thread::get_id();
1259 putLogError(100029, formatter.str(), __FILE__, __LINE__ );
1263 /*-------- DEBUG LOG --------*/
1264 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1266 std::string datadump;
1267 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
1268 "send_rest_size = %d, send_possible_size = %d, "
1269 "send_offset = %d, unsend_size = %d, edit_division = %d.");
1271 for (it = recv_data.send_status_list.begin();
1272 it != recv_data.send_status_list.end();
1275 formatter % i % it->status % it->send_end_size
1276 % it->send_rest_size % it->send_possible_size
1277 % it->send_offset % it->unsend_size % it->edit_division;
1278 datadump += formatter.str();
1281 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1282 "handle_client_recv() : send status list dump : send status list size = %d.%s");
1284 formatter % recv_data.send_status_list.size() % datadump;
1285 putLogDebug(100040, formatter.str(), __FILE__, __LINE__ );
1287 /*------DEBUG LOG END------*/
1289 it = recv_data.send_status_list.begin();
1290 //get original status info
1291 while (it != it_end)
1293 //item status is SEND_END
1294 if (it->status == SEND_END)
1297 recv_data.send_status_list.erase(it++);
1300 //item status is SEND_CONTINUE
1301 else if (it->status == SEND_CONTINUE)
1303 it->send_offset += it->send_end_size;
1304 data_remain_start = it->send_offset;
1307 //item status is SEND_NG
1310 data_remain_start = it->send_offset;
1311 data_remain_size = it->unsend_size;
1317 /*-------- DEBUG LOG --------*/
1318 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1320 std::string datadump;
1321 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
1322 "send_rest_size = %d, send_possible_size = %d, "
1323 "send_offset = %d, unsend_size = %d, edit_division = %d.");
1325 for (it = recv_data.send_status_list.begin();
1326 it != recv_data.send_status_list.end();
1329 formatter % i % it->status % it->send_end_size
1330 % it->send_rest_size % it->send_possible_size
1331 % it->send_offset % it->unsend_size % it->edit_division;
1332 datadump += formatter.str();
1335 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1336 "handle_client_recv() : send status list dump : send status list size = %d.%s");
1338 formatter % recv_data.send_status_list.size() % datadump;
1339 putLogDebug(100041, formatter.str(), __FILE__, __LINE__ );
1341 /*------DEBUG LOG END------*/
1343 //recive buffer process
1344 //buffer rest size < request size
1345 if (recv_data.recive_buffer_rest_size < recvlen)
1347 //buffer max size < remain size + request size
1348 //buffer is need reallocate
1349 if (recv_data.recive_buffer_max_size < data_remain_size + recvlen)
1351 //the buffer's size that will be allocated is exceed the upper limit value
1352 if (MAX_SESSIONLESS_MODULE_BUFFER_SIZE < data_remain_size + recvlen)
1354 std::cerr << "protocol_module_sessionless::handle_client_recv() : the buffer's size that will be allacted is exceed the upper limit value." << std::endl;
1355 boost::format formatter("The buffer's size that will be allocated is exceed the upper limit value. thread id : %d.");
1356 formatter % boost::this_thread::get_id();
1357 putLogError(100030, formatter.str(), __FILE__, __LINE__ );
1358 /*-------- DEBUG LOG --------*/
1359 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1361 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1362 "handle_client_recv(const boost::thread::id thread_id, "
1363 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1364 "const size_t recvlen) : return_value = %d. thread id : %d.");
1365 formatter % FINALIZE % boost::this_thread::get_id();
1366 putLogDebug(100042, formatter.str(), __FILE__, __LINE__ );
1368 /*------DEBUG LOG END------*/
1372 buffer_size = (data_remain_size + recvlen) > MAX_BUFFER_SIZE ? (data_remain_size + recvlen) : MAX_BUFFER_SIZE;
1373 //recive_buffer1's memory allocate and initialization
1374 buffer1 = new char[buffer_size];
1375 /*-------- DEBUG LOG --------*/
1376 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1378 boost::format formatter("new : address = &(%d), size = %lu.");
1379 formatter % static_cast<void*>(buffer1) % buffer_size;
1380 putLogDebug(100043, formatter.str(), __FILE__, __LINE__ );
1382 /*------DEBUG LOG END------*/
1383 memset(buffer1, 0, buffer_size);
1384 //recive_buffer2's memory allocate and initialization
1385 buffer2 = new char[buffer_size];
1386 /*-------- DEBUG LOG --------*/
1387 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1389 boost::format formatter("new : address = &(%d), size = %lu.");
1390 formatter % static_cast<void*>(buffer2) % buffer_size;
1391 putLogDebug(100044, formatter.str(), __FILE__, __LINE__ );
1393 /*------DEBUG LOG END------*/
1394 memset(buffer2, 0, buffer_size);
1396 /*-------- DEBUG LOG --------*/
1397 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1399 std::string datadump;
1400 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
1401 boost::format formatter(
1402 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1403 "handle_client_recv() : before memcpy (data dump) : "
1404 "data begin = %d, data_size = %d, data = %s");
1405 formatter % data_remain_start % data_remain_size % datadump;
1406 putLogDebug(100045, formatter.str(), __FILE__, __LINE__ );
1408 /*------DEBUG LOG END------*/
1409 //copy data from old buffer to new buffer
1410 memcpy(buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
1411 /*-------- DEBUG LOG --------*/
1412 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1414 std::string datadump;
1415 dump_memory(buffer1, data_remain_size, datadump);
1416 boost::format formatter(
1417 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1418 "handle_client_recv() : after memcpy (data dump) : "
1419 "data begin = 0, data_size = %d, data = %s");
1420 formatter % data_remain_size % datadump;
1421 putLogDebug(100046, formatter.str(), __FILE__, __LINE__ );
1423 /*------DEBUG LOG END------*/
1425 /*-------- DEBUG LOG --------*/
1426 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1428 std::string datadump;
1429 dump_memory(recvbuffer.data(), recvlen, datadump);
1430 boost::format formatter(
1431 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1432 "handle_client_recv() : before memcpy (data dump) : "
1433 "data begin = 0, data_size = %d, data = %s");
1434 formatter % recvlen % datadump;
1435 putLogDebug(100047, formatter.str(), __FILE__, __LINE__ );
1437 /*------DEBUG LOG END------*/
1438 memcpy(buffer1 + data_remain_size, recvbuffer.data(), recvlen);
1439 /*-------- DEBUG LOG --------*/
1440 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1442 std::string datadump;
1443 dump_memory(buffer1 + data_remain_size, recvlen, datadump);
1444 boost::format formatter(
1445 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1446 "handle_client_recv() : after memcpy (data dump) : "
1447 "data begin = %d, data_size = %d, data = %s");
1448 formatter % data_remain_size % recvlen % datadump;
1449 putLogDebug(100048, formatter.str(), __FILE__, __LINE__ );
1451 /*------DEBUG LOG END------*/
1452 //free old buffer1 and old buffer2
1453 if (recv_data.recive_buffer1 != NULL)
1455 /*-------- DEBUG LOG --------*/
1456 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1458 boost::format formatter("delete : address = &(%d).");
1459 formatter % static_cast<void*>(recv_data.recive_buffer1);
1460 putLogDebug(100049, formatter.str(), __FILE__,
1463 /*------DEBUG LOG END------*/
1464 delete[] recv_data.recive_buffer1;
1465 recv_data.recive_buffer1 = NULL;
1468 if (recv_data.recive_buffer2 != NULL)
1470 /*-------- DEBUG LOG --------*/
1471 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1473 boost::format formatter("delete : address = &(%d).");
1474 formatter % static_cast<void*>(recv_data.recive_buffer2);
1475 putLogDebug(100050, formatter.str(), __FILE__,
1478 /*------DEBUG LOG END------*/
1479 delete[] recv_data.recive_buffer2;
1480 recv_data.recive_buffer2 = NULL;
1483 //set new buffer pointer
1484 recv_data.recive_buffer1 = buffer1;
1485 recv_data.recive_buffer2 = buffer2;
1486 recv_data.recive_buffer = recv_data.recive_buffer1;
1487 //set new buffer's max size
1488 recv_data.recive_buffer_max_size = buffer_size;
1490 //buffer's max size >= remain data size + requst size
1491 //buffer isn't need reallocate, but switch
1494 //pointer valid check
1495 if (unlikely(recv_data.recive_buffer1 == NULL || recv_data.recive_buffer2 == NULL))
1497 boost::format formatter("Invalid pointer. thread id : %d.");
1498 formatter % boost::this_thread::get_id();
1499 putLogError(100031, formatter.str(), __FILE__, __LINE__ );
1502 //using buffer is buffer1
1503 if (recv_data.recive_buffer == recv_data.recive_buffer1)
1505 //buffer2 initialization
1506 memset(recv_data.recive_buffer2, 0, recv_data.recive_buffer_max_size);
1507 /*-------- DEBUG LOG --------*/
1508 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1510 std::string datadump;
1511 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
1512 boost::format formatter(
1513 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1514 "handle_client_recv() : before memcpy (data dump) : "
1515 "data begin = %d, data_size = %d, data = %s");
1516 formatter % data_remain_start % data_remain_size % datadump;
1517 putLogDebug(100051, formatter.str(), __FILE__, __LINE__ );
1519 /*------DEBUG LOG END------*/
1520 //copy data from buffer1 to buffer2
1521 memcpy(recv_data.recive_buffer2, recv_data.recive_buffer + data_remain_start, data_remain_size);
1522 /*-------- DEBUG LOG --------*/
1523 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1525 std::string datadump;
1526 dump_memory(recv_data.recive_buffer2, recvlen, datadump);
1527 boost::format formatter(
1528 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1529 "handle_client_recv() : after memcpy (data dump) : "
1530 "data begin = 0, data_size = %d, data = %s");
1531 formatter % recvlen % datadump;
1532 putLogDebug(100052, formatter.str(), __FILE__, __LINE__ );
1534 /*------DEBUG LOG END------*/
1535 /*-------- DEBUG LOG --------*/
1536 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1538 std::string datadump;
1539 dump_memory(recvbuffer.data(), recvlen, datadump);
1540 boost::format formatter(
1541 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1542 "handle_client_recv() : before memcpy (data dump) : "
1543 "data begin = 0, data_size = %d, data = %s");
1544 formatter % recvlen % datadump;
1545 putLogDebug(100053, formatter.str(), __FILE__, __LINE__ );
1547 /*------DEBUG LOG END------*/
1548 memcpy(recv_data.recive_buffer2 + data_remain_size, recvbuffer.data(), recvlen);
1549 /*-------- DEBUG LOG --------*/
1550 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1552 std::string datadump;
1553 dump_memory(recv_data.recive_buffer2 + data_remain_size, recvlen, datadump);
1554 boost::format formatter(
1555 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1556 "handle_client_recv() : after memcpy (data dump) : "
1557 "data begin = %d, data_size = %d, data = %s");
1558 formatter % data_remain_size % recvlen % datadump;
1559 putLogDebug(100054, formatter.str(), __FILE__, __LINE__ );
1561 /*------DEBUG LOG END------*/
1562 //set buffer2 as using buffer
1563 recv_data.recive_buffer = recv_data.recive_buffer2;
1565 //using buffer is buffer2
1568 //buffer1 initializtion
1569 memset(recv_data.recive_buffer1, 0, recv_data.recive_buffer_max_size);
1570 /*-------- DEBUG LOG --------*/
1571 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1573 std::string datadump;
1574 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
1575 boost::format formatter(
1576 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1577 "handle_client_recv() : before memcpy (data dump) : "
1578 "data begin = %d, data_size = %d, data = %s");
1579 formatter % data_remain_start % data_remain_size % datadump;
1580 putLogDebug(100055, formatter.str(), __FILE__, __LINE__ );
1582 /*------DEBUG LOG END------*/
1583 //copy data from buffer2 to buffer1
1584 memcpy(recv_data.recive_buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
1585 /*-------- DEBUG LOG --------*/
1586 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1588 std::string datadump;
1589 dump_memory(recv_data.recive_buffer1, data_remain_size, datadump);
1590 boost::format formatter(
1591 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1592 "handle_client_recv() : after memcpy (data dump) : "
1593 "data begin = 0, data_size = %d, data = %s");
1594 formatter % data_remain_size % datadump;
1595 putLogDebug(100056, formatter.str(), __FILE__, __LINE__ );
1597 /*------DEBUG LOG END------*/
1598 /*-------- DEBUG LOG --------*/
1599 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1601 std::string datadump;
1602 dump_memory(recvbuffer.data(), recvlen, datadump);
1603 boost::format formatter(
1604 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1605 "handle_client_recv() : before memcpy (data dump) : "
1606 "data begin = 0, data_size = %d, data = %s");
1607 formatter % recvlen % datadump;
1608 putLogDebug(100057, formatter.str(), __FILE__, __LINE__ );
1610 /*------DEBUG LOG END------*/
1611 memcpy(recv_data.recive_buffer1 + data_remain_size, recvbuffer.data(), recvlen);
1612 /*-------- DEBUG LOG --------*/
1613 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1615 std::string datadump;
1616 dump_memory(recv_data.recive_buffer1 + data_remain_size, recvlen, datadump);
1617 boost::format formatter(
1618 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1619 "handle_client_recv() : after memcpy (data dump) : "
1620 "data begin = %d, data_size = %d, data = %s");
1621 formatter % data_remain_size % recvlen % datadump;
1622 putLogDebug(100058, formatter.str(), __FILE__, __LINE__ );
1624 /*------DEBUG LOG END------*/
1625 //set buffer1 as using buffer
1626 recv_data.recive_buffer = recv_data.recive_buffer1;
1630 //set buffer's rest size
1631 recv_data.recive_buffer_rest_size = recv_data.recive_buffer_max_size - data_remain_size - recvlen;
1633 //remain_size recalc
1634 data_remain_size += recvlen;
1636 send_status_it it_begin = recv_data.send_status_list.begin();
1637 send_status_it it_end = recv_data.send_status_list.end();
1640 for (; it_begin != it_end; ++it_begin)
1642 it_begin->send_offset -= data_remain_start;
1645 //buffer's rest size >= request size
1648 //pointer valid check
1649 if (unlikely(recv_data.recive_buffer == NULL))
1651 boost::format formatter("Invalid pointer. thread id : %d.");
1652 formatter % boost::this_thread::get_id();
1653 putLogError(100032, formatter.str(), __FILE__, __LINE__ );
1656 /*-------- DEBUG LOG --------*/
1657 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1659 std::string datadump;
1660 dump_memory(recvbuffer.data(), recvlen, datadump);
1661 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1662 "handle_client_recv() : before memcpy (data dump) : "
1663 "data begin = 0, data_size = %d, data = %s");
1664 formatter % recvlen % datadump;
1665 putLogDebug(100059, formatter.str(), __FILE__, __LINE__ );
1667 /*------DEBUG LOG END------*/
1668 //copy data from parameter to using buffer
1669 memcpy(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
1670 recvbuffer.data(), recvlen);
1671 /*-------- DEBUG LOG --------*/
1672 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1674 std::string datadump;
1675 dump_memory(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
1677 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1678 "handle_client_recv() : after memcpy (data dump) : "
1679 "data begin = %d, data_size = %d, data = %s");
1680 formatter % (recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size )
1681 % recvlen % datadump;
1682 putLogDebug(100060, formatter.str(), __FILE__, __LINE__ );
1684 /*------DEBUG LOG END------*/
1685 //buffer's rest size recalc
1686 recv_data.recive_buffer_rest_size -= recvlen;
1687 //remain data size recalc
1688 data_remain_size += recvlen;
1691 it = recv_data.send_status_list.begin();
1692 it_end = recv_data.send_status_list.end();
1694 //set request rest size
1695 request_data_remain_size = recvlen;
1697 //original status process
1698 for (; it != it_end; ++it)
1700 //status is SEND_CONTINUE
1701 if (it->status == SEND_CONTINUE)
1703 //send rest size > request size
1704 if (it->send_rest_size > request_data_remain_size)
1706 //send possible size recalc
1707 it->send_possible_size = request_data_remain_size;
1708 //send rest size recalc
1709 it->send_rest_size -= request_data_remain_size;
1710 //send end size recalc
1711 it->send_end_size = 0;
1712 //request size recalc
1713 request_data_remain_size = 0;
1715 //send rest size <= request size
1718 //send possible size recalc
1719 it->send_possible_size = it->send_rest_size;
1720 //send rest size recalc
1721 request_data_remain_size -= it->send_rest_size;
1722 //send end size recalc
1723 it->send_end_size = 0;
1724 //request size recalc
1725 it->send_rest_size = 0;
1727 //set edit_division flag off
1728 it->edit_division = EDIT_DIVISION_NO_EDIT;
1729 //set status SEND_OK
1730 it->status = SEND_OK;
1733 else if (it->status == SEND_NG)
1736 check_result = check_http_method(recv_data.recive_buffer + it->send_offset, data_remain_size);
1737 /*-------- DEBUG LOG --------*/
1738 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1740 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1741 "handle_client_recv() : call check_http_method : "
1742 "return_value = %d. thread id : %d.");
1743 formatter % check_result % boost::this_thread::get_id();
1744 putLogDebug(100061, formatter.str(), __FILE__, __LINE__ );
1746 /*------DEBUG LOG END------*/
1747 //check http method result is OK
1748 if (check_result == CHECK_OK)
1750 //check http version
1751 check_result = check_http_version(recv_data.recive_buffer + it->send_offset, data_remain_size);
1752 /*-------- DEBUG LOG --------*/
1753 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1755 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1756 "handle_client_recv() : call check_http_version : "
1757 "return_value = %d. thread id : %d.");
1758 formatter % check_result % boost::this_thread::get_id();
1759 putLogDebug(100062, formatter.str(), __FILE__, __LINE__ );
1761 /*------DEBUG LOG END------*/
1763 //check method and version result is OK
1764 if (check_result == CHECK_OK)
1766 //search http header
1767 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size, http_header,
1768 header_offset, header_offset_len);
1769 /*-------- DEBUG LOG --------*/
1770 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1772 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1773 "handle_client_recv() : call find_http_header : "
1774 "return_value = %d. thread id : %d.");
1775 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
1776 putLogDebug(100063, formatter.str(), __FILE__, __LINE__ );
1778 /*------DEBUG LOG END------*/
1779 //search http header result is OK
1782 //search Content_Length header
1783 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size,
1784 content_header, content_length_header_offset, content_length_header_len);
1785 /*-------- DEBUG LOG --------*/
1786 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1788 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1789 "handle_client_recv() : call find_http_header : "
1790 "return_value = %d. thread id : %d.");
1791 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
1792 putLogDebug(100064, formatter.str(), __FILE__, __LINE__ );
1794 /*------DEBUG LOG END------*/
1795 //search Content_Length result is OK
1798 //Get Content_Length header's numeric value
1799 for (pos = 0; recv_data.recive_buffer[it->send_offset + content_length_header_offset + pos] != ':' && pos
1800 < content_length_header_len; ++pos)
1802 if (pos == content_length_header_len)
1804 throw std::string("Content_Length field's value is invalid.");
1809 str_value.assign(recv_data.recive_buffer + it->send_offset + content_length_header_offset + pos,
1810 content_length_header_len - pos);
1812 size_t pos_end = str_value.find_last_of('\r');
1813 if (pos_end != std::string::npos)
1815 str_value = str_value.erase(pos_end);
1818 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos);
1820 str_value = str_value.substr(pos);
1824 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
1826 catch (const boost::bad_lexical_cast& ex)
1828 throw std::string("Content_Length field's value is invalid.");
1831 //send_rest_size recalc
1832 //set whole http header's length + Content_Length's value
1833 it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
1835 //search Content_Length result is NG
1838 //send_rest_size recalc
1839 //set whole http header's length
1840 it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
1842 //set edit_division flag on
1843 it->edit_division = EDIT_DIVISION_EDIT;
1845 //search http header result is NG
1848 //unsend_size recalc
1849 it->unsend_size += request_data_remain_size;
1850 //request data rest size recalc
1851 request_data_remain_size = 0;
1855 //check method and version result is NG
1856 else if (check_result == CHECK_NG)
1858 //set edit_division flag off
1859 it->edit_division = EDIT_DIVISION_NO_EDIT;
1860 //send_rest_size recalc
1861 it->send_rest_size = it->unsend_size + request_data_remain_size;
1863 //check method and version result is CHECK_INPOSSIBLE
1866 //unsend_size recalc
1867 it->unsend_size += request_data_remain_size;
1868 //request data rest size recalc
1869 request_data_remain_size = 0;
1873 //recalc fields value according to send_rest_size and request rest size
1874 if (it->send_rest_size > it->unsend_size + request_data_remain_size)
1876 it->send_possible_size = it->unsend_size + request_data_remain_size;
1877 it->send_rest_size -= (it->unsend_size + request_data_remain_size);
1878 it->send_end_size = 0;
1879 it->unsend_size = 0;
1880 request_data_remain_size = 0;
1884 it->send_possible_size = it->send_rest_size;
1885 request_data_remain_size = it->unsend_size + request_data_remain_size - it->send_rest_size;
1886 it->send_end_size = 0;
1887 it->unsend_size = 0;
1888 it->send_rest_size = 0;
1891 //change status from SEND_NG to SEND_OK
1892 it->status = SEND_OK;
1894 //no request rest data to process
1895 if (request_data_remain_size <= 0)
1900 /*-------- DEBUG LOG --------*/
1901 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1903 std::string datadump;
1904 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
1905 "send_rest_size = %d, send_possible_size = %d, "
1906 "send_offset = %d, unsend_size = %d, edit_division = %d.");
1908 for (it = recv_data.send_status_list.begin();
1909 it != recv_data.send_status_list.end();
1912 formatter % i % it->status % it->send_end_size
1913 % it->send_rest_size % it->send_possible_size
1914 % it->send_offset % it->unsend_size % it->edit_division;
1915 datadump += formatter.str();
1918 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1919 "handle_client_recv() : send status list dump : send status list size = %d.%s");
1921 formatter % recv_data.send_status_list.size() % datadump;
1922 putLogDebug(100065, formatter.str(), __FILE__, __LINE__ );
1924 /*------DEBUG LOG END------*/
1925 //there are still rest data need to process
1926 //new status created and add to status list
1927 while (request_data_remain_size > 0)
1929 //new status created
1930 send_status new_send_state;
1932 new_send_state.edit_division = EDIT_DIVISION_NO_EDIT;
1933 new_send_state.send_end_size = 0;
1934 new_send_state.send_offset = 0;
1935 new_send_state.send_possible_size = 0;
1936 new_send_state.unsend_size = 0;
1937 new_send_state.send_rest_size = 0;
1938 //status initialize to SEND_NG
1939 new_send_state.status = SEND_NG;
1940 //add new status to status_list
1941 recv_data.send_status_list.push_back(new_send_state);
1942 std::list<send_status>::reverse_iterator new_send_it = recv_data.send_status_list.rbegin();
1944 new_send_it->send_offset = recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size
1945 - request_data_remain_size;
1948 check_result = check_http_method(recv_data.recive_buffer + new_send_it->send_offset,
1949 request_data_remain_size);
1950 /*-------- DEBUG LOG --------*/
1951 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1953 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1954 "handle_client_recv() : call check_http_method : "
1955 "return_value = %d. thread id : %d.");
1956 formatter % check_result % boost::this_thread::get_id();
1957 putLogDebug(100066, formatter.str(), __FILE__, __LINE__ );
1959 /*------DEBUG LOG END------*/
1960 //check http method result is OK
1961 if (check_result == CHECK_OK)
1963 //check http version
1964 check_result = check_http_version(recv_data.recive_buffer + new_send_it->send_offset,
1965 request_data_remain_size);
1966 /*-------- DEBUG LOG --------*/
1967 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1969 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1970 "handle_client_recv() : call check_http_version : "
1971 "return_value = %d. thread id : %d.");
1972 formatter % check_result % boost::this_thread::get_id();
1973 putLogDebug(100067, formatter.str(), __FILE__, __LINE__ );
1975 /*------DEBUG LOG END------*/
1977 //check http method and version result is OK
1978 if (check_result == CHECK_OK)
1980 //search whole http header, get whole http header's offset and length
1981 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset, request_data_remain_size,
1982 http_header, header_offset, header_offset_len);
1983 /*-------- DEBUG LOG --------*/
1984 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1986 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1987 "handle_client_recv() : call find_http_header : "
1988 "return_value = %d. thread id : %d.");
1989 formatter % check_result % boost::this_thread::get_id();
1990 putLogDebug(100068, formatter.str(), __FILE__, __LINE__ );
1992 /*------DEBUG LOG END------*/
1993 //searched whole http header
1996 //search ContentLength http header, get ContentLength header's offset and length
1997 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset,
1998 request_data_remain_size, content_header, content_length_header_offset, content_length_header_len);
1999 /*-------- DEBUG LOG --------*/
2000 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2002 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2003 "handle_client_recv() : call find_http_header : "
2004 "return_value = %d. thread id : %d.");
2005 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
2006 putLogDebug(100069, formatter.str(), __FILE__, __LINE__ );
2008 /*------DEBUG LOG END------*/
2010 //searched ContentLength http header
2013 //Get Content_Length header's numeric value
2015 recv_data.recive_buffer[new_send_it->send_offset + content_length_header_offset + pos] != ':'
2016 && pos < content_length_header_len;
2018 if (pos == content_length_header_len)
2020 throw std::string("Content_Length field's value is invalid.");
2025 str_value.assign(recv_data.recive_buffer + new_send_it->send_offset + content_length_header_offset + pos,
2026 content_length_header_len - pos);
2028 size_t pos_end = str_value.find_last_of('\r');
2029 if (pos_end != std::string::npos)
2031 str_value = str_value.erase(pos_end);
2034 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos);
2036 str_value = str_value.substr(pos);
2039 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
2041 catch (const boost::bad_lexical_cast& ex)
2043 throw std::string("Content_Length field's value is invalid.");
2045 //send_rest_size recalc
2046 //set whole http header's + whole http header's length + Content_Length's value
2047 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
2049 //not searched ContentLength http header
2052 //send_rest_size recalc
2053 //set whole http header's + whole http header's length
2054 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
2057 //set edit_division flag on
2058 new_send_it->edit_division = EDIT_DIVISION_EDIT;
2060 //not searched whole http header
2063 new_send_it->unsend_size = request_data_remain_size;
2064 request_data_remain_size = 0;
2068 //check http method or version result is NG
2069 else if (check_result == CHECK_NG)
2071 new_send_it->edit_division = EDIT_DIVISION_NO_EDIT;
2072 new_send_it->send_rest_size = request_data_remain_size;
2075 //check http method or version result is impossible
2078 new_send_it->unsend_size = request_data_remain_size;
2079 request_data_remain_size = 0;
2083 //recalc fields value according to send_rest_size and request rest size
2084 if (new_send_it->send_rest_size > request_data_remain_size)
2086 new_send_it->send_possible_size = request_data_remain_size;
2087 new_send_it->send_rest_size -= request_data_remain_size;
2088 new_send_it->send_end_size = 0;
2089 request_data_remain_size = 0;
2093 new_send_it->send_possible_size = new_send_it->send_rest_size;
2094 request_data_remain_size -= new_send_it->send_rest_size;
2095 new_send_it->send_end_size = 0;
2096 new_send_it->send_rest_size = 0;
2099 //change status from SEND_NG to SEND_OK
2100 new_send_it->status = SEND_OK;
2103 /*-------- DEBUG LOG --------*/
2104 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2106 std::string datadump;
2107 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
2108 "send_rest_size = %d, send_possible_size = %d, "
2109 "send_offset = %d, unsend_size = %d, edit_division = %d.");
2111 for (it = recv_data.send_status_list.begin();
2112 it != recv_data.send_status_list.end();
2115 formatter % i % it->status % it->send_end_size
2116 % it->send_rest_size % it->send_possible_size
2117 % it->send_offset % it->unsend_size % it->edit_division;
2118 datadump += formatter.str();
2121 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2122 "handle_client_recv() : send status list dump : send status list size = %d.%s");
2124 formatter % recv_data.send_status_list.size() % datadump;
2125 putLogDebug(100070, formatter.str(), __FILE__, __LINE__ );
2127 /*------DEBUG LOG END------*/
2128 //search for send_possible item in status list
2129 send_status_it it_find = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
2130 data_send_possible());
2131 //the data that can be sent possible is exist
2132 if (it_find != recv_data.send_status_list.end())
2135 if (session_data->sorry_flag == SORRY_FLAG_ON)
2137 status = SORRYSERVER_CONNECT;
2142 status = REALSERVER_CONNECT;
2145 //the data that can be sent possible is not exist
2148 status = CLIENT_RECV;
2154 /*-------- DEBUG LOG --------*/
2155 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2157 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2158 "handle_client_recv() : catch exception e = %d. thread id : %d.");
2159 formatter % e % boost::this_thread::get_id();
2160 putLogDebug(100071, formatter.str(), __FILE__, __LINE__ );
2162 /*------DEBUG LOG END------*/
2165 catch (const std::string& ex)
2167 std::cerr << "protocol_module_sessionless::handle_client_recv() : exception : " << ex << std::endl;
2168 boost::format formatter("protocol_module_sessionless::handle_client_recv() : exception : %s. thread id : %d.");
2169 formatter % ex.c_str() % boost::this_thread::get_id();
2170 putLogError(100033, formatter.str(), __FILE__, __LINE__ );
2173 catch (const std::bad_alloc&)
2175 std::cerr << "protocol_module_sessionless::handle_client_recv() : exception : Could not allocate memory." << std::endl;
2176 boost::format formatter("Could not allocate memory. thread id : %d.");
2177 formatter % boost::this_thread::get_id();
2178 putLogError(100034, formatter.str(), __FILE__, __LINE__ );
2181 catch (const std::exception& ex)
2183 std::cerr << "protocol_module_sessionless::handle_client_recv() : exception : error = " << ex.what() << "." << std::endl;
2184 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2185 "handle_client_recv() : exception : error = %s. thread id : %d.");
2186 formatter % ex.what() % boost::this_thread::get_id();
2187 putLogError(100035, formatter.str(), __FILE__, __LINE__ );
2193 std::cerr << "protocol_module_sessionless::handle_client_recv() : Unknown exception." << std::endl;
2194 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2195 "protocol_module_sessionless::handle_client_recv() : "
2196 "Unknown exception. thread id : %d.");
2197 formatter % boost::this_thread::get_id();
2198 putLogError(100036, formatter.str(), __FILE__, __LINE__ );
2202 /*-------- DEBUG LOG --------*/
2203 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2205 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2206 "handle_client_recv(const boost::thread::id thread_id, "
2207 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
2208 "const size_t recvlen) : return_value = %d. thread id : %d.");
2209 formatter % status % boost::this_thread::get_id();
2210 putLogDebug(100072, formatter.str(), __FILE__, __LINE__ );
2212 /*------DEBUG LOG END------*/
2217 //! called from after realserver select.use in upstream thread.
2218 //! @param[in] upstream thread id
2219 //! @param[out] realserver TCP endpoint
2220 //! @return session use EVENT mode.
2221 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_select(
2222 const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint & rs_endpoint)
2224 /*-------- DEBUG LOG --------*/
2225 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2227 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2228 "handle_realserver_select(const boost::thread::id thread_id, "
2229 "boost::asio::ip::tcp::endpoint & rs_endpoint) : "
2230 "thread_id = %d, rs_endpoint = [%s]:%d.");
2231 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
2232 putLogDebug(100073, formatter.str(), __FILE__, __LINE__ );
2234 /*------DEBUG LOG END------*/
2235 EVENT_TAG status = FINALIZE;
2236 boost::asio::ip::tcp::endpoint tmp_endpoint;
2237 thread_data_ptr session_data;
2238 session_thread_data_map_it session_thread_it;
2239 session_thread_data_map_it session_thread_it_end;
2240 recive_data_map_it recive_data_it;
2242 if (schedule_tcp.empty())
2244 std::cerr << "protocol_module_sessionless::handle_realserver_select() : Schedule_tcp function is empty." << std::endl;
2245 boost::format formatter("Schedule_tcp function is empty. thread id : %d.");
2246 formatter % boost::this_thread::get_id();
2247 putLogError(100037, formatter.str(), __FILE__, __LINE__ );
2248 /*-------- DEBUG LOG --------*/
2249 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2251 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2252 "handle_realserver_select(const boost::thread::id thread_id, "
2253 "boost::asio::ip::tcp::endpoint & rs_endpoint)"
2254 " : return_value = %d. thread id : %d.");
2255 formatter % FINALIZE % boost::this_thread::get_id();
2256 putLogDebug(100074, formatter.str(), __FILE__, __LINE__ );
2258 /*------DEBUG LOG END------*/
2265 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
2267 session_thread_it = session_thread_data_map.find(thread_id);
2268 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2270 boost::format formatter("Invalid thread id. thread id : %d.");
2271 formatter % boost::this_thread::get_id();
2272 putLogError(100038, formatter.str(), __FILE__, __LINE__ );
2276 session_data = session_thread_it->second;
2279 //call schedule_module's schedule function, get realserver endpoint
2281 rs_list_scoped_lock scoped_lock(rs_list_lock, rs_list_unlock);
2282 schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, rs_endpoint);
2285 /*-------- DEBUG LOG --------*/
2286 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2288 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2289 "handle_realserver_select() : call schedule_tcp : "
2290 "rs_endpoint = [%s]:%d. thread id : %d.");
2291 formatter % rs_endpoint.address().to_string() % rs_endpoint.port() % boost::this_thread::get_id();
2292 putLogDebug(100075, formatter.str(), __FILE__, __LINE__ );
2294 /*------DEBUG LOG END------*/
2297 if (rs_endpoint != tmp_endpoint)
2300 session_data->target_endpoint = rs_endpoint;
2302 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
2303 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
2305 boost::format formatter("Invalid endpoint. thread id : %d.");
2306 formatter % boost::this_thread::get_id();
2307 putLogError(100039, formatter.str(), __FILE__, __LINE__ );
2310 recive_data& recv_data = recive_data_it->second;
2312 send_status_it it = recv_data.send_status_list.begin();
2313 send_status_it it_end = recv_data.send_status_list.end();
2315 it = find_if(it, it_end, data_send_possible());
2318 status = REALSERVER_CONNECT;
2322 status = CLIENT_RECV;
2328 session_data->sorry_flag = SORRY_FLAG_ON;
2329 /*-------- DEBUG LOG --------*/
2330 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2332 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2333 "handle_realserver_select() : SORRY_FLAG_ON. thread id : %d.");
2334 formatter % boost::this_thread::get_id();
2335 putLogDebug(100076, formatter.str(), __FILE__, __LINE__ );
2337 /*------DEBUG LOG END------*/
2338 status = SORRYSERVER_SELECT;
2343 /*-------- DEBUG LOG --------*/
2344 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2346 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2347 "handle_realserver_select() : catch exception e = %d. thread id : %d.");
2348 formatter % e % boost::this_thread::get_id();
2349 putLogDebug(100077, formatter.str(), __FILE__, __LINE__ );
2352 /*------DEBUG LOG END------*/
2354 catch (const std::exception& ex)
2356 std::cerr << "protocol_module_sessionless::handle_realserver_select() : exception : error = " << ex.what() << "." << std::endl;
2357 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2358 "handle_realserver_select() : exception : error = %s. thread id : %d.");
2359 formatter % ex.what() % boost::this_thread::get_id();
2360 putLogError(100040, formatter.str(), __FILE__, __LINE__ );
2365 std::cerr << "protocol_module_sessionless::handle_realserver_select() : Unknown exception." << std::endl;
2366 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2367 "protocol_module_sessionless::handle_realserver_select() : "
2368 "Unknown exception. thread id : %d.");
2369 formatter % boost::this_thread::get_id();
2370 putLogError(100041, formatter.str(), __FILE__, __LINE__ );
2374 /*-------- DEBUG LOG --------*/
2375 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2377 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2378 "handle_realserver_select(const boost::thread::id thread_id, "
2379 "boost::asio::ip::tcp::endpoint & rs_endpoint)"
2380 " : return_value = %d. thread id : %d.");
2381 formatter % status % boost::this_thread::get_id();
2382 putLogDebug(100078, formatter.str(), __FILE__, __LINE__ );
2384 /*------DEBUG LOG END------*/
2389 //! called from after realserver select
2390 //! @param[in] upstream thread id
2391 //! @param[out] realserver UDP endpoint
2392 //! @param[out] sendbuffer reference
2393 //! @param[out] send data length
2394 //! @return session use EVENT mode.
2395 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_select(
2396 const boost::thread::id thread_id, boost::asio::ip::udp::endpoint& rs_endpoint, boost::array<char,
2397 MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
2399 /*-------- DEBUG LOG --------*/
2400 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2402 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2403 "handle_realserver_select(const boost::thread::id thread_id, "
2404 "boost::asio::ip::udp::endpoint& rs_endpoint, boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
2405 "size_t& datalen) : "
2406 "return_value = %d. thread id : %d.");
2407 formatter % STOP % boost::this_thread::get_id();
2408 putLogDebug(100079, formatter.str(), __FILE__, __LINE__ );
2410 /*------DEBUG LOG END------*/
2413 //! called from after realserver connect
2414 //! @param[in] upstream thread id
2415 //! @param[out] sendbuffer reference
2416 //! @param[out] send data length
2417 //! @return session use EVENT mode.
2418 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_connect(
2419 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
2421 /*-------- DEBUG LOG --------*/
2422 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2424 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2425 "handle_realserver_connect(const boost::thread::id thread_id, "
2426 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
2428 formatter % thread_id;
2429 putLogDebug(100080, formatter.str(), __FILE__, __LINE__ );
2431 /*------DEBUG LOG END------*/
2433 EVENT_TAG status = FINALIZE;
2435 size_t header_offset = 0;
2436 size_t header_offset_len = 0;
2437 size_t send_buffer_remian_size = 0;
2438 size_t copy_size = 0;
2439 const int send_buffer_end_size = sendbuffer.max_size();
2440 const std::string http_header = "";
2441 const std::string str_forword_for = "X-Forwarded-For";
2442 thread_data_ptr session_data;
2443 session_thread_data_map_it session_thread_it;
2444 recive_data_map_it recive_data_it;
2449 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
2452 session_thread_it = session_thread_data_map.find(thread_id);
2453 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2455 boost::format formatter("Invalid thread id. thread id : %d.");
2456 formatter % boost::this_thread::get_id();
2457 putLogError(100042, formatter.str(), __FILE__, __LINE__ );
2461 session_data = session_thread_it->second;
2465 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
2466 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
2468 boost::format formatter("Invalid endpoint. thread id : %d.");
2469 formatter % boost::this_thread::get_id();
2470 putLogError(100043, formatter.str(), __FILE__, __LINE__ );
2474 //recive_buffer pointer check
2475 recive_data& recv_data = recive_data_it->second;
2476 if (unlikely(recv_data.recive_buffer == NULL))
2478 boost::format formatter("Invalid pointer. thread id : %d.");
2479 formatter % boost::this_thread::get_id();
2480 putLogError(100044, formatter.str(), __FILE__, __LINE__ );
2485 send_status_it it = recv_data.send_status_list.begin();
2486 send_status_it it_end = recv_data.send_status_list.end();
2487 it = find_if(it, it_end, data_send_possible());
2488 if (unlikely(it == it_end))
2490 boost::format formatter("Sending possible data is not existed. thread id : %d.");
2491 formatter % boost::this_thread::get_id();
2492 putLogError(100045, formatter.str(), __FILE__, __LINE__ );
2496 //send buffer rest size initialization
2497 send_buffer_remian_size = send_buffer_end_size;
2499 //edit_division flag on
2500 if (it->edit_division == EDIT_DIVISION_EDIT && forwarded_for == FORWARDED_FOR_ON)
2502 //edit list is empty
2503 if (it->edit_data_list.empty())
2507 edata.data_size = 0;
2508 edata.insert_posission = 0;
2509 edata.replace_size = 0;
2510 //search X-Forwarded-For header
2511 ret = find_http_header(recv_data.recive_buffer + it->send_offset, it->send_possible_size,
2512 str_forword_for, header_offset, header_offset_len);
2513 /*-------- DEBUG LOG --------*/
2514 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2516 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2517 "handle_realserver_connect() : call find_http_header : "
2518 "return_value = %d. thread id : %d.");
2519 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
2520 putLogDebug(100081, formatter.str(), __FILE__, __LINE__ );
2522 /*------DEBUG LOG END------*/
2523 //search http header result is OK
2526 //edit X-Forwarded-For header, set it to edata.data
2527 edata.data.assign(recv_data.recive_buffer + it->send_offset + header_offset, header_offset_len);
2529 edata.data += session_data->client_endpoint_tcp.address().to_string();
2530 //save new X-Forwarded-For header offset
2531 edata.insert_posission = header_offset;
2532 //save new X-Forwarded-For header length
2533 edata.data_size = edata.data.size();
2534 //save old X-Forwarded-For header length
2535 edata.replace_size = header_offset_len;
2537 //search http header result is NG
2540 //search whole http header, get whole http header's offset and length
2541 ret = find_http_header(recv_data.recive_buffer + it->send_offset, it->send_possible_size, "",
2542 header_offset, header_offset_len);
2543 /*-------- DEBUG LOG --------*/
2544 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2546 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2547 "handle_realserver_connect() : call find_http_header : "
2548 "return_value = %d. thread id : %d.");
2549 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
2550 putLogDebug(100082, formatter.str(), __FILE__, __LINE__ );
2552 /*------DEBUG LOG END------*/
2555 boost::format formatter("find_http_header() function failure. thread id : %d.");
2556 formatter % boost::this_thread::get_id();
2557 putLogError(100046, formatter.str(), __FILE__, __LINE__ );
2558 /*-------- DEBUG LOG --------*/
2559 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2561 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2562 "handle_realserver_connect(const boost::thread::id thread_id, "
2563 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
2564 "size_t& datalen) : return_value = %d. thread id : %d.");
2565 formatter % FINALIZE % boost::this_thread::get_id();
2566 putLogDebug(100083, formatter.str(), __FILE__, __LINE__ );
2568 /*------DEBUG LOG END------*/
2571 //create X-Forwarded-For header, put it to edata.data
2572 edata.data = str_forword_for;
2574 edata.data += session_data->client_endpoint_tcp.address().to_string();
2575 edata.data += "\r\n";
2576 //save new X-Forwarded-For header offset
2577 edata.insert_posission = header_offset;
2578 //save new X-Forwarded-For header length
2579 edata.data_size = edata.data.size();
2580 //save old X-Forwarded-For header length
2581 edata.replace_size = 0;
2584 //add to edit_data_list
2585 it->edit_data_list.push_back(edata);
2588 /*-------- DEBUG LOG --------*/
2589 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2591 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2592 "handle_realserver_connect() : Copy data loop start. thread id : %d.");
2593 formatter % boost::this_thread::get_id();
2594 putLogDebug(100084, formatter.str(), __FILE__, __LINE__ );
2596 /*------DEBUG LOG END------*/
2599 //edit_data_list is empty
2600 if (it->edit_data_list.empty())
2602 //set edit_division flag on
2603 it->edit_division = EDIT_DIVISION_NO_EDIT;
2605 if (send_buffer_remian_size > 0 && it->send_possible_size > 0)
2607 //send_buffer_remian_size is larger
2608 if (send_buffer_remian_size >= it->send_possible_size)
2610 copy_size = it->send_possible_size;
2611 /*-------- DEBUG LOG --------*/
2612 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2614 std::string datadump;
2615 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
2616 it->send_possible_size, datadump);
2617 boost::format formatter(
2618 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2619 "handle_realserver_connect() : before memcpy (data dump) : "
2620 "data begin = %d, data_size = %d, data = %s");
2621 formatter % (it->send_offset + it->send_end_size)
2622 % copy_size % datadump;
2623 putLogDebug(100085, formatter.str(), __FILE__, __LINE__ );
2625 /*------DEBUG LOG END------*/
2626 //copy data from recive_buffer to sendbuffer by sending_possible size
2627 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2628 recv_data.recive_buffer + it->send_offset + it->send_end_size,
2629 it->send_possible_size);
2630 /*-------- DEBUG LOG --------*/
2631 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2633 std::string datadump;
2634 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2635 it->send_possible_size, datadump);
2637 boost::format formatter(
2638 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2639 "handle_realserver_connect() : after memcpy (data dump) : "
2640 "data begin = %d, data_size = %d, data = %s");
2641 formatter % (send_buffer_end_size - send_buffer_remian_size)
2642 % copy_size % datadump;
2643 putLogDebug(100086, formatter.str(), __FILE__, __LINE__ );
2645 /*------DEBUG LOG END------*/
2647 it->send_end_size += copy_size;
2648 it->send_possible_size = 0;
2649 send_buffer_remian_size -= copy_size;
2651 //send_possible_size is larger
2654 copy_size = send_buffer_remian_size;
2655 /*-------- DEBUG LOG --------*/
2656 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2658 std::string datadump;
2659 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
2660 copy_size, datadump);
2662 boost::format formatter(
2663 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2664 "handle_realserver_connect() : before memcpy (data dump) : "
2665 "data begin = %d, data_size = %d, data = %s");
2666 formatter % (it->send_offset + it->send_end_size)
2667 % copy_size % datadump;
2668 putLogDebug(100087, formatter.str(), __FILE__, __LINE__ );
2670 /*------DEBUG LOG END------*/
2671 //copy data from recive_buffer to sendbuffer by send buffer rest size
2672 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2673 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
2674 /*-------- DEBUG LOG --------*/
2675 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2677 std::string datadump;
2678 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2679 copy_size, datadump);
2681 boost::format formatter(
2682 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2683 "handle_realserver_connect() : after memcpy (data dump) : "
2684 "data begin = %d, data_size = %d, data = %s");
2685 formatter % (send_buffer_end_size - send_buffer_remian_size)
2686 % copy_size % datadump;
2687 putLogDebug(100088, formatter.str(), __FILE__, __LINE__ );
2689 /*------DEBUG LOG END------*/
2690 it->send_end_size += copy_size;
2691 it->send_possible_size -= copy_size;
2692 send_buffer_remian_size = 0;
2697 //edit_data_list is not empty
2700 //find the item in the list which has mininum insert_posission
2701 std::list<edit_data>::iterator edit_min = std::min_element(it->edit_data_list.begin(),
2702 it->edit_data_list.end());
2703 //send_buffer_remian_size is larger than data that before X-Forwarded-For
2704 if (send_buffer_remian_size >= edit_min->insert_posission - it->send_end_size)
2706 //copy data before X-Forwarded-For
2707 copy_size = edit_min->insert_posission - it->send_end_size;
2708 /*-------- DEBUG LOG --------*/
2709 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2711 std::string datadump;
2712 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
2713 copy_size, datadump);
2715 boost::format formatter(
2716 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2717 "handle_realserver_connect() : before memcpy (data dump) : "
2718 "data begin = %d, data_size = %d, data = %s");
2719 formatter % (it->send_offset + it->send_end_size)
2720 % copy_size % datadump;
2721 putLogDebug(100089, formatter.str(), __FILE__, __LINE__ );
2723 /*------DEBUG LOG END------*/
2724 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2725 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
2726 /*-------- DEBUG LOG --------*/
2727 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2729 std::string datadump;
2730 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2731 copy_size, datadump);
2732 boost::format formatter(
2733 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2734 "handle_realserver_connect() : after memcpy (data dump) : "
2735 "data begin = %d, data_size = %d, data = %s");
2736 formatter % (send_buffer_end_size - send_buffer_remian_size)
2737 % copy_size % datadump;
2738 putLogDebug(100090, formatter.str(), __FILE__, __LINE__ );
2740 /*------DEBUG LOG END------*/
2741 it->send_end_size += copy_size;
2742 it->send_possible_size -= copy_size;
2743 send_buffer_remian_size -= copy_size;
2745 //there is remain buffer for copy X-Forwarded-For
2746 if (send_buffer_remian_size >= edit_min->data_size)
2748 /*-------- DEBUG LOG --------*/
2749 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2751 std::string datadump;
2752 dump_memory(edit_min->data.c_str(),
2753 edit_min->data_size, datadump);
2755 boost::format formatter(
2756 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2757 "handle_realserver_connect() : before memcpy (data dump) : "
2758 "data begin = 0, data_size = %d, data = %s");
2759 formatter % edit_min->data_size % datadump;
2760 putLogDebug(100091, formatter.str(), __FILE__, __LINE__ );
2762 /*------DEBUG LOG END------*/
2763 //copy X-Forwarded-For
2764 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2765 edit_min->data.c_str(), edit_min->data_size);
2766 /*-------- DEBUG LOG --------*/
2767 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2769 std::string datadump;
2770 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2771 edit_min->data_size, datadump);
2772 boost::format formatter(
2773 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2774 "handle_realserver_connect() : after memcpy (data dump) : "
2775 "data begin = %d, data_size = %d, data = %s");
2776 formatter % (send_buffer_end_size - send_buffer_remian_size)
2777 % edit_min->data_size % datadump;
2778 putLogDebug(100092, formatter.str(), __FILE__, __LINE__ );
2780 /*------DEBUG LOG END------*/
2781 it->send_end_size += edit_min->replace_size;
2782 it->send_possible_size -= edit_min->replace_size;
2783 send_buffer_remian_size -= edit_min->data_size;
2784 it->edit_data_list.erase(edit_min);
2792 //data that before X-Forwarded-For is larger than send_buffer_remian_size
2795 copy_size = send_buffer_remian_size;
2796 /*-------- DEBUG LOG --------*/
2797 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2799 std::string datadump;
2800 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
2801 copy_size, datadump);
2803 boost::format formatter(
2804 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2805 "handle_realserver_connect() : before memcpy (data dump) : "
2806 "data begin = %d, data_size = %d, data = %s");
2807 formatter % (it->send_offset + it->send_end_size)
2808 % copy_size % datadump;
2809 putLogDebug(100093, formatter.str(), __FILE__, __LINE__ );
2811 /*------DEBUG LOG END------*/
2812 //copy data as large as possible
2813 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2814 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
2815 /*-------- DEBUG LOG --------*/
2816 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2818 std::string datadump;
2819 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2820 copy_size, datadump);
2822 boost::format formatter(
2823 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2824 "handle_realserver_connect() : after memcpy (data dump) : "
2825 "data begin = %d, data_size = %d, data = %s");
2826 formatter % (send_buffer_end_size - send_buffer_remian_size)
2827 % copy_size % datadump;
2828 putLogDebug(100094, formatter.str(), __FILE__, __LINE__ );
2830 /*------DEBUG LOG END------*/
2832 it->send_end_size += copy_size;
2833 it->send_possible_size -= copy_size;
2834 send_buffer_remian_size -= copy_size;
2839 /*-------- DEBUG LOG --------*/
2840 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2842 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2843 "handle_realserver_connect() : Copy data loop end. thread id : %d.");
2844 formatter % boost::this_thread::get_id();
2845 putLogDebug(100095, formatter.str(), __FILE__, __LINE__ );
2847 /*------DEBUG LOG END------*/
2849 //edit_division flag is off
2852 //copy data as large as possible
2853 //send_possible_size is larger
2854 if (send_buffer_remian_size >= it->send_possible_size)
2856 copy_size = it->send_possible_size;
2857 /*-------- DEBUG LOG --------*/
2858 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2860 std::string datadump;
2861 dump_memory(recv_data.recive_buffer + it->send_offset,
2862 copy_size, datadump);
2863 boost::format formatter(
2864 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2865 "handle_realserver_connect() : before memcpy (data dump) : "
2866 "data begin = %d, data_size = %d, data = %s");
2867 formatter % it->send_offset
2868 % copy_size % datadump;
2869 putLogDebug(100096, formatter.str(), __FILE__, __LINE__ );
2871 /*------DEBUG LOG END------*/
2872 //copy data by send_possible size
2873 memcpy(sendbuffer.data(), recv_data.recive_buffer + it->send_offset, copy_size);
2874 /*-------- DEBUG LOG --------*/
2875 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2877 std::string datadump;
2878 dump_memory(sendbuffer.data(), copy_size, datadump);
2879 boost::format formatter(
2880 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2881 "handle_realserver_connect() : after memcpy (data dump) : "
2882 "data begin = 0, data_size = %d, data = %s");
2883 formatter % copy_size % datadump;
2884 putLogDebug(100097, formatter.str(), __FILE__, __LINE__ );
2886 /*------DEBUG LOG END------*/
2887 it->send_end_size = copy_size;
2888 it->send_possible_size = 0;
2889 send_buffer_remian_size -= copy_size;
2891 //buffer rest size is larger
2894 /*-------- DEBUG LOG --------*/
2895 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2897 std::string datadump;
2898 dump_memory(recv_data.recive_buffer + it->send_offset, send_buffer_remian_size, datadump);
2900 boost::format formatter(
2901 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2902 "handle_realserver_connect() : before memcpy (data dump) : "
2903 "data begin = %d, data_size = %d, data = %s");
2904 formatter % it->send_offset
2905 % send_buffer_remian_size % datadump;
2906 putLogDebug(100098, formatter.str(), __FILE__, __LINE__ );
2908 /*------DEBUG LOG END------*/
2909 //copy data by buffer rest size
2910 memcpy(sendbuffer.data(), recv_data.recive_buffer + it->send_offset, send_buffer_remian_size);
2911 /*-------- DEBUG LOG --------*/
2912 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2914 std::string datadump;
2915 dump_memory(sendbuffer.data(), send_buffer_remian_size, datadump);
2916 boost::format formatter(
2917 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2918 "handle_realserver_connect() : after memcpy (data dump) : "
2919 "data begin = 0, data_size = %d, data = %s");
2920 formatter % send_buffer_remian_size % datadump;
2921 putLogDebug(100099, formatter.str(), __FILE__, __LINE__ );
2923 /*------DEBUG LOG END------*/
2924 it->send_end_size = send_buffer_remian_size;
2925 it->send_possible_size -= send_buffer_remian_size;
2926 send_buffer_remian_size = 0;
2930 //set copyed data length
2931 datalen = send_buffer_end_size - send_buffer_remian_size;
2932 status = REALSERVER_SEND;
2936 /*-------- DEBUG LOG --------*/
2937 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2939 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2940 "handle_realserver_connect() : catch exception e = %d. thread id : %d.");
2941 formatter % e % boost::this_thread::get_id();
2942 putLogDebug(100100, formatter.str(), __FILE__, __LINE__ );
2945 /*------DEBUG LOG END------*/
2947 catch (const std::exception& ex)
2949 std::cerr << "protocol_module_sessionless::handle_realserver_connect() : exception : error = " << ex.what() << "." << std::endl;
2950 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2951 "handle_realserver_connect() : exception : error = %s. thread id : %d.");
2952 formatter % ex.what() % boost::this_thread::get_id();
2953 putLogError(100047, formatter.str(), __FILE__, __LINE__ );
2958 std::cerr << "protocol_module_sessionless::handle_realserver_connect() : Unknown exception." << std::endl;
2959 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2960 "handle_realserver_connect() : Unknown exception. thread id : %d.");
2961 formatter % boost::this_thread::get_id();
2962 putLogError(100048, formatter.str(), __FILE__, __LINE__ );
2966 /*-------- DEBUG LOG --------*/
2967 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2969 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2970 "handle_realserver_connect(const boost::thread::id thread_id, "
2971 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
2972 "size_t& datalen) : return_value = %d. thread id : %d.");
2973 formatter % status % boost::this_thread::get_id();
2974 putLogDebug(100101, formatter.str(), __FILE__, __LINE__ );
2976 /*------DEBUG LOG END------*/
2981 //! called from after realserver connection fail
2982 //! @param[in] upstream thread id
2983 //! @param[in] fail realserver endpoint reference
2984 //! @return session use EVENT mode.
2985 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_connection_fail(
2986 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint)
2988 /*-------- DEBUG LOG --------*/
2989 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2991 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2992 "handle_realserver_connection_fail(const boost::thread::id thread_id, "
2993 "const boost::asio::ip::tcp::endpoint & rs_endpoint) : "
2994 "thread_id = %d, rs_endpoint = [%s]:%d.");
2995 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
2996 putLogDebug(100102, formatter.str(), __FILE__, __LINE__ );
2998 /*------DEBUG LOG END------*/
3000 EVENT_TAG status = FINALIZE;
3001 thread_data_ptr session_data;
3002 session_thread_data_map_it session_thread_it;
3006 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
3008 session_thread_it = session_thread_data_map.find(thread_id);
3009 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3011 boost::format formatter("Invalid thread id. thread id : %d.");
3012 formatter % boost::this_thread::get_id();
3013 putLogError(100049, formatter.str(), __FILE__, __LINE__ );
3017 session_data = session_thread_it->second;
3020 session_data->end_flag = END_FLAG_ON;
3021 /*-------- DEBUG LOG --------*/
3022 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3024 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3025 "handle_realserver_connection_fail() : END_FLAG_ON. thread id : %d.");
3026 formatter % boost::this_thread::get_id();
3027 putLogDebug(100103, formatter.str(), __FILE__, __LINE__ );
3029 /*------DEBUG LOG END------*/
3030 status = CLIENT_DISCONNECT;
3034 /*-------- DEBUG LOG --------*/
3035 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3037 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3038 "handle_realserver_connection_fail() : catch exception e = %d. thread id : %d.");
3039 formatter % e % boost::this_thread::get_id();
3040 putLogDebug(100104, formatter.str(), __FILE__, __LINE__ );
3043 /*------DEBUG LOG END------*/
3045 catch (std::exception& ex)
3047 std::cerr << "protocol_module_sessionless::handle_realserver_connection_fail() : exception : error = " << ex.what() << "." << std::endl;
3048 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3049 "handle_realserver_connection_fail() : exception : error = %s. thread id : %d.");
3050 formatter % ex.what() % boost::this_thread::get_id();
3051 putLogError(100050, formatter.str(), __FILE__, __LINE__ );
3056 std::cerr << "protocol_module_sessionless::handle_realserver_connection_fail() : Unknown exception." << std::endl;
3057 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3058 "handle_realserver_connection_fail() : Unknown exception. thread id : %d.");
3059 formatter % boost::this_thread::get_id();
3060 putLogError(100051, formatter.str(), __FILE__, __LINE__ );
3064 /*-------- DEBUG LOG --------*/
3065 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3067 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3068 "handle_realserver_connection_fail(const boost::thread::id thread_id, "
3069 "const boost::asio::ip::tcp::endpoint & rs_endpoint) : return_value = %d. thread id : %d.");
3070 formatter % status % boost::this_thread::get_id();
3071 putLogDebug(100105, formatter.str(), __FILE__, __LINE__ );
3073 /*------DEBUG LOG END------*/
3076 //! called from after realserver send.
3077 //! @param[in] upstream thread id
3078 //! @return session use EVENT mode.
3079 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_send(
3080 const boost::thread::id thread_id)
3082 /*-------- DEBUG LOG --------*/
3083 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3085 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3086 "handle_realserver_send(const boost::thread::id thread_id) : "
3088 formatter % thread_id;
3089 putLogDebug(100106, formatter.str(), __FILE__, __LINE__ );
3091 /*------DEBUG LOG END------*/
3092 EVENT_TAG status = FINALIZE;
3093 thread_data_ptr session_data;
3094 session_thread_data_map_it session_thread_it;
3095 recive_data_map_it recive_data_it;
3100 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
3103 session_thread_it = session_thread_data_map.find(thread_id);
3104 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3106 boost::format formatter("Invalid thread id. thread id : %d.");
3107 formatter % boost::this_thread::get_id();
3108 putLogError(100052, formatter.str(), __FILE__, __LINE__ );
3112 session_data = session_thread_it->second;
3116 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
3117 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
3119 boost::format formatter("Invalid endpoint. thread id : %d.");
3120 formatter % boost::this_thread::get_id();
3121 putLogError(100053, formatter.str(), __FILE__, __LINE__ );
3125 recive_data& recv_data = recive_data_it->second;
3127 send_status_it it = recv_data.send_status_list.begin();
3128 send_status_it it_end = recv_data.send_status_list.end();
3131 it = std::adjacent_find(it, it_end, data_send_list_incorrect());
3132 if (unlikely(it != it_end))
3134 boost::format formatter("Sending possible data is invalid. thread id : %d.");
3135 formatter % boost::this_thread::get_id();
3136 putLogError(100054, formatter.str(), __FILE__, __LINE__ );
3141 it = recv_data.send_status_list.begin();
3142 it = std::find_if(it, it_end, data_send_ok());
3143 if (unlikely(it == it_end))
3145 boost::format formatter("Sending possible data is not existed. thread id : %d.");
3146 formatter % boost::this_thread::get_id();
3147 putLogError(100055, formatter.str(), __FILE__, __LINE__ );
3151 //sending possible data is exist
3152 if (it->send_possible_size > 0)
3154 //status remain SEND_OK
3155 it->status = SEND_OK;
3157 it->send_offset += it->send_end_size;
3159 //insert_posission recalc
3160 for (std::list<edit_data>::iterator list_it = it->edit_data_list.begin(); list_it
3161 != it->edit_data_list.end(); ++list_it)
3163 list_it->insert_posission -= it->send_end_size;
3166 //send_end_size recalc
3167 it->send_end_size = 0;
3169 //sending possible data is not exist
3172 //can recive from client continue
3173 if (it->send_rest_size > 0)
3175 //change status from SEND_OK to SEND_CONTINUE
3176 it->status = SEND_CONTINUE;
3178 //can not recive from client continue
3181 //change status from SEND_OK to SEND_END
3182 it->status = SEND_END;
3186 it = recv_data.send_status_list.begin();
3187 it = find_if(it, it_end, data_send_ok());
3188 //send_ok item is exist
3191 status = REALSERVER_CONNECT;
3193 //send_ok item is exist
3196 status = CLIENT_RECV;
3202 /*-------- DEBUG LOG --------*/
3203 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3205 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3206 "handle_realserver_send() : catch exception e = %d. thread id : %d.");
3207 formatter % e % boost::this_thread::get_id();
3208 putLogDebug(100107, formatter.str(), __FILE__, __LINE__ );
3211 /*------DEBUG LOG END------*/
3213 catch (const std::exception& ex)
3215 std::cerr << "protocol_module_sessionless::handle_realserver_send() : exception : error = " << ex.what() << "." << std::endl;
3216 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3217 "handle_realserver_send() : exception : error = %s. thread id : %d.");
3218 formatter % ex.what() % boost::this_thread::get_id();
3219 putLogError(100056, formatter.str(), __FILE__, __LINE__ );
3225 std::cerr << "protocol_module_sessionless::handle_realserver_send() : Unknown exception." << std::endl;
3226 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3227 "handle_realserver_send() : Unknown exception. thread id : %d.");
3228 formatter % boost::this_thread::get_id();
3229 putLogError(100057, formatter.str(), __FILE__, __LINE__ );
3233 /*-------- DEBUG LOG --------*/
3234 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3236 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3237 "handle_realserver_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
3238 formatter % status % boost::this_thread::get_id();
3239 putLogDebug(100108, formatter.str(), __FILE__, __LINE__ );
3241 /*------DEBUG LOG END------*/
3246 //! called from after sorryserver select
3247 //! @param[in] upstream thread id
3248 //! @param[in] sorryserver endpiont reference
3249 //! @return session use EVENT mode.
3250 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_select(
3251 const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint& sorry_endpoint)
3253 /*-------- DEBUG LOG --------*/
3254 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3256 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3257 "handle_sorryserver_select(const boost::thread::id thread_id, "
3258 "boost::asio::ip::tcp::endpoint& sorry_endpoint) : "
3259 "thread_id = %d, sorry_endpoint = [%s]:%d.");
3260 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port();
3261 putLogDebug(100109, formatter.str(), __FILE__, __LINE__ );
3263 /*------DEBUG LOG END------*/
3264 EVENT_TAG status = FINALIZE;
3265 boost::asio::ip::tcp::endpoint client_endpoint;
3267 thread_data_ptr session_data;
3268 session_thread_data_map_it session_thread_it;
3269 recive_data_map_it recive_data_it;
3273 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
3275 session_thread_it = session_thread_data_map.find(thread_id);
3276 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second== NULL))
3278 boost::format formatter("Invalid thread id. thread id : %d.");
3279 formatter % boost::this_thread::get_id();
3280 putLogError(100058, formatter.str(), __FILE__, __LINE__ );
3284 session_data = session_thread_it->second;
3285 //set sorry_endpoint
3286 session_data->target_endpoint = sorry_endpoint;
3289 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
3290 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
3292 boost::format formatter("Invalid endpoint. thread id : %d.");
3293 formatter % boost::this_thread::get_id();
3294 putLogError(100059, formatter.str(), __FILE__, __LINE__ );
3298 recive_data& recv_data = recive_data_it->second;
3300 send_status_it it = recv_data.send_status_list.begin();
3301 send_status_it it_end = recv_data.send_status_list.end();
3303 it = find_if(it, it_end, data_send_possible());
3306 status = SORRYSERVER_CONNECT;
3310 status = CLIENT_RECV;
3316 /*-------- DEBUG LOG --------*/
3317 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3319 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3320 "handle_sorryserver_select() : catch exception e = %d. thread id : %d.");
3321 formatter % e % boost::this_thread::get_id();
3322 putLogDebug(100110, formatter.str(), __FILE__, __LINE__ );
3325 /*------DEBUG LOG END------*/
3327 catch (const std::bad_alloc& ex)
3329 std::cerr << "protocol_module_sessionless::handle_sorryserver_select() : exception : Could not allocate memory." << std::endl;
3330 boost::format formatter("Could not allocate memory. thread id : %d.");
3331 formatter % boost::this_thread::get_id();
3332 putLogError(100060, formatter.str(), __FILE__, __LINE__ );
3335 catch (const std::exception& ex)
3337 std::cerr << "protocol_module_sessionless::handle_sorryserver_select() : exception : error = " << ex.what() << "." << std::endl;
3338 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3339 "handle_sorryserver_select() : exception : error = %s. thread id : %d.");
3340 formatter % ex.what() % boost::this_thread::get_id();
3341 putLogError(100061, formatter.str(), __FILE__, __LINE__ );
3346 std::cerr << "protocol_module_sessionless::handle_sorryserver_select() : Unknown exception." << std::endl;
3347 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3348 "handle_sorryserver_select() : Unknown exception. thread id : %d.");
3349 formatter % boost::this_thread::get_id();
3350 putLogError(100062, formatter.str(), __FILE__, __LINE__ );
3354 /*-------- DEBUG LOG --------*/
3355 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3359 "out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3360 "handle_sorryserver_select(const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint& sorry_endpoint) : return_value = %d."
3361 " thread id : %d.");
3362 formatter % status % boost::this_thread::get_id();
3363 putLogDebug(100111, formatter.str(), __FILE__, __LINE__ );
3365 /*------DEBUG LOG END------*/
3369 //! called from after sorryserver connect
3370 //! @param[in] upstream thread id
3371 //! @param[out] send buffer reference.
3372 //! @param[out] send length
3373 //! @return session use EVENT mode.
3374 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_connect(
3375 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
3377 /*-------- DEBUG LOG --------*/
3378 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3380 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3381 "handle_sorryserver_connect(const boost::thread::id thread_id, "
3382 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
3384 formatter % thread_id;
3385 putLogDebug(100112, formatter.str(), __FILE__, __LINE__ );
3387 /*------DEBUG LOG END------*/
3388 EVENT_TAG status = FINALIZE;
3390 size_t header_offset = 0;
3391 size_t header_offset_len = 0;
3392 size_t url_offset = 0;
3393 size_t url_offset_len = 0;
3394 size_t send_buffer_remian_size = 0;
3395 size_t copy_size = 0;
3396 const int send_buffer_end_size = sendbuffer.max_size();
3397 const std::string http_header = "";
3398 const std::string str_forword_for = "X-Forwarded-For";
3399 thread_data_ptr session_data;
3400 session_thread_data_map_it session_thread_it;
3401 recive_data_map_it recive_data_it;
3406 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
3409 session_thread_it = session_thread_data_map.find(thread_id);
3410 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3412 boost::format formatter("Invalid thread id. thread id : %d.");
3413 formatter % boost::this_thread::get_id();
3414 putLogError(100063, formatter.str(), __FILE__, __LINE__ );
3418 session_data = session_thread_it->second;
3422 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
3423 if (unlikely(recive_data_it
3424 == session_data->recive_data_map.end()))
3426 boost::format formatter("Invalid endpoint. thread id : %d.");
3427 formatter % boost::this_thread::get_id();
3428 putLogError(100064, formatter.str(), __FILE__, __LINE__ );
3432 //recive_buffer pointer check
3433 recive_data& recv_data = recive_data_it->second;
3434 if (unlikely(recv_data.recive_buffer == NULL))
3436 boost::format formatter("Invalid pointer. thread id : %d.");
3437 formatter % boost::this_thread::get_id();
3438 putLogError(100065, formatter.str(), __FILE__, __LINE__ );
3443 send_status_it it = recv_data.send_status_list.begin();
3444 send_status_it it_end = recv_data.send_status_list.end();
3446 it = find_if(it, it_end, data_send_possible());
3447 if (unlikely(it == it_end))
3449 boost::format formatter("Sending possible data is not existed. thread id : %d.");
3450 formatter % boost::this_thread::get_id();
3451 putLogError(100066, formatter.str(), __FILE__, __LINE__ );
3455 //send buffer rest size initialization
3456 send_buffer_remian_size = send_buffer_end_size;
3458 //edit_division flag on
3459 if (it->edit_division == EDIT_DIVISION_EDIT)
3461 //edit list is empty
3462 if (it->edit_data_list.empty())
3466 edata.data_size = 0;
3467 edata.insert_posission = 0;
3468 edata.replace_size = 0;
3470 if (strlen(sorry_uri.data()) > 0)
3472 ret = find_uri(recv_data.recive_buffer + it->send_offset, it->send_possible_size, url_offset,
3474 /*-------- DEBUG LOG --------*/
3475 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3477 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3478 "handle_sorryserver_connect() : call find_uri : "
3479 "return_value = %d. thread id : %d.");
3480 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
3481 putLogDebug(100113, formatter.str(), __FILE__, __LINE__ );
3483 /*------DEBUG LOG END------*/
3484 //search http header result is OK
3487 //edit sorry_uri, put it to edata.data
3488 edata.data = sorry_uri.data();
3489 //save new uri offset
3490 edata.insert_posission = url_offset;
3491 //save new uri length
3492 edata.data_size = edata.data.size();
3493 //save old uri length
3494 edata.replace_size = url_offset_len;
3495 //add to edit_data_list
3496 it->edit_data_list.push_back(edata);
3500 if (forwarded_for == FORWARDED_FOR_ON)
3502 //search X-Forwarded-For header
3503 ret = find_http_header(recv_data.recive_buffer + it->send_offset, it->send_possible_size,
3504 str_forword_for.c_str(), header_offset, header_offset_len);
3505 /*-------- DEBUG LOG --------*/
3506 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3508 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3509 "handle_sorryserver_connect() : call find_http_header : "
3510 "return_value = %d. thread id : %d.");
3511 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
3512 putLogDebug(100114, formatter.str(), __FILE__, __LINE__ );
3514 /*------DEBUG LOG END------*/
3516 //search http header result is OK
3519 //edit X-Forwarded-For header, put it to edata.data
3520 edata.data.assign(recv_data.recive_buffer + it->send_offset + header_offset, header_offset_len);
3522 edata.data += session_data->client_endpoint_tcp.address().to_string();
3523 //save new X-Forwarded-For header offset
3524 edata.insert_posission = header_offset;
3525 //save new X-Forwarded-For header length
3526 edata.data_size = edata.data.size();
3527 //save old X-Forwarded-For header length
3528 edata.replace_size = header_offset_len;
3530 //search http header result is NG
3533 //search whole http header, get whole http header's offset and length
3534 ret = find_http_header(recv_data.recive_buffer + it->send_offset, it->send_possible_size, "",
3535 header_offset, header_offset_len);
3536 /*-------- DEBUG LOG --------*/
3537 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3539 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3540 "handle_sorryserver_connect() : call find_http_header : "
3541 "return_value = %d. thread id : %d.");
3542 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
3543 putLogDebug(100115, formatter.str(), __FILE__, __LINE__ );
3545 /*------DEBUG LOG END------*/
3548 boost::format formatter("find_http_header() function failure. thread id : %d.");
3549 formatter % boost::this_thread::get_id();
3550 putLogError(100067, formatter.str(), __FILE__, __LINE__ );
3551 /*-------- DEBUG LOG --------*/
3552 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3554 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3555 "handle_sorryserver_connect(const boost::thread::id thread_id, "
3556 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
3557 "size_t& datalen) : return_value = %d. thread id : %d.");
3558 formatter % FINALIZE % boost::this_thread::get_id();
3559 putLogDebug(100116, formatter.str(), __FILE__, __LINE__ );
3561 /*------DEBUG LOG END------*/
3564 //create X-Forwarded-For header, set it to edata.data
3565 edata.data = str_forword_for;
3567 edata.data += session_data->client_endpoint_tcp.address().to_string();
3568 edata.data += "\r\n";
3569 //save new X-Forwarded-For header offset
3570 edata.insert_posission = header_offset;
3571 //save new X-Forwarded-For header length
3572 edata.data_size = edata.data.size();
3573 //save old X-Forwarded-For header length
3574 edata.replace_size = 0;
3577 //add to edit_data_list
3578 it->edit_data_list.push_back(edata);
3582 /*-------- DEBUG LOG --------*/
3583 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3585 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3586 "handle_sorryserver_connect() : Copy data loop start. thread id : %d.");
3587 formatter % boost::this_thread::get_id();
3588 putLogDebug(100117, formatter.str(), __FILE__, __LINE__ );
3590 /*------DEBUG LOG END------*/
3593 //edit_data_list is empty
3594 if (it->edit_data_list.empty())
3596 //set edit_division flag off
3597 it->edit_division = EDIT_DIVISION_NO_EDIT;
3599 if (send_buffer_remian_size > 0 && it->send_possible_size > 0)
3601 //send_buffer_remian_size is larger
3602 if (send_buffer_remian_size > it->send_possible_size)
3604 //copy data from recive_buffer to sendbuffer by sending_possible size
3605 copy_size = it->send_possible_size;
3606 /*-------- DEBUG LOG --------*/
3607 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3609 std::string datadump;
3610 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
3611 copy_size, datadump);
3612 boost::format formatter(
3613 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3614 "handle_sorryserver_connect() : before memcpy (data dump) : "
3615 "data begin = %d, data_size = %d, data = %s");
3616 formatter % (it->send_offset + it->send_end_size)
3617 % copy_size % datadump;
3618 putLogDebug(100118, formatter.str(), __FILE__, __LINE__ );
3620 /*------DEBUG LOG END------*/
3621 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3622 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
3623 /*-------- DEBUG LOG --------*/
3624 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3626 std::string datadump;
3627 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3628 copy_size, datadump);
3629 boost::format formatter(
3630 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3631 "handle_sorryserver_connect() : after memcpy (data dump) : "
3632 "data begin = %d, data_size = %d, data = %s");
3633 formatter % (send_buffer_end_size - send_buffer_remian_size)
3634 % copy_size % datadump;
3635 putLogDebug(100119, formatter.str(), __FILE__, __LINE__ );
3637 /*------DEBUG LOG END------*/
3638 it->send_end_size += copy_size;
3639 it->send_possible_size = 0;
3640 send_buffer_remian_size -= copy_size;
3642 //send_possible_size is larger
3645 copy_size = send_buffer_remian_size;
3646 /*-------- DEBUG LOG --------*/
3647 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3649 std::string datadump;
3650 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
3651 copy_size, datadump);
3652 boost::format formatter(
3653 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3654 "handle_sorryserver_connect() : before memcpy (data dump) : "
3655 "data begin = %d, data_size = %d, data = %s");
3656 formatter % (it->send_offset + it->send_end_size)
3657 % copy_size % datadump;
3658 putLogDebug(100120, formatter.str(), __FILE__, __LINE__ );
3660 /*------DEBUG LOG END------*/
3661 //copy data from recive_buffer to sendbuffer by send buffer rest size
3662 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3663 recv_data.recive_buffer + it->send_offset + it->send_end_size,
3665 /*-------- DEBUG LOG --------*/
3666 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3668 std::string datadump;
3669 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3670 copy_size, datadump);
3671 boost::format formatter(
3672 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3673 "handle_sorryserver_connect() : after memcpy (data dump) : "
3674 "data begin = %d, data_size = %d, data = %s");
3675 formatter % (send_buffer_end_size - send_buffer_remian_size)
3676 % copy_size % datadump;
3677 putLogDebug(100121, formatter.str(), __FILE__, __LINE__ );
3679 /*------DEBUG LOG END------*/
3680 it->send_end_size += copy_size;
3681 it->send_possible_size -= copy_size;
3682 send_buffer_remian_size = 0;
3688 //edit_data_list is not empty
3691 //search item which insert_posission is mininum
3692 std::list<edit_data>::iterator edit_min = std::min_element(it->edit_data_list.begin(),
3693 it->edit_data_list.end());
3694 //send_buffer_remian_size is larger than data that before X-Forwarded-For/uri
3695 if (send_buffer_remian_size >= edit_min->insert_posission - it->send_end_size)
3697 //copy data before X-Forwarded-For/url
3698 copy_size = edit_min->insert_posission - it->send_end_size;
3699 /*-------- DEBUG LOG --------*/
3700 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3702 std::string datadump;
3703 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
3704 copy_size, datadump);
3706 boost::format formatter(
3707 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3708 "handle_sorryserver_connect() : before memcpy (data dump) : "
3709 "data begin = %d, data_size = %d, data = %s");
3710 formatter % (it->send_offset + it->send_end_size)
3711 % copy_size % datadump;
3712 putLogDebug(100122, formatter.str(), __FILE__, __LINE__ );
3714 /*------DEBUG LOG END------*/
3715 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3716 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
3717 /*-------- DEBUG LOG --------*/
3718 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3720 std::string datadump;
3721 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3722 copy_size, datadump);
3723 boost::format formatter(
3724 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3725 "handle_sorryserver_connect() : after memcpy (data dump) : "
3726 "data begin = %d, data_size = %d, data = %s");
3727 formatter % (send_buffer_end_size - send_buffer_remian_size)
3728 % copy_size % datadump;
3729 putLogDebug(100123, formatter.str(), __FILE__, __LINE__ );
3731 /*------DEBUG LOG END------*/
3732 it->send_end_size += copy_size;
3733 it->send_possible_size -= copy_size;
3734 send_buffer_remian_size -= copy_size;
3736 //there is remain buffer for copy X-Forwarded-For/url
3737 if (send_buffer_remian_size >= edit_min->data_size)
3739 /*-------- DEBUG LOG --------*/
3740 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3742 std::string datadump;
3743 dump_memory(edit_min->data.c_str(),
3744 edit_min->data_size, datadump);
3745 boost::format formatter(
3746 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3747 "handle_sorryserver_connect() : before memcpy (data dump) : "
3748 "data begin = 0, data_size = %d, data = %s");
3749 formatter % edit_min->data_size % datadump;
3750 putLogDebug(100124, formatter.str(), __FILE__, __LINE__ );
3752 /*------DEBUG LOG END------*/
3753 //copy X-Forwarded-For/uri
3754 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3755 edit_min->data.c_str(), edit_min->data_size);
3756 /*-------- DEBUG LOG --------*/
3757 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3759 std::string datadump;
3760 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3761 edit_min->data_size, datadump);
3763 boost::format formatter(
3764 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3765 "handle_sorryserver_connect() : after memcpy (data dump) : "
3766 "data begin = %d, data_size = %d, data = %s");
3767 formatter % (send_buffer_end_size - send_buffer_remian_size)
3768 % edit_min->data_size % datadump;
3769 putLogDebug(100125, formatter.str(), __FILE__, __LINE__ );
3771 /*------DEBUG LOG END------*/
3772 it->send_end_size += edit_min->replace_size;
3773 it->send_possible_size -= edit_min->replace_size;
3774 send_buffer_remian_size -= edit_min->data_size;
3775 it->edit_data_list.erase(edit_min);
3783 //data that before X-Forwarded-For/uri is larger than send_buffer_remian_size
3786 copy_size = send_buffer_remian_size;
3787 /*-------- DEBUG LOG --------*/
3788 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3790 std::string datadump;
3791 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3792 copy_size, datadump);
3794 boost::format formatter(
3795 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3796 "handle_sorryserver_connect() : before memcpy (data dump) : "
3797 "data begin = %d, data_size = %d, data = %s");
3798 formatter % (it->send_offset + it->send_end_size)
3799 % copy_size % datadump;
3800 putLogDebug(100126, formatter.str(), __FILE__, __LINE__ );
3802 /*------DEBUG LOG END------*/
3803 //copy data as large as possible
3804 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3805 recv_data.recive_buffer + it->send_offset + it->send_end_size, send_buffer_remian_size);
3806 /*-------- DEBUG LOG --------*/
3807 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3809 std::string datadump;
3810 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3811 copy_size, datadump);
3813 boost::format formatter(
3814 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3815 "handle_sorryserver_connect() : after memcpy (data dump) : "
3816 "data begin = %d, data_size = %d, data = %s");
3817 formatter % (send_buffer_end_size - send_buffer_remian_size)
3818 % copy_size % datadump;
3819 putLogDebug(100127, formatter.str(), __FILE__, __LINE__ );
3821 /*------DEBUG LOG END------*/
3822 it->send_end_size += copy_size;
3823 it->send_possible_size -= copy_size;
3824 send_buffer_remian_size -= copy_size;
3829 /*-------- DEBUG LOG --------*/
3830 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3832 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3833 "handle_sorryserver_connect() : Copy data loop end. thread id : %d.");
3834 formatter % boost::this_thread::get_id();
3835 putLogDebug(100128, formatter.str(), __FILE__, __LINE__ );
3837 /*------DEBUG LOG END------*/
3839 //edit_division flag is off
3842 //copy data as large as possible
3843 //send_possible_size is larger
3844 if (send_buffer_remian_size >= it->send_possible_size)
3846 copy_size = it->send_possible_size;
3847 /*-------- DEBUG LOG --------*/
3848 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3850 std::string datadump;
3851 dump_memory(recv_data.recive_buffer+ it->send_offset, copy_size, datadump);
3853 boost::format formatter(
3854 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3855 "handle_sorryserver_connect() : before memcpy (data dump) : "
3856 "data begin = %d, data_size = %d, data = %s");
3857 formatter % it->send_offset
3858 % copy_size % datadump;
3859 putLogDebug(100129, formatter.str(), __FILE__, __LINE__ );
3861 /*------DEBUG LOG END------*/
3862 //copy data by send_possible size
3863 memcpy(sendbuffer.data(), recv_data.recive_buffer
3864 + it->send_offset, copy_size);
3865 /*-------- DEBUG LOG --------*/
3866 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3868 std::string datadump;
3869 dump_memory(sendbuffer.data(), copy_size, datadump);
3871 boost::format formatter(
3872 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3873 "handle_sorryserver_connect() : after memcpy (data dump) : "
3874 "data begin = 0, data_size = %d, data = %s");
3875 formatter % copy_size % datadump;
3876 putLogDebug(100130, formatter.str(), __FILE__, __LINE__ );
3878 /*------DEBUG LOG END------*/
3879 it->send_end_size = it->send_possible_size;
3880 it->send_possible_size = 0;
3881 send_buffer_remian_size -= copy_size;
3883 //buffer rest size is larger
3886 /*-------- DEBUG LOG --------*/
3887 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3889 std::string datadump;
3890 dump_memory(recv_data.recive_buffer+ it->send_offset, send_buffer_remian_size, datadump);
3892 boost::format formatter(
3893 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3894 "handle_sorryserver_connect() : before memcpy (data dump) : "
3895 "data begin = %d, data_size = %d, data = %s");
3896 formatter % it->send_offset
3897 % send_buffer_remian_size % datadump;
3898 putLogDebug(100131, formatter.str(), __FILE__, __LINE__ );
3900 /*------DEBUG LOG END------*/
3901 //copy data by buffer rest size
3902 memcpy(sendbuffer.data(), recv_data.recive_buffer
3903 + it->send_offset, send_buffer_remian_size);
3904 /*-------- DEBUG LOG --------*/
3905 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3907 std::string datadump;
3908 dump_memory(sendbuffer.data(), send_buffer_remian_size, datadump);
3910 boost::format formatter(
3911 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3912 "handle_sorryserver_connect() : after memcpy (data dump) : "
3913 "data begin = 0, data_size = %d, data = %s");
3914 formatter % send_buffer_remian_size % datadump;
3915 putLogDebug(100132, formatter.str(), __FILE__, __LINE__ );
3917 /*------DEBUG LOG END------*/
3918 it->send_end_size = send_buffer_remian_size;
3919 it->send_possible_size -= send_buffer_remian_size;
3920 send_buffer_remian_size = 0;
3924 //set copyed data length
3925 datalen = send_buffer_end_size - send_buffer_remian_size;
3927 status = SORRYSERVER_SEND;
3932 /*-------- DEBUG LOG --------*/
3933 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3935 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3936 "handle_sorryserver_connect() : catch exception e = %d. thread id : %d.");
3937 formatter % e % boost::this_thread::get_id();
3938 putLogDebug(100133, formatter.str(), __FILE__, __LINE__ );
3941 /*------DEBUG LOG END------*/
3943 catch (const std::exception& ex)
3945 std::cerr << "protocol_module_sessionless::handle_sorryserver_connect() : exception : error = " << ex.what() << "." << std::endl;
3946 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3947 "handle_sorryserver_connect() : exception : error = %s. thread id : %d.");
3948 formatter % ex.what() % boost::this_thread::get_id();
3949 putLogError(100068, formatter.str(), __FILE__, __LINE__ );
3954 std::cerr << "protocol_module_sessionless::handle_sorryserver_connect() : Unknown exception." << std::endl;
3955 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3956 "handle_sorryserver_connect() : Unknown exception. thread id : %d.");
3957 formatter % boost::this_thread::get_id();
3958 putLogError(100069, formatter.str(), __FILE__, __LINE__ );
3962 /*-------- DEBUG LOG --------*/
3963 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3965 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3966 "handle_sorryserver_connect(const boost::thread::id thread_id, "
3967 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
3968 "size_t& datalen) : return_value = %d. thread id : %d.");
3969 formatter % status % boost::this_thread::get_id();
3970 putLogDebug(100134, formatter.str(), __FILE__, __LINE__ );
3972 /*------DEBUG LOG END------*/
3977 //! called from after sorryserver connection fail
3978 //! @param[in] upstream thread id
3979 //! @param[in] sorryserver endpoint reference.
3980 //! @return session use EVENT mode.
3981 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_connection_fail(
3982 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint)
3984 /*-------- DEBUG LOG --------*/
3985 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3987 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3988 "handle_sorryserver_connection_fail(const boost::thread::id thread_id, "
3989 "const boost::asio::ip::tcp::endpoint & sorry_endpoint) : "
3990 "thread_id = %d, sorry_endpoint = [%s]:%d.");
3991 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port();
3992 putLogDebug(100135, formatter.str(), __FILE__, __LINE__ );
3994 /*------DEBUG LOG END------*/
3996 EVENT_TAG status = FINALIZE;
3997 thread_data_ptr session_data;
3998 session_thread_data_map_it session_thread_it;
4002 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
4004 session_thread_it = session_thread_data_map.find(thread_id);
4005 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
4007 boost::format formatter("Invalid thread id. thread id : %d.");
4008 formatter % boost::this_thread::get_id();
4009 putLogError(100070, formatter.str(), __FILE__, __LINE__ );
4013 session_data = session_thread_it->second;
4016 session_data->end_flag = END_FLAG_ON;
4017 /*-------- DEBUG LOG --------*/
4018 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4020 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4021 "handle_sorryserver_connection_fail() : END_FLAG_ON. thread id : %d.");
4022 formatter % boost::this_thread::get_id();
4023 putLogDebug(100136, formatter.str(), __FILE__, __LINE__ );
4025 /*------DEBUG LOG END------*/
4027 status = CLIENT_DISCONNECT;
4031 /*-------- DEBUG LOG --------*/
4032 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4034 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4035 "handle_sorryserver_connection_fail() : catch exception e = %d. thread id : %d.");
4036 formatter % e % boost::this_thread::get_id();
4037 putLogDebug(100137, formatter.str(), __FILE__, __LINE__ );
4040 /*------DEBUG LOG END------*/
4042 catch (const std::exception& ex)
4044 std::cerr << "protocol_module_sessionless::handle_sorryserver_connection_fail() : exception : error=" << ex.what() << "." << std::endl;
4045 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4046 "handle_sorryserver_connection_fail() : exception : error = %s. thread id : %d.");
4047 formatter % ex.what() % boost::this_thread::get_id();
4048 putLogError(100071, formatter.str(), __FILE__, __LINE__ );
4053 std::cerr << "protocol_module_sessionless::handle_sorryserver_connection_fail() : Unknown exception." << std::endl;
4054 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4055 "handle_sorryserver_connection_fail() : Unknown exception. thread id : %d.");
4056 formatter % boost::this_thread::get_id();
4057 putLogError(100072, formatter.str(), __FILE__, __LINE__ );
4061 /*-------- DEBUG LOG --------*/
4062 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4066 "out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4067 "handle_sorryserver_connection_fail( const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint) : return_value = %d."
4068 " thread id : %d.");
4069 formatter % status % boost::this_thread::get_id();
4070 putLogDebug(100138, formatter.str(), __FILE__, __LINE__ );
4072 /*------DEBUG LOG END------*/
4076 //! called from after sorryserver send
4077 //! @param[in] upstream thread id
4078 //! @return session use EVENT mode.
4079 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_send(
4080 const boost::thread::id thread_id)
4082 /*-------- DEBUG LOG --------*/
4083 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4085 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4086 "handle_sorryserver_send(const boost::thread::id thread_id) : "
4088 formatter % thread_id;
4089 putLogDebug(100139, formatter.str(), __FILE__, __LINE__ );
4091 /*------DEBUG LOG END------*/
4092 EVENT_TAG status = FINALIZE;
4093 thread_data_ptr session_data;
4094 session_thread_data_map_it session_thread_it;
4095 recive_data_map_it recive_data_it;
4100 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
4103 session_thread_it = session_thread_data_map.find(thread_id);
4104 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
4106 boost::format formatter("Invalid thread id. thread id : %d.");
4107 formatter % boost::this_thread::get_id();
4108 putLogError(100073, formatter.str(), __FILE__, __LINE__ );
4112 session_data = session_thread_it->second;
4116 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
4117 if (unlikely(recive_data_it
4118 == session_data->recive_data_map.end()))
4120 boost::format formatter("Invalid endpoint. thread id : %d.");
4121 formatter % boost::this_thread::get_id();
4122 putLogError(100074, formatter.str(), __FILE__, __LINE__ );
4126 recive_data& recv_data = recive_data_it->second;
4128 send_status_it it = recv_data.send_status_list.begin();
4129 send_status_it it_end = recv_data.send_status_list.end();
4131 it = std::adjacent_find(it, it_end, data_send_list_incorrect());
4132 if (unlikely(it != it_end))
4134 boost::format formatter("Sending possible data is invalid. thread id : %d.");
4135 formatter % boost::this_thread::get_id();
4136 putLogError(100075, formatter.str(), __FILE__, __LINE__ );
4141 it = recv_data.send_status_list.begin();
4142 it = find_if(it, it_end, data_send_ok());
4143 if (unlikely(it == it_end))
4145 boost::format formatter("Sending possible data is not existed. thread id : %d.");
4146 formatter % boost::this_thread::get_id();
4147 putLogError(100076, formatter.str(), __FILE__, __LINE__ );
4151 //sending possible data is exist
4152 if (it->send_possible_size > 0)
4154 //status remain SEND_OK
4155 it->status = SEND_OK;
4157 it->send_offset += it->send_end_size;
4159 //insert_posission recalc
4160 for (std::list<edit_data>::iterator list_it = it->edit_data_list.begin(); list_it
4161 != it->edit_data_list.end(); ++list_it)
4163 list_it->insert_posission -= it->send_end_size;
4166 //send_end_size recalc
4167 it->send_end_size = 0;
4169 //sending possible data is not exist
4172 //can recive from clent continue
4173 if (it->send_rest_size > 0)
4175 //change status from SEND_OK to SEND_CONTINUE
4176 it->status = SEND_CONTINUE;
4178 //can not recive from clent continue
4181 //change status from SEND_OK to SEND_END
4182 it->status = SEND_END;
4186 it = recv_data.send_status_list.begin();
4187 it = find_if(it, it_end, data_send_ok());
4188 //send_ok item is exist
4191 status = SORRYSERVER_CONNECT;
4193 //send_ok item is exist
4196 status = CLIENT_RECV;
4202 /*-------- DEBUG LOG --------*/
4203 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4205 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4206 "handle_sorryserver_send() : catch exception e = %d. thread id : %d.");
4207 formatter % e % boost::this_thread::get_id();
4208 putLogDebug(100140, formatter.str(), __FILE__, __LINE__ );
4211 /*------DEBUG LOG END------*/
4213 catch (const std::exception& ex)
4215 std::cerr << "protocol_module_sessionless::handle_sorryserver_send() : exception : error = " << ex.what() << "." << std::endl;
4216 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4217 "handle_sorryserver_send() : exception : error = %s. thread id : %d.");
4218 formatter % ex.what() % boost::this_thread::get_id();
4219 putLogError(100077, formatter.str(), __FILE__, __LINE__ );
4225 std::cerr << "protocol_module_sessionless::handle_sorryserver_send() : Unknown exception." << std::endl;
4226 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4227 "handle_sorryserver_send() : Unknown exception. thread id : %d.");
4228 formatter % boost::this_thread::get_id();
4229 putLogError(100078, formatter.str(), __FILE__, __LINE__ );
4233 /*-------- DEBUG LOG --------*/
4234 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4236 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4237 "handle_sorryserver_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
4238 formatter % status % boost::this_thread::get_id();
4239 putLogDebug(100141, formatter.str(), __FILE__, __LINE__ );
4241 /*------DEBUG LOG END------*/
4246 //! called from after realserver recive.for UDP
4247 //! @param[in] downstream thread id
4248 //! @param[in] realserver UDP endpoint reference
4249 //! @param[in] recive from realserver buffer reference
4250 //! @param[in] recv data length
4251 //! @return session use EVENT mode.
4252 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_recv(
4253 const boost::thread::id thread_id, const boost::asio::ip::udp::endpoint& rs_endpoint, const boost::array<char,
4254 MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
4256 /*-------- DEBUG LOG --------*/
4257 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4259 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4260 "handle_realserver_recv(const boost::thread::id thread_id, "
4261 "const boost::asio::ip::udp::endpoint& rs_endpoint, "
4262 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4263 "const size_t recvlen) : "
4264 "return_value = %d. thread id : %d.");
4265 formatter % STOP % boost::this_thread::get_id();
4266 putLogDebug(100142, formatter.str(), __FILE__, __LINE__ );
4268 /*------DEBUG LOG END------*/
4272 //! called from after realserver recvive for TCP/IP
4273 //! @param[in] downstream thread id
4274 //! @param[in] realserver TCP/IP endpoint reference
4275 //! @param[in] realserver recive buffer reference.
4276 //! @param[in] recv data length
4277 //! @return session use EVENT mode.
4278 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_recv(
4279 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint& rs_endpoint, const boost::array<char,
4280 MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
4282 /*-------- DEBUG LOG --------*/
4283 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4285 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
4287 dump_memory(recvbuffer.data(), buffer_size, buffer);
4288 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4289 "handle_realserver_recv(const boost::thread::id thread_id, "
4290 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
4291 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4292 "const size_t recvlen) : thread_id = %d, rs_endpoint = [%s]:%d, recvbuffer = %s, recvlen = %d.");
4293 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port()
4295 putLogDebug(100143, formatter.str(), __FILE__, __LINE__ );
4297 /*------DEBUG LOG END------*/
4299 EVENT_TAG status = FINALIZE;
4300 size_t data_remain_start = 0;
4301 size_t data_remain_size = 0;
4302 size_t request_data_remain_size = 0;
4303 size_t header_offset = 0;
4304 size_t header_offset_len = 0;
4305 size_t content_length_header_offset = 0;
4306 size_t content_length_header_len = 0;
4307 size_t content_len_value = 0;
4309 size_t buffer_size = 0;
4310 const size_t cr_lf_len = strlen("\r\n\r\n");
4311 thread_data_ptr session_data;
4312 char* buffer1 = NULL;
4313 char* buffer2 = NULL;
4314 std::string str_value;
4315 const std::string http_header = "";
4316 const std::string content_header = "Content-Length";
4318 CHECK_RESULT_TAG check_result;
4319 session_thread_data_map_it session_thread_it;
4320 recive_data_map_it recive_data_it;
4323 if (recvlen > recvbuffer.size())
4325 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : Data size bigger than buffer size." << std::endl;
4326 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
4327 formatter % boost::this_thread::get_id();
4328 putLogError(100079, formatter.str(), __FILE__, __LINE__ );
4329 /*-------- DEBUG LOG --------*/
4330 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4332 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4333 "handle_realserver_recv(const boost::thread::id thread_id, "
4334 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
4335 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4336 "const size_t recvlen) : return_value = %d. thread id : %d.");
4337 formatter % FINALIZE % boost::this_thread::get_id();
4338 putLogDebug(100144, formatter.str(), __FILE__, __LINE__ );
4340 /*------DEBUG LOG END------*/
4347 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
4349 session_thread_it = session_thread_data_map.find(thread_id);
4350 if (unlikely(session_thread_it == session_thread_data_map.end()
4351 ||session_thread_it->second == NULL))
4353 boost::format formatter("Invalid thread id. thread id : %d.");
4354 formatter % boost::this_thread::get_id();
4355 putLogError(100080, formatter.str(), __FILE__, __LINE__ );
4359 session_data = session_thread_it->second;
4362 recive_data_it = session_data->recive_data_map.find(rs_endpoint);
4363 if (recive_data_it == session_data->recive_data_map.end())
4365 recive_data recv_data;
4366 session_data->recive_data_map[rs_endpoint] = recv_data;
4369 session_data->target_endpoint = rs_endpoint;
4371 recive_data& recv_data = session_data->recive_data_map[rs_endpoint];
4373 send_status_it it = recv_data.send_status_list.begin();
4374 send_status_it it_end = recv_data.send_status_list.end();
4377 it = std::find_if(it, it_end, data_send_ok());
4378 if (unlikely(it != it_end))
4380 boost::format formatter("Sending data is not correct. thread id : %d.");
4381 formatter % boost::this_thread::get_id();
4382 putLogError(100081, formatter.str(), __FILE__, __LINE__ );
4387 it = recv_data.send_status_list.begin();
4388 it = std::adjacent_find(it, it_end, data_send_repeated());
4389 if (unlikely(it != it_end))
4391 boost::format formatter("Sending data is not correct. thread id : %d.");
4392 formatter % boost::this_thread::get_id();
4393 putLogError(100082, formatter.str(), __FILE__, __LINE__ );
4397 /*-------- DEBUG LOG --------*/
4398 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4400 std::string datadump;
4401 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
4402 "send_rest_size = %d, send_possible_size = %d, "
4403 "send_offset = %d, unsend_size = %d, edit_division = %d.");
4405 for (it = recv_data.send_status_list.begin();
4406 it != recv_data.send_status_list.end();
4409 formatter % i % it->status % it->send_end_size
4410 % it->send_rest_size % it->send_possible_size
4411 % it->send_offset % it->unsend_size % it->edit_division;
4412 datadump += formatter.str();
4415 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4416 "handle_realserver_recv() : send status list dump : send status list size = %d.%s");
4418 formatter % recv_data.send_status_list.size() % datadump;
4419 putLogDebug(100145, formatter.str(), __FILE__, __LINE__ );
4421 /*------DEBUG LOG END------*/
4422 it = recv_data.send_status_list.begin();
4423 //get original status info
4424 while (it != it_end)
4426 //item status is SEND_END
4427 if (it->status == SEND_END)
4430 recv_data.send_status_list.erase(it++);
4433 //item status is SEND_CONTINUE
4434 else if (it->status == SEND_CONTINUE)
4436 it->send_offset += it->send_end_size;
4437 data_remain_start = it->send_offset;
4440 //item status is SEND_NG
4443 data_remain_start = it->send_offset;
4444 data_remain_size = it->unsend_size;
4450 /*-------- DEBUG LOG --------*/
4451 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4453 std::string datadump;
4454 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
4455 "send_rest_size = %d, send_possible_size = %d, "
4456 "send_offset = %d, unsend_size = %d, edit_division = %d.");
4458 for (it = recv_data.send_status_list.begin();
4459 it != recv_data.send_status_list.end();
4462 formatter % i % it->status % it->send_end_size
4463 % it->send_rest_size % it->send_possible_size
4464 % it->send_offset % it->unsend_size % it->edit_division;
4465 datadump += formatter.str();
4468 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4469 "handle_realserver_recv() : send status list dump : send status list size = %d.%s");
4471 formatter % recv_data.send_status_list.size() % datadump;
4472 putLogDebug(100146, formatter.str(), __FILE__, __LINE__ );
4474 /*------DEBUG LOG END------*/
4475 //recive buffer process
4476 //buffer rest size < request size
4477 if (recv_data.recive_buffer_rest_size < recvlen)
4479 //buffer max size < remain size + request size
4480 //buffer is need reallocate
4481 if (recv_data.recive_buffer_max_size < data_remain_size + recvlen)
4483 //the buffer's size that will be allocated is exceed the upper limit value
4484 if (MAX_SESSIONLESS_MODULE_BUFFER_SIZE < data_remain_size + recvlen)
4486 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : the buffer's size that will be allacted is exceed the upper limit value." << std::endl;
4487 boost::format formatter("The buffer's size that will be allocated is exceed the upper limit value. thread id : %d.");
4488 formatter % boost::this_thread::get_id();
4489 putLogError(100083, formatter.str(), __FILE__, __LINE__ );
4491 /*-------- DEBUG LOG --------*/
4492 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4494 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4495 "handle_realserver_recv(const boost::thread::id thread_id, "
4496 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
4497 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4498 "const size_t recvlen) : return_value = %d. thread id : %d.");
4499 formatter % FINALIZE % boost::this_thread::get_id();
4500 putLogDebug(100147, formatter.str(), __FILE__, __LINE__ );
4502 /*------DEBUG LOG END------*/
4506 //recive_buffer1's memory allocate and initialization
4507 buffer_size = (data_remain_size + recvlen) > MAX_BUFFER_SIZE ? (data_remain_size + recvlen) : MAX_BUFFER_SIZE;
4508 buffer1 = new char[buffer_size];
4509 /*-------- DEBUG LOG --------*/
4510 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4512 boost::format formatter("new : address = &(%d), size = %lu.");
4513 formatter % static_cast<void*>(buffer1) % buffer_size;
4514 putLogDebug(100148, formatter.str(), __FILE__, __LINE__ );
4516 /*-------- DEBUG LOG --------*/
4517 memset(buffer1, 0, buffer_size);
4518 //recive_buffer2's memory allocate and initialization
4519 buffer2 = new char[buffer_size];
4520 /*-------- DEBUG LOG --------*/
4521 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4523 boost::format formatter("new : address = &(%d), size = %lu.");
4524 formatter % static_cast<void*>(buffer2) % buffer_size;
4525 putLogDebug(100149, formatter.str(), __FILE__, __LINE__ );
4527 /*-------- DEBUG LOG END--------*/
4528 memset(buffer2, 0, buffer_size);
4530 /*-------- DEBUG LOG --------*/
4531 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4533 std::string datadump;
4534 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
4536 boost::format formatter(
4537 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4538 "handle_realserver_recv() : before memcpy (data dump) : "
4539 "data begin = %d, data_size = %d, data = %s");
4540 formatter % data_remain_start % data_remain_size % datadump;
4541 putLogDebug(100150, formatter.str(), __FILE__, __LINE__ );
4543 /*------DEBUG LOG END------*/
4544 //copy data from old buffer to new buffer
4545 memcpy(buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
4546 /*-------- DEBUG LOG --------*/
4547 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4549 std::string datadump;
4550 dump_memory(buffer1, data_remain_size, datadump);
4552 boost::format formatter(
4553 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4554 "handle_realserver_recv() : after memcpy (data dump) : "
4555 "data begin = 0, data_size = %d, data = %s");
4556 formatter % data_remain_size % datadump;
4557 putLogDebug(100151, formatter.str(), __FILE__, __LINE__ );
4559 /*------DEBUG LOG END------*/
4561 /*-------- DEBUG LOG --------*/
4562 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4564 std::string datadump;
4565 dump_memory(recvbuffer.data(), recvlen, datadump);
4566 boost::format formatter(
4567 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4568 "handle_realserver_recv() : before memcpy (data dump) : "
4569 "data begin = 0, data_size = %d, data = %s");
4570 formatter % recvlen % datadump;
4571 putLogDebug(100152, formatter.str(), __FILE__, __LINE__ );
4573 /*------DEBUG LOG END------*/
4574 memcpy(buffer1 + data_remain_size, recvbuffer.data(), recvlen);
4575 /*-------- DEBUG LOG --------*/
4576 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4578 std::string datadump;
4579 dump_memory(buffer1 + data_remain_size, recvlen, datadump);
4580 boost::format formatter(
4581 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4582 "handle_realserver_recv() : after memcpy (data dump) : "
4583 "data begin = %d, data_size = %d, data = %s");
4584 formatter % data_remain_size % recvlen % datadump;
4585 putLogDebug(100153, formatter.str(), __FILE__, __LINE__ );
4587 /*------DEBUG LOG END------*/
4588 //free old buffer1 and old buffer2
4589 if (recv_data.recive_buffer1 != NULL)
4591 /*-------- DEBUG LOG --------*/
4592 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4594 boost::format formatter("delete : address = &(%d).");
4595 formatter % static_cast<void*>(recv_data.recive_buffer1);
4596 putLogDebug(100154, formatter.str(), __FILE__,
4599 /*------DEBUG LOG END------*/
4600 delete[] recv_data.recive_buffer1;
4601 recv_data.recive_buffer1 = NULL;
4604 if (recv_data.recive_buffer2 != NULL)
4606 /*-------- DEBUG LOG --------*/
4607 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4609 boost::format formatter("delete : address = &(%d).");
4610 formatter % static_cast<void*>(recv_data.recive_buffer2);
4611 putLogDebug(100155, formatter.str(), __FILE__,
4614 /*------DEBUG LOG END------*/
4615 delete[] recv_data.recive_buffer2;
4616 recv_data.recive_buffer2 = NULL;
4619 //set new buffer pointer
4620 recv_data.recive_buffer1 = buffer1;
4621 recv_data.recive_buffer2 = buffer2;
4622 recv_data.recive_buffer = recv_data.recive_buffer1;
4623 //set new buffer's max size
4624 recv_data.recive_buffer_max_size = buffer_size;
4626 //buffer's max size >= remain data size + requst size
4627 //buffer isn't need reallocate, but switch
4630 //pointer valid check
4631 if (unlikely(recv_data.recive_buffer1 == NULL || recv_data.recive_buffer2 == NULL))
4633 boost::format formatter("Invalid pointer. thread id : %d.");
4634 formatter % boost::this_thread::get_id();
4635 putLogError(100084, formatter.str(), __FILE__, __LINE__ );
4638 //using buffer is buffer1
4639 if (recv_data.recive_buffer == recv_data.recive_buffer1)
4641 //buffer2 initialization
4642 memset(recv_data.recive_buffer2, 0, recv_data.recive_buffer_max_size);
4643 /*-------- DEBUG LOG --------*/
4644 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4646 std::string datadump;
4647 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
4648 boost::format formatter(
4649 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4650 "handle_realserver_recv() : before memcpy (data dump) : "
4651 "data begin = %d, data_size = %d, data = %s");
4652 formatter % data_remain_start % data_remain_size % datadump;
4653 putLogDebug(100156, formatter.str(), __FILE__, __LINE__ );
4655 /*------DEBUG LOG END------*/
4656 //copy data from buffer1 to buffer2
4657 memcpy(recv_data.recive_buffer2, recv_data.recive_buffer + data_remain_start, data_remain_size);
4658 /*-------- DEBUG LOG --------*/
4659 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4661 std::string datadump;
4662 dump_memory(recv_data.recive_buffer2, data_remain_size, datadump);
4663 boost::format formatter(
4664 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4665 "handle_realserver_recv() : after memcpy (data dump) : "
4666 "data begin = 0, data_size = %d, data = %s");
4667 formatter % data_remain_size % datadump;
4668 putLogDebug(100157, formatter.str(), __FILE__, __LINE__ );
4670 /*------DEBUG LOG END------*/
4671 /*-------- DEBUG LOG --------*/
4672 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4674 std::string datadump;
4675 dump_memory(recvbuffer.data(), recvlen, datadump);
4676 boost::format formatter(
4677 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4678 "handle_realserver_recv() : before memcpy (data dump) : "
4679 "data begin = 0, data_size = %d, data = %s");
4680 formatter % data_remain_size % datadump;
4681 putLogDebug(100158, formatter.str(), __FILE__, __LINE__ );
4683 /*------DEBUG LOG END------*/
4684 memcpy(recv_data.recive_buffer2 + data_remain_size, recvbuffer.data(), recvlen);
4685 /*-------- DEBUG LOG --------*/
4686 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4688 std::string datadump;
4689 dump_memory(recv_data.recive_buffer2 + data_remain_size, recvlen, datadump);
4691 boost::format formatter(
4692 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4693 "handle_realserver_recv() : after memcpy (data dump) : "
4694 "data begin = %d, data_size = %d, data = %s");
4695 formatter % data_remain_size % recvlen % datadump;
4696 putLogDebug(100159, formatter.str(), __FILE__, __LINE__ );
4698 /*------DEBUG LOG END------*/
4699 //set buffer2 as using buffer
4700 recv_data.recive_buffer = recv_data.recive_buffer2;
4702 //using buffer is buffer2
4705 //buffer1 initialization
4706 memset(recv_data.recive_buffer1, 0, recv_data.recive_buffer_max_size);
4707 /*-------- DEBUG LOG --------*/
4708 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4710 std::string datadump;
4711 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
4713 boost::format formatter(
4714 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4715 "handle_realserver_recv() : before memcpy (data dump) : "
4716 "data begin = %d, data_size = %d, data = %s");
4717 formatter % data_remain_start % data_remain_size % datadump;
4718 putLogDebug(100160, formatter.str(), __FILE__, __LINE__ );
4720 /*------DEBUG LOG END------*/
4721 //copy data from buffer2 to buffer1
4722 memcpy(recv_data.recive_buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
4723 /*-------- DEBUG LOG --------*/
4724 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4726 std::string datadump;
4727 dump_memory(recv_data.recive_buffer1, data_remain_size, datadump);
4729 boost::format formatter(
4730 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4731 "handle_realserver_recv() : after memcpy (data dump) : "
4732 "data begin = 0, data_size = %d, data = %s");
4733 formatter % data_remain_size % datadump;
4734 putLogDebug(100161, formatter.str(), __FILE__, __LINE__ );
4736 /*------DEBUG LOG END------*/
4737 /*-------- DEBUG LOG --------*/
4738 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4740 std::string datadump;
4741 dump_memory(recvbuffer.data(), recvlen, datadump);
4743 boost::format formatter(
4744 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4745 "handle_realserver_recv() : before memcpy (data dump) : "
4746 "data begin = 0, data_size = %d, data = %s");
4747 formatter % recvlen % datadump;
4748 putLogDebug(100162, formatter.str(), __FILE__, __LINE__ );
4750 /*------DEBUG LOG END------*/
4751 memcpy(recv_data.recive_buffer1 + data_remain_size, recvbuffer.data(), recvlen);
4752 /*-------- DEBUG LOG --------*/
4753 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4755 std::string datadump;
4756 dump_memory(recv_data.recive_buffer1 + data_remain_size, recvlen, datadump);
4758 boost::format formatter(
4759 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4760 "handle_realserver_recv() : after memcpy (data dump) : "
4761 "data begin = %d, data_size = %d, data = %s");
4762 formatter % data_remain_size % recvlen % datadump;
4763 putLogDebug(100163, formatter.str(), __FILE__, __LINE__ );
4765 /*------DEBUG LOG END------*/
4766 //set buffer1 as using buffer
4767 recv_data.recive_buffer = recv_data.recive_buffer1;
4771 //set buffer's rest size
4772 recv_data.recive_buffer_rest_size = recv_data.recive_buffer_max_size - data_remain_size - recvlen;
4774 //remain_size recalc
4775 data_remain_size += recvlen;
4777 send_status_it it_begin = recv_data.send_status_list.begin();
4778 send_status_it it_end = recv_data.send_status_list.end();
4780 for (; it_begin != it_end; ++it_begin)
4782 it_begin->send_offset -= data_remain_start;
4785 //buffer's rest size >= request size
4789 //pointer valid check
4790 if (unlikely(recv_data.recive_buffer == NULL))
4792 boost::format formatter("Invalid pointer. thread id : %d.");
4793 formatter % boost::this_thread::get_id();
4794 putLogError(100085, formatter.str(), __FILE__, __LINE__ );
4797 /*-------- DEBUG LOG --------*/
4798 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4800 std::string datadump;
4801 dump_memory(recvbuffer.data(), recvlen, datadump);
4802 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4803 "handle_realserver_recv() : before memcpy (data dump) : "
4804 "data begin = 0, data_size = %d, data = %s");
4805 formatter % recvlen % datadump;
4806 putLogDebug(100164, formatter.str(), __FILE__, __LINE__ );
4808 /*------DEBUG LOG END------*/
4810 //copy data from parameter to using buffer
4811 memcpy(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
4812 recvbuffer.data(), recvlen);
4813 /*-------- DEBUG LOG --------*/
4814 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4816 std::string datadump;
4817 dump_memory(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
4819 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4820 "handle_realserver_recv() : before memcpy (data dump) : "
4821 "data begin = %d, data_size = %d, data = %s");
4822 formatter % (recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size )
4823 % recvlen % datadump;
4824 putLogDebug(100165, formatter.str(), __FILE__, __LINE__ );
4826 /*------DEBUG LOG END------*/
4827 //buffer's rest size recalc
4828 recv_data.recive_buffer_rest_size -= recvlen;
4829 //remain data size recalc
4830 data_remain_size += recvlen;
4833 it = recv_data.send_status_list.begin();
4834 it_end = recv_data.send_status_list.end();
4835 //request rest size initialization
4836 request_data_remain_size = recvlen;
4837 //original status process
4838 for (; it != it_end; ++it)
4840 //status is SEND_CONTINUE
4841 if (it->status == SEND_CONTINUE)
4843 //send rest size > request size
4844 if (it->send_rest_size > request_data_remain_size)
4846 //send possible size recalc
4847 it->send_possible_size = request_data_remain_size;
4848 //send rest size recalc
4849 it->send_rest_size -= request_data_remain_size;
4850 //send end size recalc
4851 it->send_end_size = 0;
4852 //request size recalc
4853 request_data_remain_size = 0;
4855 //send rest size <= request size
4858 //send possible size recalc
4859 it->send_possible_size = it->send_rest_size;
4860 //send rest size recalc
4861 request_data_remain_size -= it->send_rest_size;
4862 //send end size recalc
4863 it->send_end_size = 0;
4864 //request size recalc
4865 it->send_rest_size = 0;
4867 //change status from SEND_CONTINUE to SEND_OK
4868 it->status = SEND_OK;
4871 else if (it->status == SEND_NG)
4874 check_result = check_status_code(recv_data.recive_buffer + it->send_offset, data_remain_size);
4875 /*-------- DEBUG LOG --------*/
4876 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4878 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4879 "handle_realserver_recv() : call check_http_method : "
4880 "return_value = %d. thread id : %d.");
4881 formatter % check_result % boost::this_thread::get_id();
4882 putLogDebug(100166, formatter.str(), __FILE__, __LINE__ );
4884 /*------DEBUG LOG END------*/
4885 //check http method result is OK
4886 if (check_result == CHECK_OK)
4888 //check http version
4889 check_result = check_http_version(recv_data.recive_buffer + it->send_offset, data_remain_size);
4890 /*-------- DEBUG LOG --------*/
4891 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4893 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4894 "handle_realserver_recv() : call check_http_version : "
4895 "return_value = %d. thread id : %d.");
4896 formatter % check_result % boost::this_thread::get_id();
4897 putLogDebug(100167, formatter.str(), __FILE__, __LINE__ );
4899 /*------DEBUG LOG END------*/
4901 //check method and version result is OK
4902 if (check_result == CHECK_OK)
4904 //search http header
4905 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size, http_header,
4906 header_offset, header_offset_len);
4907 /*-------- DEBUG LOG --------*/
4908 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4910 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4911 "handle_realserver_recv() : call find_http_header : "
4912 "return_value = %d. thread id : %d.");
4913 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
4914 putLogDebug(100168, formatter.str(), __FILE__, __LINE__ );
4916 /*------DEBUG LOG END------*/
4917 //search http header result is OK
4920 //search Content_Length header
4921 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size,
4922 content_header, content_length_header_offset, content_length_header_len);
4923 /*-------- DEBUG LOG --------*/
4924 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4926 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4927 "handle_realserver_recv() : call find_http_header : "
4928 "return_value = %d. thread id : %d.");
4929 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
4930 putLogDebug(100169, formatter.str(), __FILE__, __LINE__ );
4932 /*------DEBUG LOG END------*/
4933 //search Content_Length result is OK
4936 //Get Content_Length header's numeric value
4937 for (pos = 0; recv_data.recive_buffer[it->send_offset + content_length_header_offset + pos] != ':' && pos
4938 < content_length_header_len; ++pos)
4940 if (pos == content_length_header_len)
4942 throw std::string("Content_Length field's value is invalid.");
4947 str_value.assign(recv_data.recive_buffer + it->send_offset + content_length_header_offset + pos,
4948 content_length_header_len - pos);
4950 size_t pos_end = str_value.find_last_of('\r');
4951 if (pos_end != std::string::npos)
4953 str_value = str_value.erase(pos_end);
4956 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos)
4959 str_value = str_value.substr(pos);
4963 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
4965 catch (const boost::bad_lexical_cast& ex)
4967 throw std::string("Content_Length field's value is invalid.");
4969 //send_rest_size recalc
4970 //set whole http header's length + Content_Length's value
4971 it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
4973 //search Content_Length result is NG
4976 //send_rest_size recalc
4977 //set whole http header's length
4978 it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
4981 //search http header result is NG
4984 it->unsend_size += request_data_remain_size;
4985 request_data_remain_size = 0;
4989 //check method and version result is NG
4990 else if (check_result == CHECK_NG)
4992 //send_rest_size recalc
4993 it->send_rest_size = it->unsend_size + request_data_remain_size;
4995 //check method and version result is CHECK_INPOSSIBLE
4998 it->unsend_size += request_data_remain_size;
4999 request_data_remain_size = 0;
5003 //recalc fields value according to send_rest_size and request rest size
5004 if (it->send_rest_size > it->unsend_size + request_data_remain_size)
5006 it->send_possible_size = it->unsend_size+ request_data_remain_size;
5007 it->send_rest_size -= (it->unsend_size + request_data_remain_size);
5008 it->send_end_size = 0;
5009 it->unsend_size = 0;
5010 request_data_remain_size = 0;
5014 it->send_possible_size = it->send_rest_size;
5015 request_data_remain_size = it->unsend_size + request_data_remain_size - it->send_rest_size;
5016 it->send_end_size = 0;
5017 it->unsend_size = 0;
5018 it->send_rest_size = 0;
5021 //change status from SEND_NG to SEND_OK
5022 it->status = SEND_OK;
5024 //no request rest data to process
5025 if (request_data_remain_size <= 0)
5031 /*-------- DEBUG LOG --------*/
5032 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5034 std::string datadump;
5035 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
5036 "send_rest_size = %d, send_possible_size = %d, "
5037 "send_offset = %d, unsend_size = %d, edit_division = %d.");
5039 for (it = recv_data.send_status_list.begin();
5040 it != recv_data.send_status_list.end();
5043 formatter % i % it->status % it->send_end_size
5044 % it->send_rest_size % it->send_possible_size
5045 % it->send_offset % it->unsend_size % it->edit_division;
5046 datadump += formatter.str();
5049 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5050 "handle_realserver_recv() : send status list dump : send status list size = %d.%s");
5052 formatter % recv_data.send_status_list.size() % datadump;
5053 putLogDebug(100170, formatter.str(), __FILE__, __LINE__ );
5055 /*------DEBUG LOG END------*/
5056 //there are still rest data need to process
5057 //new status created and add to status list
5058 while (request_data_remain_size > 0)
5060 //new status created
5061 send_status new_send_state;
5062 new_send_state.edit_division = EDIT_DIVISION_NO_EDIT;
5063 new_send_state.send_end_size = 0;
5064 new_send_state.send_offset = 0;
5065 new_send_state.send_possible_size = 0;
5066 new_send_state.unsend_size = 0;
5067 new_send_state.send_rest_size = 0;
5068 //status initialize to SEND_NG
5069 new_send_state.status = SEND_NG;
5070 //add new status to status_list
5071 recv_data.send_status_list.push_back(new_send_state);
5072 std::list<send_status>::reverse_iterator new_send_it = recv_data.send_status_list.rbegin();
5074 new_send_it->send_offset = recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size
5075 - request_data_remain_size;
5078 check_result = check_status_code(recv_data.recive_buffer + new_send_it->send_offset,
5079 request_data_remain_size);
5080 /*-------- DEBUG LOG --------*/
5081 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5083 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5084 "handle_realserver_recv() : call check_http_method : "
5085 "return_value = %d. thread id : %d.");
5086 formatter % check_result % boost::this_thread::get_id();
5087 putLogDebug(100171, formatter.str(), __FILE__, __LINE__ );
5089 /*------DEBUG LOG END------*/
5090 //check http method result is OK
5091 if (check_result == CHECK_OK)
5093 //check http version
5094 check_result = check_http_version(recv_data.recive_buffer + new_send_it->send_offset,
5095 request_data_remain_size);
5096 /*-------- DEBUG LOG --------*/
5097 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5099 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5100 "handle_realserver_recv() : call check_http_version : "
5101 "return_value = %d. thread id : %d.");
5102 formatter % check_result % boost::this_thread::get_id();
5103 putLogDebug(100172, formatter.str(), __FILE__, __LINE__ );
5105 /*------DEBUG LOG END------*/
5107 //check http method and version result is OK
5108 if (check_result == CHECK_OK)
5110 //search whole http header, get whole http header's offset and length
5111 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset, request_data_remain_size,
5112 http_header, header_offset, header_offset_len);
5113 /*-------- DEBUG LOG --------*/
5114 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5116 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5117 "handle_realserver_recv() : call find_http_header : "
5118 "return_value = %d. thread id : %d.");
5119 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
5120 putLogDebug(100173, formatter.str(), __FILE__, __LINE__ );
5122 /*------DEBUG LOG END------*/
5123 //searched whole http header
5126 //search ContentLength http header, get ContentLength header's offset and length
5127 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset,
5128 request_data_remain_size, content_header, content_length_header_offset, content_length_header_len);
5129 /*-------- DEBUG LOG --------*/
5130 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5132 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5133 "handle_realserver_recv() : call find_http_header : "
5134 "return_value = %d. thread id : %d.");
5135 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
5136 putLogDebug(100174, formatter.str(), __FILE__, __LINE__ );
5138 /*------DEBUG LOG END------*/
5140 //searched ContentLength http header
5143 //Get Content_Length header's numeric value
5144 for (pos = 0; recv_data.recive_buffer[new_send_it->send_offset + content_length_header_offset + pos] != ':'
5145 && pos < content_length_header_len; ++pos)
5147 if (pos == content_length_header_len)
5149 throw std::string("Content_Length field's value is invalid.");
5154 str_value.assign(recv_data.recive_buffer + new_send_it->send_offset + content_length_header_offset + pos,
5155 content_length_header_len - pos);
5157 size_t pos_end = str_value.find_last_of('\r');
5158 if (pos_end != std::string::npos)
5160 str_value = str_value.erase(pos_end);
5163 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos)
5166 str_value = str_value.substr(pos);
5169 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
5171 catch (const boost::bad_lexical_cast& ex)
5173 throw std::string("Content_Length field's value is invalid.");
5175 //send_rest_size recalc
5176 //set whole http header's + whole http header's length + Content_Length's value
5177 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
5179 //not searched ContentLength http header
5182 //send_rest_size recalc
5183 //set whole http header's + whole http header's length
5184 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
5187 //not searched whole http header
5190 new_send_it->unsend_size = request_data_remain_size;
5191 request_data_remain_size = 0;
5195 //check http method or version result is NG
5196 else if (check_result == CHECK_NG)
5198 new_send_it->send_rest_size = request_data_remain_size;
5200 //check http method or version result is impossible
5203 new_send_it->unsend_size = request_data_remain_size;
5204 request_data_remain_size = 0;
5208 //recalc fields value according to send_rest_size and request rest size
5209 if (new_send_it->send_rest_size > request_data_remain_size)
5211 new_send_it->send_possible_size = request_data_remain_size;
5212 new_send_it->send_rest_size -= request_data_remain_size;
5213 new_send_it->send_end_size = 0;
5214 new_send_it->send_end_size = 0;
5215 request_data_remain_size = 0;
5219 new_send_it->send_possible_size = new_send_it->send_rest_size;
5220 request_data_remain_size -= new_send_it->send_rest_size;
5221 new_send_it->send_end_size = 0;
5222 new_send_it->send_rest_size = 0;
5225 //change status from SEND_NG to SEND_OK
5226 new_send_it->status = SEND_OK;
5228 /*-------- DEBUG LOG --------*/
5229 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5231 std::string datadump;
5232 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
5233 "send_rest_size = %d, send_possible_size = %d, "
5234 "send_offset = %d, unsend_size = %d, edit_division = %d.");
5236 for (it = recv_data.send_status_list.begin();
5237 it != recv_data.send_status_list.end();
5240 formatter % i % it->status % it->send_end_size
5241 % it->send_rest_size % it->send_possible_size
5242 % it->send_offset % it->unsend_size % it->edit_division;
5243 datadump += formatter.str();
5246 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5247 "handle_realserver_recv() : send status list dump : send status list size = %d.%s");
5249 formatter % recv_data.send_status_list.size() % datadump;
5250 putLogDebug(100175, formatter.str(), __FILE__, __LINE__ );
5252 /*------DEBUG LOG END------*/
5254 //search for send_possible item in status list
5255 send_status_it it_find = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
5256 data_send_possible());
5257 //the data that can be sent possible is exist
5258 if (it_find != recv_data.send_status_list.end())
5260 status = CLIENT_CONNECTION_CHECK;
5262 //the data that can be sent possible is not exist
5265 status = REALSERVER_RECV;
5270 /*-------- DEBUG LOG --------*/
5271 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5273 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5274 "handle_realserver_recv() : catch exception e = %d. thread id : %d.");
5275 formatter % e % boost::this_thread::get_id();
5276 putLogDebug(100176, formatter.str(), __FILE__, __LINE__ );
5278 /*------DEBUG LOG END------*/
5281 catch (const std::string& ex)
5283 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : exception : " << ex << std::endl;
5284 boost::format formatter("protocol_module_sessionless::handle_realserver_recv() : exception : %s. thread id : %d.");
5285 formatter % ex.c_str() % boost::this_thread::get_id();
5286 putLogError(100086, formatter.str(), __FILE__, __LINE__ );
5289 catch (const std::bad_alloc&)
5291 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : exception : Could not allocate memory." << std::endl;
5292 boost::format formatter("Could not allocate memory. thread id : %d.");
5293 formatter % boost::this_thread::get_id();
5294 putLogError(100087, formatter.str(), __FILE__, __LINE__ );
5297 catch (const std::exception& ex)
5299 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : exception : error = " << ex.what() << "." << std::endl;
5300 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5301 "handle_realserver_recv() : exception : error = %s. thread id : %d.");
5302 formatter % ex.what() % boost::this_thread::get_id();
5303 putLogError(100088, formatter.str(), __FILE__, __LINE__ );
5309 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : Unknown exception." << std::endl;
5310 boost::format formatter("function : protocol_module_base::EVENT_TAG "
5311 "protocol_module_sessionless::handle_realserver_recv() : "
5312 "Unknown exception. thread id : %d.");
5313 formatter % boost::this_thread::get_id();
5314 putLogError(100089, formatter.str(), __FILE__, __LINE__ );
5318 /*-------- DEBUG LOG --------*/
5319 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5321 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5322 "handle_realserver_recv(const boost::thread::id thread_id, "
5323 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
5324 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5325 "const size_t recvlen) : return_value = %d. thread id : %d.");
5326 formatter % status % boost::this_thread::get_id();
5327 putLogDebug(100177, formatter.str(), __FILE__, __LINE__ );
5329 /*------DEBUG LOG END------*/
5336 //! called from after sorryserver recive
5337 //! @param[in] downstream thread id
5338 //! @param[in] sorryserver endpoint reference
5339 //! @param[in] recive from realserver buffer reference.
5340 //! @param[in] recv data length
5341 //! @return session use EVENT mode
5342 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_recv(
5343 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint& sorry_endpoint, const boost::array<
5344 char, MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
5346 /*-------- DEBUG LOG --------*/
5347 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5349 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
5351 dump_memory(recvbuffer.data(), buffer_size, buffer);
5352 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5353 "handle_sorryserver_recv(const boost::thread::id thread_id, "
5354 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
5355 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5356 "const size_t recvlen) : thread_id = %d, sorry_endpoint = [%s]:%d, recvbuffer = %s, recvlen = %d.");
5357 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port()
5359 putLogDebug(100178, formatter.str(), __FILE__, __LINE__ );
5361 /*------DEBUG LOG END------*/
5363 EVENT_TAG status = FINALIZE;
5364 size_t data_remain_start = 0;
5365 size_t data_remain_size = 0;
5366 size_t request_data_remain_size = 0;
5367 size_t header_offset = 0;
5368 size_t header_offset_len = 0;
5369 size_t content_length_header_offset = 0;
5370 size_t content_length_header_len = 0;
5371 size_t content_len_value = 0;
5373 size_t buffer_size = 0;
5374 const size_t cr_lf_len = strlen("\r\n\r\n");
5375 std::string str_value;
5376 const std::string http_header = "";
5377 const std::string content_header = "Content-Length";
5378 thread_data_ptr session_data;
5379 char* buffer1 = NULL;
5380 char* buffer2 = NULL;
5382 CHECK_RESULT_TAG check_result;
5383 session_thread_data_map_it session_thread_it;
5384 recive_data_map_it recive_data_it;
5387 if (recvlen > recvbuffer.size())
5389 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : Data size bigger than buffer size." << std::endl;
5390 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
5391 formatter % boost::this_thread::get_id();
5392 putLogError(100090, formatter.str(), __FILE__,
5394 /*-------- DEBUG LOG --------*/
5395 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5397 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5398 "handle_sorryserver_recv(const boost::thread::id thread_id, "
5399 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
5400 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5401 "const size_t recvlen) : return_value = %d. thread id : %d.");
5402 formatter % FINALIZE % boost::this_thread::get_id();
5403 putLogDebug(100179, formatter.str(), __FILE__, __LINE__ );
5405 /*------DEBUG LOG END------*/
5412 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
5414 session_thread_it = session_thread_data_map.find(thread_id);
5415 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
5417 boost::format formatter("Invalid thread id. thread id : %d.");
5418 formatter % boost::this_thread::get_id();
5419 putLogError(100091, formatter.str(), __FILE__, __LINE__ );
5423 session_data = session_thread_it->second;
5426 recive_data_it = session_data->recive_data_map.find(sorry_endpoint);
5427 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
5429 recive_data recv_data;
5430 session_data->recive_data_map[sorry_endpoint] = recv_data;
5433 session_data->target_endpoint = sorry_endpoint;
5435 recive_data& recv_data = session_data->recive_data_map[sorry_endpoint];
5438 send_status_it it = recv_data.send_status_list.begin();
5439 send_status_it it_end = recv_data.send_status_list.end();
5440 it = std::find_if(it, it_end, data_send_ok());
5441 if (unlikely(it != it_end))
5443 boost::format formatter("Sending data is invalid. thread id : %d.");
5444 formatter % boost::this_thread::get_id();
5445 putLogError(100092, formatter.str(), __FILE__, __LINE__ );
5450 it = recv_data.send_status_list.begin();
5451 it = std::adjacent_find(it, it_end, data_send_repeated());
5452 if (unlikely(it != it_end))
5454 boost::format formatter("Sending data is invalid. thread id : %d.");
5455 formatter % boost::this_thread::get_id();
5456 putLogError(100093, formatter.str(), __FILE__, __LINE__ );
5460 /*-------- DEBUG LOG --------*/
5461 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5463 std::string datadump;
5464 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
5465 "send_rest_size = %d, send_possible_size = %d, "
5466 "send_offset = %d, unsend_size = %d, edit_division = %d.");
5468 for (it = recv_data.send_status_list.begin();
5469 it != recv_data.send_status_list.end();
5472 formatter % i % it->status % it->send_end_size
5473 % it->send_rest_size % it->send_possible_size
5474 % it->send_offset % it->unsend_size % it->edit_division;
5475 datadump += formatter.str();
5478 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5479 "handle_sorryserver_recv() : send status list dump : send status list size = %d.%s");
5481 formatter % recv_data.send_status_list.size() % datadump;
5482 putLogDebug(100180, formatter.str(), __FILE__, __LINE__ );
5484 /*------DEBUG LOG END------*/
5486 it = recv_data.send_status_list.begin();
5487 //get original status info
5488 while (it != it_end)
5490 //item status is SEND_END
5491 if (it->status == SEND_END)
5494 recv_data.send_status_list.erase(it++);
5497 //item status is SEND_CONTINUE
5498 else if (it->status == SEND_CONTINUE)
5500 it->send_offset += it->send_end_size;
5501 data_remain_start = it->send_offset;
5504 //item status is SEND_NG
5507 data_remain_start = it->send_offset;
5508 data_remain_size = it->unsend_size;
5514 /*-------- DEBUG LOG --------*/
5515 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5517 std::string datadump;
5518 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
5519 "send_rest_size = %d, send_possible_size = %d, "
5520 "send_offset = %d, unsend_size = %d, edit_division = %d.");
5522 for (it = recv_data.send_status_list.begin();
5523 it != recv_data.send_status_list.end();
5526 formatter % i % it->status % it->send_end_size
5527 % it->send_rest_size % it->send_possible_size
5528 % it->send_offset % it->unsend_size % it->edit_division;
5529 datadump += formatter.str();
5532 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5533 "handle_sorryserver_recv() : send status list dump : send status list size = %d.%s");
5535 formatter % recv_data.send_status_list.size() % datadump;
5536 putLogDebug(100181, formatter.str(), __FILE__, __LINE__ );
5538 /*------DEBUG LOG END------*/
5539 //recive buffer process
5540 //buffer rest size < request size
5541 if (recv_data.recive_buffer_rest_size < recvlen)
5543 //buffer max size < remain size + request size
5544 //buffer is need reallocate
5545 if (recv_data.recive_buffer_max_size < data_remain_size + recvlen)
5547 //the buffer's size that will be allocated is exceed the upper limit value
5548 if (MAX_SESSIONLESS_MODULE_BUFFER_SIZE < data_remain_size + recvlen)
5550 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : the buffer's size that will be allacted is exceed the upper limit value." << std::endl;
5551 boost::format formatter("The buffer's size that will be allocated is exceed the upper limit value. thread id : %d.");
5552 formatter % boost::this_thread::get_id();
5553 putLogError(100094, formatter.str(), __FILE__, __LINE__ );
5554 /*-------- DEBUG LOG --------*/
5555 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5557 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5558 "handle_sorryserver_recv(const boost::thread::id thread_id, "
5559 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
5560 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5561 "const size_t recvlen) : return_value = %d. thread id : %d.");
5562 formatter % FINALIZE % boost::this_thread::get_id();
5563 putLogDebug(100182, formatter.str(), __FILE__, __LINE__ );
5565 /*------DEBUG LOG END------*/
5568 //recive_buffer1's memory allocate and initialization
5569 buffer_size = (data_remain_size + recvlen) > MAX_BUFFER_SIZE ? (data_remain_size + recvlen) : MAX_BUFFER_SIZE;
5570 buffer1 = new char[buffer_size];
5571 /*-------- DEBUG LOG --------*/
5572 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5574 boost::format formatter("new : address = &(%d), size = %lu.");
5575 formatter % static_cast<void*>(buffer1) % buffer_size;
5576 putLogDebug(100183, formatter.str(), __FILE__, __LINE__ );
5578 /*-------- DEBUG LOG END--------*/
5579 memset(buffer1, 0, buffer_size);
5580 //recive_buffer2's memory allocate and initialization
5581 buffer2 = new char[buffer_size];
5582 /*-------- DEBUG LOG --------*/
5583 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5585 boost::format formatter("new : address = &(%d), size = %lu.");
5586 formatter % static_cast<void*>(buffer2) % buffer_size;
5587 putLogDebug(100184, formatter.str(), __FILE__, __LINE__ );
5589 /*-------- DEBUG LOG END--------*/
5590 memset(buffer2, 0, buffer_size);
5592 /*-------- DEBUG LOG --------*/
5593 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5595 std::string datadump;
5596 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
5597 boost::format formatter(
5598 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5599 "handle_sorryserver_recv() : before memcpy (data dump) : "
5600 "data begin = %d, data_size = %d, data = %s");
5601 formatter % data_remain_start % data_remain_size % datadump;
5602 putLogDebug(100185, formatter.str(), __FILE__, __LINE__ );
5604 /*------DEBUG LOG END------*/
5605 //copy data from old buffer to new buffer
5606 memcpy(buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
5607 /*-------- DEBUG LOG --------*/
5608 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5610 std::string datadump;
5611 dump_memory(buffer1, data_remain_size, datadump);
5612 boost::format formatter(
5613 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5614 "handle_sorryserver_recv() : after memcpy (data dump) : "
5615 "data begin = 0, data_size = %d, data = %s");
5616 formatter % data_remain_size % datadump;
5617 putLogDebug(100186, formatter.str(), __FILE__, __LINE__ );
5619 /*------DEBUG LOG END------*/
5621 /*-------- DEBUG LOG --------*/
5622 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5624 std::string datadump;
5625 dump_memory(recvbuffer.data(), recvlen, datadump);
5626 boost::format formatter(
5627 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5628 "handle_sorryserver_recv() : before memcpy (data dump) : "
5629 "data begin = 0, data_size = %d, data = %s");
5630 formatter % recvlen % datadump;
5631 putLogDebug(100187, formatter.str(), __FILE__, __LINE__ );
5633 /*------DEBUG LOG END------*/
5634 memcpy(buffer1 + data_remain_size, recvbuffer.data(), recvlen);
5635 /*-------- DEBUG LOG --------*/
5636 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5638 std::string datadump;
5639 dump_memory(buffer1 + data_remain_size, recvlen, datadump);
5640 boost::format formatter(
5641 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5642 "handle_sorryserver_recv() : after memcpy (data dump) : "
5643 "data begin = %d, data_size = %d, data = %s");
5644 formatter % data_remain_size % recvlen % datadump;
5645 putLogDebug(100188, formatter.str(), __FILE__, __LINE__ );
5647 /*------DEBUG LOG END------*/
5648 //free old buffer1 and old buffer2
5649 if (recv_data.recive_buffer1 != NULL)
5651 /*-------- DEBUG LOG --------*/
5652 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5654 boost::format formatter("delete : address = &(%d).");
5655 formatter % static_cast<void*>(recv_data.recive_buffer1);
5656 putLogDebug(100189, formatter.str(), __FILE__,
5659 /*------DEBUG LOG END------*/
5660 delete[] recv_data.recive_buffer1;
5661 recv_data.recive_buffer1 = NULL;
5664 if (recv_data.recive_buffer2 != NULL)
5666 /*-------- DEBUG LOG --------*/
5667 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5669 boost::format formatter("delete : address = &(%d).");
5670 formatter % static_cast<void*>(recv_data.recive_buffer2);
5671 putLogDebug(100190, formatter.str(), __FILE__,
5674 /*------DEBUG LOG END------*/
5675 delete[] recv_data.recive_buffer2;
5676 recv_data.recive_buffer2 = NULL;
5679 //set new buffer pointer
5680 recv_data.recive_buffer1 = buffer1;
5681 recv_data.recive_buffer2 = buffer2;
5682 recv_data.recive_buffer = recv_data.recive_buffer1;
5683 //set new buffer's max size
5684 recv_data.recive_buffer_max_size = buffer_size;
5686 //buffer's max size >= remain data size + requst size
5687 //buffer isn't need reallocate, but switch
5690 //pointer valid check
5691 if (unlikely(recv_data.recive_buffer1 == NULL || recv_data.recive_buffer2 == NULL))
5693 boost::format formatter("Invalid pointer. thread id : %d.");
5694 formatter % boost::this_thread::get_id();
5695 putLogError(100095, formatter.str(), __FILE__, __LINE__ );
5698 //using buffer is buffer1
5699 if (recv_data.recive_buffer == recv_data.recive_buffer1)
5701 //buffer2 initialization
5702 memset(recv_data.recive_buffer2, 0, recv_data.recive_buffer_max_size);
5703 /*-------- DEBUG LOG --------*/
5704 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5706 std::string datadump;
5707 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
5708 boost::format formatter(
5709 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5710 "handle_sorryserver_recv() : before memcpy (data dump) : "
5711 "data begin = %d, data_size = %d, data = %s");
5712 formatter % data_remain_start % data_remain_size % datadump;
5713 putLogDebug(100191, formatter.str(), __FILE__, __LINE__ );
5715 /*------DEBUG LOG END------*/
5716 //copy data from buffer1 to buffer2
5717 memcpy(recv_data.recive_buffer2, recv_data.recive_buffer + data_remain_start, data_remain_size);
5718 /*-------- DEBUG LOG --------*/
5719 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5721 std::string datadump;
5722 dump_memory(recv_data.recive_buffer2, data_remain_size, datadump);
5723 boost::format formatter(
5724 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5725 "handle_sorryserver_recv() : after memcpy (data dump) : "
5726 "data begin = 0, data_size = %d, data = %s");
5727 formatter % data_remain_size % datadump;
5728 putLogDebug(100192, formatter.str(), __FILE__, __LINE__ );
5730 /*------DEBUG LOG END------*/
5731 /*-------- DEBUG LOG --------*/
5732 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5734 std::string datadump;
5735 dump_memory(recvbuffer.data(), recvlen, datadump);
5736 boost::format formatter(
5737 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5738 "handle_sorryserver_recv() : before memcpy (data dump) : "
5739 "data begin = 0, data_size = %d, data = %s");
5740 formatter % recvlen % datadump;
5741 putLogDebug(100193, formatter.str(), __FILE__, __LINE__ );
5743 /*------DEBUG LOG END------*/
5744 memcpy(recv_data.recive_buffer2 + data_remain_size, recvbuffer.data(), recvlen);
5745 /*-------- DEBUG LOG --------*/
5746 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5748 std::string datadump;
5749 dump_memory(recv_data.recive_buffer2 + data_remain_size, recvlen, datadump);
5750 boost::format formatter(
5751 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5752 "handle_sorryserver_recv() : after memcpy (data dump) : "
5753 "data begin = %d, data_size = %d, data = %s");
5754 formatter % data_remain_size % recvlen % datadump;
5755 putLogDebug(100194, formatter.str(), __FILE__, __LINE__ );
5757 /*------DEBUG LOG END------*/
5758 //set buffer2 as using buffer
5759 recv_data.recive_buffer = recv_data.recive_buffer2;
5761 //using buffer is buffer2
5764 //buffer1 initializtion
5765 memset(recv_data.recive_buffer1, 0, recv_data.recive_buffer_max_size);
5766 /*-------- DEBUG LOG --------*/
5767 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5769 std::string datadump;
5770 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
5771 boost::format formatter(
5772 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5773 "handle_sorryserver_recv() : before memcpy (data dump) : "
5774 "data begin = %d, data_size = %d, data = %s");
5775 formatter % data_remain_start % data_remain_size % datadump;
5776 putLogDebug(100195, formatter.str(), __FILE__, __LINE__ );
5778 /*------DEBUG LOG END------*/
5779 //copy data from buffer2 to buffer1
5780 memcpy(recv_data.recive_buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
5781 /*-------- DEBUG LOG --------*/
5782 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5784 std::string datadump;
5785 dump_memory(recv_data.recive_buffer1, data_remain_size, datadump);
5786 boost::format formatter(
5787 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5788 "handle_sorryserver_recv() : after memcpy (data dump) : "
5789 "data begin = 0, data_size = %d, data = %s");
5790 formatter % data_remain_size % datadump;
5791 putLogDebug(100196, formatter.str(), __FILE__, __LINE__ );
5793 /*------DEBUG LOG END------*/
5795 /*-------- DEBUG LOG --------*/
5796 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5798 std::string datadump;
5799 dump_memory(recvbuffer.data(), recvlen, datadump);
5800 boost::format formatter(
5801 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5802 "handle_sorryserver_recv() : before memcpy (data dump) : "
5803 "data begin = 0, data_size = %d, data = %s");
5804 formatter % recvlen % datadump;
5805 putLogDebug(100197, formatter.str(), __FILE__, __LINE__ );
5807 /*------DEBUG LOG END------*/
5808 memcpy(recv_data.recive_buffer1 + data_remain_size, recvbuffer.data(), recvlen);
5809 /*-------- DEBUG LOG --------*/
5810 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5812 std::string datadump;
5813 dump_memory(recv_data.recive_buffer1 + data_remain_size, recvlen, datadump);
5814 boost::format formatter(
5815 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5816 "handle_sorryserver_recv() : after memcpy (data dump) : "
5817 "data begin = %d, data_size = %d, data = %s");
5818 formatter % data_remain_size % recvlen % datadump;
5819 putLogDebug(100198, formatter.str(), __FILE__, __LINE__ );
5821 /*------DEBUG LOG END------*/
5822 //set buffer1 as using buffer
5823 recv_data.recive_buffer = recv_data.recive_buffer1;
5827 //set buffer's rest size
5828 recv_data.recive_buffer_rest_size = recv_data.recive_buffer_max_size - data_remain_size - recvlen;
5830 //remain_size recalc
5831 data_remain_size += recvlen;
5833 send_status_it it_begin = recv_data.send_status_list.begin();
5834 send_status_it it_end = recv_data.send_status_list.end();
5836 for (; it_begin != it_end; ++it_begin)
5838 it_begin->send_offset -= data_remain_start;
5841 //buffer's rest size >= request size
5845 //pointer valid check
5846 if (unlikely(recv_data.recive_buffer == NULL))
5848 boost::format formatter("Invalid pointer. thread id : %d");
5849 formatter % boost::this_thread::get_id();
5850 putLogError(100096, formatter.str(), __FILE__, __LINE__ );
5853 /*-------- DEBUG LOG --------*/
5854 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5856 std::string datadump;
5857 dump_memory(recvbuffer.data(), recvlen, datadump);
5858 boost::format formatter(
5859 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5860 "handle_sorryserver_recv() : before memcpy (data dump) : "
5861 "data begin = 0, data_size = %d, data = %s");
5862 formatter % recvlen % datadump;
5863 putLogDebug(100199, formatter.str(), __FILE__, __LINE__ );
5865 /*------DEBUG LOG END------*/
5867 //copy data from parameter to using buffer
5868 memcpy(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
5869 recvbuffer.data(), recvlen);
5870 /*-------- DEBUG LOG --------*/
5871 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5873 std::string datadump;
5874 dump_memory(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size, recvlen, datadump);
5875 boost::format formatter(
5876 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5877 "handle_sorryserver_recv() : after memcpy (data dump) : "
5878 "data begin = %d, data_size = %d, data = %s");
5879 formatter % (recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size) % recvlen % datadump;
5880 putLogDebug(100200, formatter.str(), __FILE__, __LINE__ );
5882 /*------DEBUG LOG END------*/
5883 //buffer's rest size recalc
5884 recv_data.recive_buffer_rest_size -= recvlen;
5885 //remain data size recalc
5886 data_remain_size += recvlen;
5889 it = recv_data.send_status_list.begin();
5890 it_end = recv_data.send_status_list.end();
5891 //request rest size initialization
5892 request_data_remain_size = recvlen;
5893 //original status process
5894 for (; it != it_end; ++it)
5896 //status is SEND_CONTINUE
5897 if (it->status == SEND_CONTINUE)
5900 if (it->send_rest_size > request_data_remain_size)
5902 it->send_possible_size = request_data_remain_size;
5903 it->send_rest_size -= request_data_remain_size;
5904 it->send_end_size = 0;
5905 request_data_remain_size = 0;
5909 it->send_possible_size = it->send_rest_size;
5910 request_data_remain_size -= it->send_rest_size;
5911 it->send_end_size = 0;
5912 it->send_rest_size = 0;
5915 //change status from SEND_CONTINUE to SEND_OK
5916 it->status = SEND_OK;
5919 else if (it->status == SEND_NG)
5922 check_result = check_status_code(recv_data.recive_buffer + it->send_offset, data_remain_size);
5923 /*-------- DEBUG LOG --------*/
5924 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5926 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5927 "handle_sorryserver_recv() : call check_status_code : "
5928 "return_value = %d. thread id : %d.");
5929 formatter % check_result % boost::this_thread::get_id();
5930 putLogDebug(100201, formatter.str(), __FILE__, __LINE__ );
5932 /*------DEBUG LOG END------*/
5933 //check http method result is OK
5934 if (check_result == CHECK_OK)
5936 //check http version
5937 check_result = check_http_version(recv_data.recive_buffer + it->send_offset, data_remain_size);
5938 /*-------- DEBUG LOG --------*/
5939 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5941 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5942 "handle_sorryserver_recv() : call check_http_version : "
5943 "return_value = %d. thread id : %d.");
5944 formatter % check_result % boost::this_thread::get_id();
5945 putLogDebug(100202, formatter.str(), __FILE__, __LINE__ );
5947 /*------DEBUG LOG END------*/
5949 //check method and version result is OK
5950 if (check_result == CHECK_OK)
5952 //search http header
5953 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size, http_header,
5954 header_offset, header_offset_len);
5955 /*-------- DEBUG LOG --------*/
5956 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5958 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5959 "handle_sorryserver_recv() : call find_http_header : "
5960 "return_value = %d. thread id : %d.");
5961 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
5962 putLogDebug(100203, formatter.str(), __FILE__, __LINE__ );
5964 /*------DEBUG LOG END------*/
5965 //search http header result is OK
5968 //search Content_Length header
5969 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size,
5970 content_header, content_length_header_offset, content_length_header_len);
5971 /*-------- DEBUG LOG --------*/
5972 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5974 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5975 "handle_sorryserver_recv() : call find_http_header : "
5976 "return_value = %d. thread id : %d.");
5977 formatter % static_cast<int>(bret) %boost::this_thread::get_id();
5978 putLogDebug(100204, formatter.str(), __FILE__, __LINE__ );
5980 /*------DEBUG LOG END------*/
5981 //search Content_Length result is OK
5984 //Get Content_Length header's numeric value
5985 for (pos = 0; recv_data.recive_buffer[it->send_offset + content_length_header_offset + pos] != ':' && pos
5986 < content_length_header_len; ++pos)
5988 if (pos == content_length_header_len)
5990 throw std::string("Content_Length field's value is invalid.");
5995 str_value.assign(recv_data.recive_buffer + it->send_offset + content_length_header_offset + pos,
5996 content_length_header_len - pos);
5998 size_t pos_end = str_value.find_last_of('\r');
5999 if (pos_end != std::string::npos)
6001 str_value = str_value.erase(pos_end);
6004 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos)
6007 str_value = str_value.substr(pos);
6011 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
6013 catch (const boost::bad_lexical_cast& ex)
6015 throw std::string("Content_Length field's value is invalid.");
6017 //send_rest_size recalc
6018 //set whole http header's length + Content_Length's value
6019 it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
6021 //search Content_Length result is NG
6024 //send_rest_size recalc
6025 //set whole http header's length
6026 it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
6029 //search http header result is NG
6032 it->unsend_size += request_data_remain_size;
6033 request_data_remain_size = 0;
6037 //check method or version result is NG
6038 else if (check_result == CHECK_NG)
6040 it->send_rest_size = it->unsend_size+request_data_remain_size;
6042 //check method and version result is CHECK_INPOSSIBLE
6045 it->unsend_size += request_data_remain_size;
6046 request_data_remain_size = 0;
6050 //recalc fields value according to send_rest_size and request rest size
6051 if (it->send_rest_size > it->unsend_size + request_data_remain_size)
6053 it->send_possible_size = it->unsend_size + request_data_remain_size;
6054 it->send_rest_size -= (it->unsend_size + request_data_remain_size);
6055 it->send_end_size = 0;
6056 it->unsend_size = 0;
6057 request_data_remain_size = 0;
6061 it->send_possible_size = it->send_rest_size;
6062 request_data_remain_size = it->unsend_size + request_data_remain_size - it->send_rest_size;
6063 it->send_end_size = 0;
6064 it->unsend_size = 0;
6065 it->send_rest_size = 0;
6068 //change status from SEND_NG to SEND_OK
6069 it->status = SEND_OK;
6071 //no request rest data to process
6072 if (request_data_remain_size <= 0)
6077 /*-------- DEBUG LOG --------*/
6078 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6080 std::string datadump;
6081 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
6082 "send_rest_size = %d, send_possible_size = %d, "
6083 "send_offset = %d, unsend_size = %d, edit_division = %d.");
6085 for (it = recv_data.send_status_list.begin();
6086 it != recv_data.send_status_list.end();
6089 formatter % i % it->status % it->send_end_size
6090 % it->send_rest_size % it->send_possible_size
6091 % it->send_offset % it->unsend_size % it->edit_division;
6092 datadump += formatter.str();
6095 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6096 "handle_sorryserver_recv() : send status list dump : send status list size = %d.%s");
6098 formatter % recv_data.send_status_list.size() % datadump;
6099 putLogDebug(100205, formatter.str(), __FILE__, __LINE__ );
6101 /*------DEBUG LOG END------*/
6103 //there are still rest data need to process
6104 //new status created and add to status list
6105 while (request_data_remain_size > 0)
6107 //new status created
6108 send_status new_send_state;
6109 new_send_state.edit_division = EDIT_DIVISION_NO_EDIT;
6110 new_send_state.send_end_size = 0;
6111 new_send_state.send_offset = 0;
6112 new_send_state.send_possible_size = 0;
6113 new_send_state.unsend_size = 0;
6114 new_send_state.send_rest_size = 0;
6115 //status initialize to SEND_NG
6116 new_send_state.status = SEND_NG;
6117 //add new status to status_list
6118 recv_data.send_status_list.push_back(new_send_state);
6119 std::list<send_status>::reverse_iterator new_send_it = recv_data.send_status_list.rbegin();
6121 new_send_it->send_offset = recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size
6122 - request_data_remain_size;
6125 check_result = check_status_code(recv_data.recive_buffer + new_send_it->send_offset,
6126 request_data_remain_size);
6127 /*-------- DEBUG LOG --------*/
6128 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6130 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6131 "handle_sorryserver_recv() : call check_status_code : "
6132 "return_value = %d. thread id : %d.");
6133 formatter % check_result % boost::this_thread::get_id();
6134 putLogDebug(100206, formatter.str(), __FILE__, __LINE__ );
6136 /*------DEBUG LOG END------*/
6137 //check http method result is OK
6138 if (check_result == CHECK_OK)
6140 //check http version
6141 check_result = check_http_version(recv_data.recive_buffer + new_send_it->send_offset,
6142 request_data_remain_size);
6143 /*-------- DEBUG LOG --------*/
6144 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6146 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6147 "handle_sorryserver_recv() : call check_http_version : "
6148 "return_value = %d. thread id : %d.");
6149 formatter % check_result % boost::this_thread::get_id();
6150 putLogDebug(100207, formatter.str(), __FILE__, __LINE__ );
6152 /*------DEBUG LOG END------*/
6154 //check http method and version result is OK
6155 if (check_result == CHECK_OK)
6157 //search whole http header, get whole http header's offset and length
6158 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset, request_data_remain_size,
6159 http_header, header_offset, header_offset_len);
6160 /*-------- DEBUG LOG --------*/
6161 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6163 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6164 "handle_sorryserver_recv() : call find_http_header : "
6165 "return_value = %d. thread id : %d.");
6166 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
6167 putLogDebug(100208, formatter.str(), __FILE__, __LINE__ );
6169 /*------DEBUG LOG END------*/
6170 //searched whole http header
6173 //search ContentLength http header, get ContentLength header's offset and length
6174 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset,
6175 request_data_remain_size, content_header, content_length_header_offset, content_length_header_len);
6176 /*-------- DEBUG LOG --------*/
6177 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6179 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6180 "handle_sorryserver_recv() : call find_http_header : "
6181 "return_value = %d. thread id : %d.");
6182 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
6183 putLogDebug(100209, formatter.str(), __FILE__, __LINE__ );
6185 /*------DEBUG LOG END------*/
6187 //searched ContentLength http header
6190 //Get Content_Length header's numeric value
6191 for (pos = 0; recv_data.recive_buffer[new_send_it->send_offset + content_length_header_offset + pos] != ':'
6192 && pos < content_length_header_len; ++pos)
6194 if (pos == content_length_header_len)
6196 throw std::string("Content_Length field's value is invalid.");
6200 str_value.assign(recv_data.recive_buffer + new_send_it->send_offset + content_length_header_offset + pos,
6201 content_length_header_len - pos);
6203 size_t pos_end = str_value.find_last_of('\r');
6204 if (pos_end != std::string::npos)
6206 str_value = str_value.erase(pos_end);
6209 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos)
6212 str_value = str_value.substr(pos);
6215 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
6217 catch (const boost::bad_lexical_cast& ex)
6219 throw std::string("Content_Length field's value is invalid.");
6221 //send_rest_size recalc
6222 //set whole http header's + whole http header's length + Content_Length's value
6223 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
6225 //not searched ContentLength http header
6228 //send_rest_size recalc
6229 //set whole http header's + whole http header's length
6230 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
6233 //not searched whole http header
6236 new_send_it->unsend_size = request_data_remain_size;
6237 request_data_remain_size = 0;
6241 //check http method or version result is NG
6242 else if (check_result == CHECK_NG)
6244 new_send_it->send_rest_size = request_data_remain_size;
6246 //check http method or version result is impossible
6249 new_send_it->unsend_size = request_data_remain_size;
6250 request_data_remain_size = 0;
6254 //recalc fields value according to send_rest_size and request rest size
6255 if (new_send_it->send_rest_size > request_data_remain_size)
6257 new_send_it->send_possible_size = request_data_remain_size;
6258 new_send_it->send_rest_size -= request_data_remain_size;
6259 new_send_it->send_end_size = 0;
6260 request_data_remain_size = 0;
6264 new_send_it->send_possible_size = new_send_it->send_rest_size;
6265 request_data_remain_size -= new_send_it->send_rest_size;
6266 new_send_it->send_end_size = 0;
6267 new_send_it->send_rest_size = 0;
6270 //change status from SEND_NG to SEND_OK
6271 new_send_it->status = SEND_OK;
6273 /*-------- DEBUG LOG --------*/
6274 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6276 std::string datadump;
6277 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
6278 "send_rest_size = %d, send_possible_size = %d, "
6279 "send_offset = %d, unsend_size = %d, edit_division = %d.");
6281 for (it = recv_data.send_status_list.begin();
6282 it != recv_data.send_status_list.end();
6285 formatter % i % it->status % it->send_end_size
6286 % it->send_rest_size % it->send_possible_size
6287 % it->send_offset % it->unsend_size % it->edit_division;
6288 datadump += formatter.str();
6291 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6292 "handle_sorryserver_recv() : send status list dump : send status list size = %d.%s");
6294 formatter % recv_data.send_status_list.size() % datadump;
6295 putLogDebug(100210, formatter.str(), __FILE__, __LINE__ );
6297 /*------DEBUG LOG END------*/
6299 //search for send_possible item in status list
6300 send_status_it it_find = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
6301 data_send_possible());
6302 //the data that can be sent possible is exist
6303 if (it_find != recv_data.send_status_list.end())
6305 status = CLIENT_CONNECTION_CHECK;
6307 //the data that can be sent possible is not exist
6310 status = SORRYSERVER_RECV;
6315 /*-------- DEBUG LOG --------*/
6316 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6318 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6319 "handle_sorryserver_recv() : catch exception e = %d. thread id : %d.");
6320 formatter % e % boost::this_thread::get_id();
6321 putLogDebug(100211, formatter.str(), __FILE__, __LINE__ );
6323 /*------DEBUG LOG END------*/
6326 catch (const std::string& ex)
6328 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : exception : " << ex << std::endl;
6329 boost::format formatter("protocol_module_sessionless::handle_sorryserver_recv() : exception : %s. thread id : %d.");
6330 formatter % ex.c_str() % boost::this_thread::get_id();
6331 putLogError(100097, formatter.str(), __FILE__, __LINE__ );
6334 catch (const std::bad_alloc&)
6336 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : exception : Could not allocate memory." << std::endl;
6337 boost::format formatter("Could not allocate memory. thread id : %d.");
6338 formatter % boost::this_thread::get_id();
6339 putLogError(100098, formatter.str(), __FILE__, __LINE__ );
6342 catch (const std::exception& ex)
6344 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : exception : error = " << ex.what() << "." << std::endl;
6345 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6346 "handle_sorryserver_recv() : exception : error = %s. thread id : %d.");
6347 formatter % ex.what() % boost::this_thread::get_id();
6348 putLogError(100099, formatter.str(), __FILE__, __LINE__ );
6354 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : Unknown exception." << std::endl;
6355 boost::format formatter("function : protocol_module_base::EVENT_TAG "
6356 "protocol_module_sessionless::handle_sorryserver_recv() : "
6357 "Unknown exception. thread id : %d.");
6358 formatter % boost::this_thread::get_id();
6359 putLogError(100100, formatter.str(), __FILE__, __LINE__ );
6363 /*-------- DEBUG LOG --------*/
6364 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6366 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6367 "handle_sorryserver_recv(const boost::thread::id thread_id, "
6368 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
6369 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
6370 "const size_t recvlen) : return_value = %d. thread id : %d.");
6371 formatter % status % boost::this_thread::get_id();
6372 putLogDebug(100212, formatter.str(), __FILE__, __LINE__ );
6374 /*------DEBUG LOG END------*/
6379 //! called from UPSTEEARM thread. make module original message.
6380 //! @param[in] downstream thread id.
6381 //! @return session use EVENT mode
6382 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_response_send_inform(
6383 const boost::thread::id thread_id)
6385 /*-------- DEBUG LOG --------*/
6386 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6388 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6389 "handle_response_send_inform(const boost::thread::id thread_id) : "
6390 "return_value = %d. thread id : %d.");
6391 formatter % STOP % boost::this_thread::get_id();
6392 putLogDebug(100213, formatter.str(), __FILE__, __LINE__ );
6394 /*------DEBUG LOG END------*/
6398 //! called from after client connection check. use TCP/IP only. create client send message.
6399 //! @param[in] downstream thread id
6400 //! @param[out] send budffer reference
6401 //! @param[out] send data length
6402 //! @return session use EVENT mode
6403 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_connection_check(
6404 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
6407 /*-------- DEBUG LOG --------*/
6408 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6410 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6411 "handle_client_connection_check(const boost::thread::id thread_id, "
6412 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
6414 formatter % thread_id;
6415 putLogDebug(100214, formatter.str(), __FILE__, __LINE__ );
6417 /*------DEBUG LOG END------*/
6419 EVENT_TAG status = FINALIZE;
6420 size_t send_buffer_size = sendbuffer.max_size();
6421 thread_data_ptr session_data;
6422 session_thread_data_map_it session_thread_it;
6423 recive_data_map_it recive_data_it;
6428 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
6430 session_thread_it = session_thread_data_map.find(thread_id);
6431 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
6433 boost::format formatter("Invalid thread id. thread id : %d.");
6434 formatter % boost::this_thread::get_id();
6435 putLogError(100101, formatter.str(), __FILE__, __LINE__ );
6439 session_data = session_thread_it->second;
6442 recive_data_it = session_data->recive_data_map.find(session_data->target_endpoint);
6443 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
6445 boost::format formatter("Invalid endpoint. thread id : %d.");
6446 formatter % boost::this_thread::get_id();
6447 putLogError(100102, formatter.str(), __FILE__, __LINE__ );
6451 recive_data& recv_data = recive_data_it->second;
6453 //get the data that can be sent possible
6454 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
6455 data_send_possible());
6456 if (unlikely(it == recv_data.send_status_list.end()))
6458 boost::format formatter("Sending possible data is not existed. thread id : %d.");
6459 formatter % boost::this_thread::get_id();
6460 putLogError(100103, formatter.str(), __FILE__, __LINE__ );
6464 //buffer size >= sending_possible size
6465 if (send_buffer_size > it->send_possible_size)
6467 /*-------- DEBUG LOG --------*/
6468 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6470 std::string datadump;
6471 dump_memory(recv_data.recive_buffer + it->send_offset, it->send_possible_size, datadump);
6473 boost::format formatter(
6474 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6475 "handle_client_connection_check() : before memcpy (data dump) : "
6476 "data begin = %d, data_size = %d, data = %s");
6477 formatter % it->send_offset % (it->send_possible_size) % datadump;
6478 putLogDebug(100215, formatter.str(), __FILE__, __LINE__ );
6480 /*------DEBUG LOG END------*/
6481 //copy data from recive_buffer to sendbuffer by sending_possible size
6482 memcpy(sendbuffer.data(), recv_data.recive_buffer + it->send_offset, it->send_possible_size);
6483 /*-------- DEBUG LOG --------*/
6484 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6486 std::string datadump;
6487 dump_memory(sendbuffer.data(), it->send_possible_size, datadump);
6489 boost::format formatter(
6490 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6491 "handle_client_connection_check() : after memcpy (data dump) : "
6492 "data begin = 0, data_size = %d, data = %s");
6493 formatter % (it->send_possible_size) % datadump;
6494 putLogDebug(100216, formatter.str(), __FILE__, __LINE__ );
6496 /*------DEBUG LOG END------*/
6497 //send_end_size recalc
6498 it->send_end_size = it->send_possible_size;
6499 //set copyed data length
6500 datalen = it->send_possible_size;
6501 //sending_possible size recalc
6502 it->send_possible_size = 0;
6504 //buffer size < sending_possible size
6507 /*-------- DEBUG LOG --------*/
6508 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6510 std::string datadump;
6511 dump_memory(recv_data.recive_buffer + it->send_offset, send_buffer_size, datadump);
6513 boost::format formatter(
6514 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6515 "handle_client_connection_check() : before memcpy (data dump) : "
6516 "data begin = %d, data_size = %d, data = %s");
6517 formatter % it->send_offset % send_buffer_size % datadump;
6518 putLogDebug(100217, formatter.str(), __FILE__, __LINE__ );
6520 /*------DEBUG LOG END------*/
6521 //copy data from recive_buffer to sendbuffer by buffer size
6522 memcpy(sendbuffer.data(), recv_data.recive_buffer + it->send_offset, send_buffer_size);
6523 /*-------- DEBUG LOG --------*/
6524 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6526 std::string datadump;
6527 dump_memory(sendbuffer.data(), send_buffer_size, datadump);
6529 boost::format formatter(
6530 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6531 "handle_client_connection_check() : after memcpy (data dump) : "
6532 "data begin = 0, data_size = %d, data = %s");
6533 formatter % send_buffer_size % datadump;
6534 putLogDebug(100218, formatter.str(), __FILE__, __LINE__ );
6536 /*------DEBUG LOG END------*/
6537 //send_end_size recalc
6538 it->send_end_size = send_buffer_size;
6539 //sending_possible size recalc
6540 it->send_possible_size -= send_buffer_size;
6541 //set copyed data length
6542 datalen = send_buffer_size;
6545 status = CLIENT_SEND;
6549 /*-------- DEBUG LOG --------*/
6550 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6552 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6553 "handle_client_connection_check() : catch exception e = %d. thread id : %d.");
6554 formatter % e % boost::this_thread::get_id();
6555 putLogDebug(100219, formatter.str(), __FILE__, __LINE__ );
6557 /*------DEBUG LOG END------*/
6560 catch (const std::exception& ex)
6562 std::cerr << "protocol_module_sessionless::handle_client_connection_check() : exception : error = " << ex.what() << "." << std::endl;
6563 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6564 "handle_client_connection_check() : exception : error = %s. thread id : %d.");
6565 formatter % ex.what() % boost::this_thread::get_id();
6566 putLogError(100104, formatter.str(), __FILE__, __LINE__ );
6571 std::cerr << "protocol_module_sessionless::handle_client_connection_check() : Unknown exception." << std::endl;
6572 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6573 "handle_client_connection_check() : Unknown exception. thread id : %d.");
6574 formatter % boost::this_thread::get_id();
6575 putLogError(100105, formatter.str(), __FILE__, __LINE__ );
6579 /*-------- DEBUG LOG --------*/
6580 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6582 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6583 "handle_client_connection_check(const boost::thread::id thread_id, "
6584 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)"
6585 " : return_value = %d. thread id : %d.");
6586 formatter % status % boost::this_thread::get_id();
6587 putLogDebug(100220, formatter.str(), __FILE__, __LINE__ );
6589 /*------DEBUG LOG END------*/
6593 //! called from after client select. use UDP only
6594 //! @param[in] downstream thread id
6595 //! @param[in] client udp endpoint
6596 //! @param[out] send buffer reference
6597 //! @param[out] send data length
6598 //! @return session use EVENT mode
6599 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_select(
6600 const boost::thread::id thread_id, boost::asio::ip::udp::endpoint& cl_endpoint, boost::array<char,
6601 MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
6603 /*-------- DEBUG LOG --------*/
6604 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6606 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6607 "handle_client_select(const boost::thread::id thread_id, "
6608 "boost::asio::ip::udp::endpoint& cl_endpoint, "
6609 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
6610 "size_t& datalen) : "
6611 "return_value = %d. thread id : %d.");
6612 formatter % STOP % boost::this_thread::get_id();
6613 putLogDebug(100221, formatter.str(), __FILE__, __LINE__ );
6615 /*------DEBUG LOG END------*/
6619 //! called from after client send
6620 //! @param[in] downstream thread id
6621 //! @return session use EVENT mode
6622 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_send(
6623 const boost::thread::id thread_id)
6625 /*-------- DEBUG LOG --------*/
6626 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6628 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6629 "handle_client_send(const boost::thread::id thread_id) : "
6631 formatter % thread_id;
6632 putLogDebug(100222, formatter.str(), __FILE__, __LINE__ );
6634 /*------DEBUG LOG END------*/
6635 EVENT_TAG status = FINALIZE;
6636 thread_data_ptr session_data;
6637 session_thread_data_map_it session_thread_it;
6638 recive_data_map_it recive_data_it;
6643 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
6645 session_thread_it = session_thread_data_map.find(thread_id);
6646 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
6648 boost::format formatter("Invalid thread id. thread id : %d.");
6649 formatter % boost::this_thread::get_id();
6650 putLogError(100106, formatter.str(), __FILE__, __LINE__ );
6653 session_data = session_thread_it->second;
6656 recive_data_it = session_data->recive_data_map.find(session_data->target_endpoint);
6657 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
6659 boost::format formatter("Invalid endpoint. thread id : %d.");
6660 formatter % boost::this_thread::get_id();
6661 putLogError(100107, formatter.str(), __FILE__, __LINE__ );
6665 recive_data& recv_data = recive_data_it->second;
6667 send_status_it it = recv_data.send_status_list.begin();
6668 send_status_it it_end = recv_data.send_status_list.end();
6671 it = std::adjacent_find(it, it_end, data_send_list_incorrect());
6672 if (unlikely(it != it_end))
6674 boost::format formatter("Sending possible data is invalid. thread id : %d.");
6675 formatter % boost::this_thread::get_id();
6676 putLogError(100108, formatter.str(), __FILE__, __LINE__ );
6680 it = recv_data.send_status_list.begin();
6681 it = find_if(it, it_end, data_send_ok());
6682 if (unlikely(it == it_end))
6684 boost::format formatter("Sending possible data is not existed. thread id : %d.");
6685 formatter % boost::this_thread::get_id();
6686 putLogError(100109, formatter.str(), __FILE__, __LINE__ );
6690 //sending possible data is exist
6691 if (it->send_possible_size > 0)
6693 //status remain SEND_OK
6694 it->status = SEND_OK;
6696 it->send_offset += it->send_end_size;
6697 //send_end_size recalc
6698 it->send_end_size = 0;
6700 //sending possible data is not exist
6703 //can recive from clent continue
6704 if (it->send_rest_size > 0)
6706 //change status from SEND_OK to SEND_CONTINUE
6707 it->status = SEND_CONTINUE;
6709 //can not recive from clent continue
6712 //change status from SEND_OK to SEND_END
6713 it->status = SEND_END;
6717 it = recv_data.send_status_list.begin();
6718 it = find_if(it, it_end, data_send_ok());
6719 //send_ok item is exist
6722 status = CLIENT_CONNECTION_CHECK;
6724 //send_ok item is not exist
6728 if (session_data->end_flag == END_FLAG_ON)
6730 status = CLIENT_DISCONNECT;
6736 if (session_data->sorry_flag == SORRY_FLAG_ON)
6738 status = SORRYSERVER_RECV;
6743 status = REALSERVER_RECV;
6750 /*-------- DEBUG LOG --------*/
6751 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6753 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6754 "handle_client_send() : catch exception e = %d. thread id : %d.");
6755 formatter % e % boost::this_thread::get_id();
6756 putLogDebug(100223, formatter.str(), __FILE__, __LINE__ );
6758 /*------DEBUG LOG END------*/
6761 catch (const std::exception& ex)
6763 std::cerr << "protocol_module_sessionless::handle_client_send() : exception : error = " << ex.what() << "." << std::endl;
6764 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6765 "handle_client_send() : exception : error = %s. thread id : %d.");
6766 formatter % ex.what() % boost::this_thread::get_id();
6767 putLogError(100110, formatter.str(), __FILE__, __LINE__ );
6772 std::cerr << "protocol_module_sessionless::handle_client_send() : Unknown exception." << std::endl;
6773 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6774 "handle_client_send() : Unknown exception. thread id : %d.");
6775 formatter % boost::this_thread::get_id();
6776 putLogError(100111, formatter.str(), __FILE__, __LINE__ );
6780 /*-------- DEBUG LOG --------*/
6781 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6783 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6784 "handle_client_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
6785 formatter % status % boost::this_thread::get_id();
6786 putLogDebug(100224, formatter.str(), __FILE__, __LINE__ );
6788 /*------DEBUG LOG END------*/
6793 //! call from client disconnect event. use upstream thread and downstream thread.
6794 //! @param[in] upstream and downstream thread id( check! one thread one event! )
6795 //! @return session use EVENT mode
6796 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_disconnect(
6797 const boost::thread::id thread_id)
6799 /*-------- DEBUG LOG --------*/
6800 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6802 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6803 "handle_client_disconnect(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
6804 formatter % FINALIZE % boost::this_thread::get_id();
6805 putLogDebug(100225, formatter.str(), __FILE__, __LINE__ );
6807 /*------DEBUG LOG END------*/
6811 //! call from sorry mode event. use upstream thread and downstream thread
6812 //! @param[in] upstream and downstream thread id( check! one thread one event and first time call pattern )
6813 //! @return session use EVENT mode
6814 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorry_enable(
6815 const boost::thread::id thread_id)
6817 /*-------- DEBUG LOG --------*/
6818 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6820 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6821 "handle_sorry_enable(const boost::thread::id thread_id) : "
6823 formatter % thread_id;
6824 putLogDebug(100226, formatter.str(), __FILE__, __LINE__ );
6826 /*------DEBUG LOG END------*/
6828 EVENT_TAG status = FINALIZE;
6829 boost::asio::ip::tcp::endpoint endpoint;
6830 bool send_possible = false;
6831 bool send_continue = false;
6832 bool send_disable = false;
6833 thread_data_ptr session_data;
6834 session_thread_data_map_it session_thread_it;
6835 recive_data_map_it recive_data_it;
6840 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
6842 session_thread_it = session_thread_data_map.find(thread_id);
6843 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
6845 boost::format formatter("Invalid thread id. thread id : %d.");
6846 formatter % boost::this_thread::get_id();
6847 putLogError(100112, formatter.str(), __FILE__, __LINE__ );
6851 session_data = session_thread_it->second;
6854 endpoint = session_data->thread_division == THREAD_DIVISION_UP_STREAM ? session_data->client_endpoint_tcp
6855 : session_data->target_endpoint;
6856 recive_data_it = session_data->recive_data_map.find(endpoint);
6857 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
6859 //must be down thread
6860 if (unlikely(session_data->thread_division == THREAD_DIVISION_UP_STREAM))
6862 boost::format formatter("Invalid endpoint. thread id : %d.");
6863 formatter % boost::this_thread::get_id();
6864 putLogError(100113, formatter.str(), __FILE__, __LINE__ );
6867 session_data->sorry_flag = SORRY_FLAG_ON;
6868 /*-------- DEBUG LOG --------*/
6869 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6871 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6872 "handle_sorry_enable() : SORRY_FLAG_ON. thread id : %d.");
6873 formatter % boost::this_thread::get_id();
6874 putLogDebug(100227, formatter.str(), __FILE__, __LINE__ );
6876 /*------DEBUG LOG END------*/
6877 status = SORRYSERVER_RECV;
6881 recive_data& recv_data = recive_data_it->second;
6883 //get this thread sending possible data
6884 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
6885 data_send_possible());
6886 if (it != recv_data.send_status_list.end())
6888 send_possible = true;
6891 it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_continue());
6892 if (it != recv_data.send_status_list.end())
6894 send_continue = true;
6897 it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_disable());
6898 if (it != recv_data.send_status_list.end())
6900 send_disable = true;
6904 if (session_data->thread_division == THREAD_DIVISION_UP_STREAM)
6906 //accept_end_flag is off
6907 if (session_data->accept_end_flag == ACCEPT_END_FLAG_OFF)
6910 session_data->sorry_flag = SORRY_FLAG_ON;
6911 /*-------- DEBUG LOG --------*/
6912 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6914 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6915 "handle_sorry_enable() : SORRY_FLAG_ON. thread id : %d.");
6916 formatter % boost::this_thread::get_id();
6917 putLogDebug(100228, formatter.str(), __FILE__, __LINE__ );
6919 /*------DEBUG LOG END------*/
6922 //accept_end_flag is on
6926 if (session_data->sorry_flag == SORRY_FLAG_ON)
6930 status = SORRYSERVER_CONNECT;
6934 status = SORRYSERVER_SELECT;
6938 //set sorry flag off
6941 //the data that can be sent continue is exist
6945 session_data->end_flag = END_FLAG_ON;
6946 /*-------- DEBUG LOG --------*/
6947 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6949 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6950 "handle_sorry_enable() : END_FLAG_ON. thread id : %d.");
6951 formatter % boost::this_thread::get_id();
6952 putLogDebug(100229, formatter.str(), __FILE__, __LINE__ );
6954 /*------DEBUG LOG END------*/
6955 status = REALSERVER_DISCONNECT;
6957 //the data that can be sent continue is not exist
6960 //set sorryserver_switch_flag on
6961 session_data->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_ON;
6962 /*-------- DEBUG LOG --------*/
6963 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6965 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6966 "handle_sorry_enable() : SORRYSERVER_SWITCH_FLAG_ON. thread id : %d.");
6967 formatter % boost::this_thread::get_id();
6968 putLogDebug(100230, formatter.str(), __FILE__, __LINE__ );
6970 /*------DEBUG LOG END------*/
6972 session_data->sorry_flag = SORRY_FLAG_ON;
6973 /*-------- DEBUG LOG --------*/
6974 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6976 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6977 "handle_sorry_enable() : SORRY_FLAG_ON. thread id : %d.");
6978 formatter % boost::this_thread::get_id();
6979 putLogDebug(100231, formatter.str(), __FILE__, __LINE__ );
6981 /*------DEBUG LOG END------*/
6982 status = REALSERVER_DISCONNECT;
6991 if (session_data->sorry_flag == SORRY_FLAG_ON)
6993 //sending possible data is exist
6996 status = CLIENT_CONNECTION_CHECK;
6998 //sending possible data is not exist
7001 status = SORRYSERVER_RECV;
7008 session_data->sorry_flag = SORRY_FLAG_ON;
7009 /*-------- DEBUG LOG --------*/
7010 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7012 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7013 "handle_sorry_enable() : SORRY_FLAG_ON. thread id : %d.");
7014 formatter % boost::this_thread::get_id();
7015 putLogDebug(100232, formatter.str(), __FILE__, __LINE__ );
7017 /*------DEBUG LOG END------*/
7018 session_data->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_ON;
7019 /*-------- DEBUG LOG --------*/
7020 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7022 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7023 "handle_sorry_enable() : SORRYSERVER_SWITCH_FLAG_ON. thread id : %d.");
7024 formatter % boost::this_thread::get_id();
7025 putLogDebug(100233, formatter.str(), __FILE__, __LINE__ );
7027 /*------DEBUG LOG END------*/
7029 //sending ng data is exist or send_rest_size > 0
7033 session_data->end_flag = END_FLAG_ON;
7034 /*-------- DEBUG LOG --------*/
7035 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7037 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7038 "handle_sorry_enable() : END_FLAG_ON. thread id : %d.");
7039 formatter % boost::this_thread::get_id();
7040 putLogDebug(100234, formatter.str(), __FILE__, __LINE__ );
7042 /*------DEBUG LOG END------*/
7043 status = REALSERVER_DISCONNECT;
7048 //sending possible data is exist
7051 status = CLIENT_CONNECTION_CHECK;
7053 //sending possible data is not exist
7056 status = SORRYSERVER_RECV;
7065 /*-------- DEBUG LOG --------*/
7066 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7068 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7069 "handle_sorry_enable() : catch exception e = %d. thread id : %d.");
7070 formatter % e % boost::this_thread::get_id();
7071 putLogDebug(100235, formatter.str(), __FILE__, __LINE__ );
7073 /*------DEBUG LOG END------*/
7076 catch (const std::exception& ex)
7078 std::cerr << "protocol_module_sessionless::handle_sorry_enable() : exception : error = " << ex.what() << "." << std::endl;
7079 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7080 "handle_sorry_enable() : exception : error = %s. thread id : %d.");
7081 formatter % ex.what() % boost::this_thread::get_id();
7082 putLogError(100114, formatter.str(), __FILE__, __LINE__ );
7087 std::cerr << "protocol_module_sessionless::handle_sorry_enable() : Unknown exception." << std::endl;
7088 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7089 "handle_sorry_enable() : Unknown exception. thread id : %d.");
7090 formatter % boost::this_thread::get_id();
7091 putLogError(100115, formatter.str(), __FILE__, __LINE__ );
7095 /*-------- DEBUG LOG --------*/
7096 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7098 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7099 "handle_sorry_enable(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
7100 formatter % status % boost::this_thread::get_id();
7101 putLogDebug(100236, formatter.str(), __FILE__, __LINE__ );
7103 /*------DEBUG LOG END------*/
7108 //! call from sorry mode disable. use upstream thread and downstream thread.
7109 //! @param[in] upstream and downstream thread id( check! one thread one event )
7110 //! @return session use EVENT mode
7111 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorry_disable(
7112 const boost::thread::id thread_id)
7114 /*-------- DEBUG LOG --------*/
7115 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7117 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7118 "handle_sorry_disable(const boost::thread::id thread_id) : "
7120 formatter % thread_id;
7121 putLogDebug(100237, formatter.str(), __FILE__, __LINE__ );
7123 /*------DEBUG LOG END------*/
7124 EVENT_TAG status = FINALIZE;
7125 boost::asio::ip::tcp::endpoint endpoint;
7126 bool send_possible = false;
7127 bool send_disable = false;
7128 bool send_continue = false;
7129 thread_data_ptr session_data;
7134 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
7136 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
7137 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
7139 boost::format formatter("Invalid thread id. thread id : %d.");
7140 formatter % boost::this_thread::get_id();
7141 putLogError(100116, formatter.str(), __FILE__, __LINE__ );
7145 session_data = session_thread_it->second;
7148 endpoint = session_data->thread_division == THREAD_DIVISION_UP_STREAM ? session_data->client_endpoint_tcp
7149 : session_data->target_endpoint;
7150 recive_data_map_it recive_data_it = session_data->recive_data_map.find(endpoint);
7151 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
7153 //must be down thread
7154 if (unlikely(session_data->thread_division == THREAD_DIVISION_UP_STREAM))
7156 boost::format formatter("Invalid endpoint. thread id : %d.");
7157 formatter % boost::this_thread::get_id();
7158 putLogError(100117, formatter.str(), __FILE__, __LINE__ );
7162 session_data->sorry_flag = SORRY_FLAG_OFF;
7163 /*-------- DEBUG LOG --------*/
7164 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7166 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7167 "handle_sorry_disable() : SORRY_FLAG_OFF. thread id : %d.");
7168 formatter % boost::this_thread::get_id();
7169 putLogDebug(100238, formatter.str(), __FILE__, __LINE__ );
7171 /*------DEBUG LOG END------*/
7172 status = REALSERVER_RECV;
7176 recive_data& recv_data = recive_data_it->second;
7178 //get this thread sending possible data
7179 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
7180 data_send_possible());
7181 if (it != recv_data.send_status_list.end())
7183 send_possible = true;
7186 //sending ng data is exist or send_rest_size > 0
7187 it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_disable());
7188 if (it != recv_data.send_status_list.end())
7190 send_disable = true;
7193 //the data that can be sent continue is exist
7194 it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_continue());
7195 if (it != recv_data.send_status_list.end())
7197 send_continue = true;
7201 if (session_data->thread_division == THREAD_DIVISION_UP_STREAM)
7203 //accept_end_flag is off
7204 if (session_data->accept_end_flag == ACCEPT_END_FLAG_OFF)
7206 //set sorry flag off
7207 session_data->sorry_flag = SORRY_FLAG_OFF;
7208 /*-------- DEBUG LOG --------*/
7209 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7211 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7212 "handle_sorry_disable() : SORRY_FLAG_OFF. thread id : %d.");
7213 formatter % boost::this_thread::get_id();
7214 putLogDebug(100239, formatter.str(), __FILE__, __LINE__ );
7216 /*------DEBUG LOG END------*/
7220 //accept_end_flag is on
7224 if (session_data->sorry_flag == SORRY_FLAG_ON)
7226 //the data that can be sent continue is exist
7230 session_data->end_flag = END_FLAG_ON;
7231 /*-------- DEBUG LOG --------*/
7232 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7234 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7235 "handle_sorry_disable() : END_FLAG_ON. thread id : %d.");
7236 formatter % boost::this_thread::get_id();
7237 putLogDebug(100240, formatter.str(), __FILE__, __LINE__ );
7239 /*------DEBUG LOG END------*/
7240 status = SORRYSERVER_DISCONNECT;
7242 //the data that can be sent continue is not exist
7245 //set realserver_switch_flag on
7246 session_data->realserver_switch_flag = REALSERVER_SWITCH_FLAG_ON;
7247 /*-------- DEBUG LOG --------*/
7248 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7250 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7251 "handle_sorry_disable() : REALSERVER_SWITCH_FLAG_ON. thread id : %d.");
7252 formatter % boost::this_thread::get_id();
7253 putLogDebug(100241, formatter.str(), __FILE__, __LINE__ );
7255 /*------DEBUG LOG END------*/
7256 //set sorry_flag off
7257 session_data->sorry_flag = SORRY_FLAG_OFF;
7258 /*-------- DEBUG LOG --------*/
7259 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7261 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7262 "handle_sorry_disable() : SORRY_FLAG_OFF. thread id : %d.");
7263 formatter % boost::this_thread::get_id();
7264 putLogDebug(100242, formatter.str(), __FILE__, __LINE__ );
7266 /*------DEBUG LOG END------*/
7267 status = SORRYSERVER_DISCONNECT;
7275 status = REALSERVER_CONNECT;
7279 status = REALSERVER_SELECT;
7288 if (session_data->sorry_flag == SORRY_FLAG_ON)
7290 //set sorry_flag off
7291 session_data->sorry_flag = SORRY_FLAG_OFF;
7292 /*-------- DEBUG LOG --------*/
7293 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7295 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7296 "handle_sorry_disable() : SORRY_FLAG_OFF. thread id : %d.");
7297 formatter % boost::this_thread::get_id();
7298 putLogDebug(100243, formatter.str(), __FILE__, __LINE__ );
7300 /*------DEBUG LOG END------*/
7301 session_data->realserver_switch_flag = REALSERVER_SWITCH_FLAG_ON;
7302 /*-------- DEBUG LOG --------*/
7303 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7305 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7306 "handle_sorry_disable() : REALSERVER_SWITCH_FLAG_ON. thread id : %d.");
7307 formatter % boost::this_thread::get_id();
7308 putLogDebug(100244, formatter.str(), __FILE__, __LINE__ );
7310 /*------DEBUG LOG END------*/
7311 //sending ng data is exist or send_rest_size > 0
7315 session_data->end_flag = END_FLAG_ON;
7316 /*-------- DEBUG LOG --------*/
7317 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7319 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7320 "handle_sorry_disable() : END_FLAG_ON. thread id : %d.");
7321 formatter % boost::this_thread::get_id();
7322 putLogDebug(100245, formatter.str(), __FILE__, __LINE__ );
7324 /*------DEBUG LOG END------*/
7325 status = SORRYSERVER_DISCONNECT;
7330 //sending possible data is exist
7333 status = CLIENT_CONNECTION_CHECK;
7335 //sending possible data is not exist
7338 status = REALSERVER_RECV;
7345 //sending possible data is exist
7348 status = CLIENT_CONNECTION_CHECK;
7350 //sending possible data is not exist
7353 status = REALSERVER_RECV;
7363 /*-------- DEBUG LOG --------*/
7364 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7366 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7367 "handle_sorry_disable() : catch exception e = %d. thread id : %d.");
7368 formatter % e % boost::this_thread::get_id();
7369 putLogDebug(100246, formatter.str(), __FILE__, __LINE__ );
7371 /*------DEBUG LOG END------*/
7374 catch (std::exception& ex)
7376 std::cerr << "protocol_module_sessionless::handle_sorry_disable() : exception : error = " << ex.what() << "." << std::endl;
7377 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7378 "handle_sorry_disable() : exception : error = %s. thread id : %d.");
7379 formatter % ex.what() % boost::this_thread::get_id();
7380 putLogError(100118, formatter.str(), __FILE__, __LINE__ );
7385 std::cerr << "protocol_module_sessionless::handle_sorry_disable() : Unknown exception." << std::endl;
7386 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7387 "handle_sorry_disable() : Unknown exception. thread id : %d.");
7388 formatter % boost::this_thread::get_id();
7389 putLogError(100119, formatter.str(), __FILE__, __LINE__ );
7393 /*-------- DEBUG LOG --------*/
7394 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7396 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7397 "handle_sorry_disable(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
7398 formatter % status % boost::this_thread::get_id();
7399 putLogDebug(100247, formatter.str(), __FILE__, __LINE__ );
7401 /*------DEBUG LOG END------*/
7406 //! call from realserver disconnect. use upstream thread and downstream thread
7407 //! @param[in] upstream and downstream thread id( check! one thread one event )
7408 //! @param[in] disconnected realserver endpoint.
7409 //! @return session use EVENT mode
7410 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_disconnect(
7411 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint)
7413 /*-------- DEBUG LOG --------*/
7414 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7416 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7417 "handle_realserver_disconnect(const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint) : "
7418 "thread_id = %d, rs_endpoint = [%s]:%d.");
7419 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
7420 putLogDebug(100248, formatter.str(), __FILE__, __LINE__ );
7422 /*------DEBUG LOG END------*/
7423 EVENT_TAG status = FINALIZE;
7424 bool possible_flag = false;
7425 thread_data_ptr session_data;
7426 boost::asio::ip::tcp::endpoint endpoint;
7431 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
7433 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
7434 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
7436 boost::format formatter("Invalid thread id. thread id : %d.");
7437 formatter % boost::this_thread::get_id();
7438 putLogError(100120, formatter.str(), __FILE__, __LINE__ );
7442 session_data = session_thread_it->second;
7445 endpoint = session_data->thread_division == THREAD_DIVISION_UP_STREAM ? session_data->client_endpoint_tcp
7446 : session_data->target_endpoint;
7447 recive_data_map_it recive_data_it = session_data->recive_data_map.find(endpoint);
7448 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
7450 boost::format formatter("Invalid endpoint. thread id : %d.");
7451 formatter % boost::this_thread::get_id();
7452 putLogError(100121, formatter.str(), __FILE__, __LINE__ );
7456 recive_data& recv_data = recive_data_it->second;
7458 //the data that can be sent possible is exist
7459 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
7460 data_send_possible());
7461 if (it != recv_data.send_status_list.end())
7463 possible_flag = true;
7467 if (session_data->thread_division == THREAD_DIVISION_UP_STREAM)
7470 if (session_data->end_flag == END_FLAG_ON)
7472 status = CLIENT_RECV;
7477 //sorryserver_switch_flag is on
7478 if (session_data->sorryserver_switch_flag == SORRYSERVER_SWITCH_FLAG_ON)
7480 session_data->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_OFF;
7481 /*-------- DEBUG LOG --------*/
7482 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7484 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7485 "handle_realserver_disconnect() : SORRYSERVER_SWITCH_FLAG_OFF. thread id : %d.");
7486 formatter % boost::this_thread::get_id();
7487 putLogDebug(100249, formatter.str(), __FILE__, __LINE__ );
7489 /*------DEBUG LOG END------*/
7491 status = SORRYSERVER_SELECT;
7494 //sorryserver_switch_flag is off
7498 session_data->end_flag = END_FLAG_ON;
7499 /*-------- DEBUG LOG --------*/
7500 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7502 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7503 "handle_realserver_disconnect() : END_FLAG_ON. thread id : %d.");
7504 formatter % boost::this_thread::get_id();
7505 putLogDebug(100250, formatter.str(), __FILE__, __LINE__ );
7507 /*------DEBUG LOG END------*/
7508 status = CLIENT_RECV;
7515 if (session_data->end_flag == END_FLAG_ON)
7517 status = CLIENT_DISCONNECT;
7521 if (session_data->sorryserver_switch_flag == SORRYSERVER_SWITCH_FLAG_ON)
7523 session_data->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_OFF;
7524 /*-------- DEBUG LOG --------*/
7525 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7527 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7528 "handle_realserver_disconnect() : SORRYSERVER_SWITCH_FLAG_OFF. thread id : %d.");
7529 formatter % boost::this_thread::get_id();
7530 putLogDebug(100251, formatter.str(), __FILE__, __LINE__ );
7532 /*------DEBUG LOG END------*/
7533 status = SORRYSERVER_RECV;
7538 session_data->end_flag = END_FLAG_ON;
7539 /*-------- DEBUG LOG --------*/
7540 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7542 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7543 "handle_realserver_disconnect() : END_FLAG_ON. thread id : %d.");
7544 formatter % boost::this_thread::get_id();
7545 putLogDebug(100252, formatter.str(), __FILE__, __LINE__ );
7547 /*------DEBUG LOG END------*/
7548 status = CLIENT_DISCONNECT;
7552 //the data that can be sent possible is exist
7555 status = CLIENT_CONNECTION_CHECK;
7561 /*-------- DEBUG LOG --------*/
7562 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7564 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7565 "handle_realserver_disconnect() : catch exception e = %d. thread id : %d.");
7566 formatter % e % boost::this_thread::get_id();
7567 putLogDebug(100253, formatter.str(), __FILE__, __LINE__ );
7569 /*------DEBUG LOG END------*/
7572 catch (std::exception& ex)
7574 std::cerr << "protocol_module_sessionless::handle_realserver_disconnect() : exception: error = " << ex.what() << "." << std::endl;
7575 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7576 "handle_realserver_disconnect() : exception : error = %s. thread id : %d.");
7577 formatter % ex.what() % boost::this_thread::get_id();
7578 putLogError(100122, formatter.str(), __FILE__, __LINE__ );
7583 std::cerr << "protocol_module_sessionless::handle_realserver_disconnect() : Unknown exception." << std::endl;
7584 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7585 "handle_realserver_disconnect() : Unknown exception. thread id : %d.");
7586 formatter % boost::this_thread::get_id();
7587 putLogError(100123, formatter.str(), __FILE__, __LINE__ );
7591 /*-------- DEBUG LOG --------*/
7592 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7594 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7595 "handle_realserver_disconnect(const boost::thread::id thread_id, "
7596 "const boost::asio::ip::tcp::endpoint & rs_endpoint) : return_value = %d. thread id : %d.");
7597 formatter % status % boost::this_thread::get_id();
7598 putLogDebug(100254, formatter.str(), __FILE__, __LINE__ );
7600 /*------DEBUG LOG END------*/
7605 //! call from sorry server disconnect. use upstraem thread and downstream thread
7606 //! @param[in] upstream and downstream thread id( check! one thread one event )
7607 //! @param[in] disconnect sorryserver endpoint
7608 //! @return session use EVENT mode
7609 //! @return session use EVENT mode
7610 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_disconnect(
7611 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint)
7613 /*-------- DEBUG LOG --------*/
7614 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7618 "in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7619 "handle_sorryserver_disconnect(const boost::thread::id thread_id, "
7620 "const boost::asio::ip::tcp::endpoint & sorry_endpoint) : "
7621 "thread_id = %d, sorry_endpoint = [%s]:%d.");
7622 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port() ;
7623 putLogDebug(100255, formatter.str(), __FILE__, __LINE__ );
7625 /*------DEBUG LOG END------*/
7626 EVENT_TAG status = FINALIZE;
7627 bool possible_flag = false;
7628 thread_data_ptr session_data;
7629 boost::asio::ip::tcp::endpoint endpoint;
7634 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
7636 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
7637 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
7639 boost::format formatter("Invalid thread id. thread id : %d.");
7640 formatter % boost::this_thread::get_id();
7641 putLogError(100124, formatter.str(), __FILE__, __LINE__ );
7645 session_data = session_thread_it->second;
7648 endpoint = session_data->thread_division == THREAD_DIVISION_UP_STREAM ? session_data->client_endpoint_tcp
7649 : session_data->target_endpoint;
7650 recive_data_map_it recive_data_it = session_data->recive_data_map.find(endpoint);
7651 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
7653 boost::format formatter("Invalid endpoint. thread id : %d.");
7654 formatter % boost::this_thread::get_id();
7655 putLogError(100125, formatter.str(), __FILE__, __LINE__ );
7659 recive_data& recv_data = recive_data_it->second;
7661 //the data that can be sent possible is exist
7662 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
7663 data_send_possible());
7664 if (it != recv_data.send_status_list.end())
7666 possible_flag = true;
7670 if (session_data->thread_division == THREAD_DIVISION_UP_STREAM)
7673 if (session_data->end_flag == END_FLAG_ON)
7675 status = CLIENT_RECV;
7680 //realserver_switch_flag is on
7681 if (session_data->realserver_switch_flag == REALSERVER_SWITCH_FLAG_ON)
7683 session_data->realserver_switch_flag = REALSERVER_SWITCH_FLAG_OFF;
7684 /*-------- DEBUG LOG --------*/
7685 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7687 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7688 "handle_sorryserver_disconnect() : REALSERVER_SWITCH_FLAG_OFF. thread id : %d.");
7689 formatter % boost::this_thread::get_id();
7690 putLogDebug(100256, formatter.str(), __FILE__, __LINE__ );
7692 /*------DEBUG LOG END------*/
7693 status = REALSERVER_SELECT;
7695 //realserver_switch_flag is off
7699 session_data->end_flag = END_FLAG_ON;
7700 /*-------- DEBUG LOG --------*/
7701 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7703 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7704 "handle_sorryserver_disconnect() : END_FLAG_ON. thread id : %d.");
7705 formatter % boost::this_thread::get_id();
7706 putLogDebug(100257, formatter.str(), __FILE__, __LINE__ );
7708 /*------DEBUG LOG END------*/
7709 status = CLIENT_RECV;
7716 if (session_data->end_flag == END_FLAG_ON)
7718 status = CLIENT_DISCONNECT;
7722 if (session_data->realserver_switch_flag == REALSERVER_SWITCH_FLAG_ON)
7724 session_data->realserver_switch_flag = REALSERVER_SWITCH_FLAG_OFF;
7725 /*-------- DEBUG LOG --------*/
7726 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7728 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7729 "handle_sorryserver_disconnect() : REALSERVER_SWITCH_FLAG_OFF. thread id : %d.");
7730 formatter % boost::this_thread::get_id();
7731 putLogDebug(100258, formatter.str(), __FILE__, __LINE__ );
7733 /*------DEBUG LOG END------*/
7734 status = REALSERVER_RECV;
7738 session_data->end_flag = END_FLAG_ON;
7739 /*-------- DEBUG LOG --------*/
7740 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7742 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7743 "handle_sorryserver_disconnect() : END_FLAG_ON. thread id : %d.");
7744 formatter % boost::this_thread::get_id();
7745 putLogDebug(100259, formatter.str(), __FILE__, __LINE__ );
7747 /*------DEBUG LOG END------*/
7748 status = CLIENT_DISCONNECT;
7752 //the data that can be sent possible is exist
7755 status = CLIENT_CONNECTION_CHECK;
7761 /*-------- DEBUG LOG --------*/
7762 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7764 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7765 "handle_sorryserver_disconnect() : catch exception e = %d. thread id : %d.");
7766 formatter % e % boost::this_thread::get_id();
7767 putLogDebug(100260, formatter.str(), __FILE__, __LINE__ );
7769 /*------DEBUG LOG END------*/
7772 catch (const std::exception& ex)
7774 std::cerr << "protocol_module_sessionless::handle_sorryserver_disconnect() : exception : error = " << ex.what() << "." << std::endl;
7775 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7776 "handle_sorryserver_disconnect() : exception : error = %s. thread id : %d.");
7777 formatter % ex.what() % boost::this_thread::get_id();
7778 putLogError(100126, formatter.str(), __FILE__, __LINE__ );
7783 std::cerr << "protocol_module_sessionless::handle_sorryserver_disconnect() : Unknown exception." << std::endl;
7784 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7785 "handle_sorryserver_disconnect() : Unknown exception. thread id : %d.");
7786 formatter % boost::this_thread::get_id();
7787 putLogError(100127, formatter.str(), __FILE__, __LINE__ );
7791 /*-------- DEBUG LOG --------*/
7792 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7796 "out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7797 "handle_sorryserver_disconnect(const boost::thread::id thread_id, "
7798 "const boost::asio::ip::tcp::endpoint& sorry_endpoint) : return_value = %d. thread id : %d.");
7799 formatter % status % boost::this_thread::get_id();
7800 putLogDebug(100261, formatter.str(), __FILE__, __LINE__ );
7802 /*------DEBUG LOG END------*/
7807 //! call from realserver disconnect. use upstream thread and downstream thread.
7808 //! @param[in] upstream and downstream thread id( check! one thread one event )
7809 //! @param[in] disconnect realserver endpoint
7810 //! @return session use EVENT mode.
7811 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_close(
7812 const boost::thread::id thread_id, const boost::asio::ip::udp::endpoint & rs_endpoint)
7814 /*-------- DEBUG LOG --------*/
7815 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7817 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7818 "handle_realserver_close(const boost::thread::id thread_id, "
7819 "const boost::asio::ip::udp::endpoint & rs_endpoint) : "
7820 "return_value = %d. thread id : %d.");
7821 formatter % STOP % boost::this_thread::get_id();
7822 putLogDebug(100262, formatter.str(), __FILE__, __LINE__ );
7824 /*------DEBUG LOG END------*/
7830 extern "C" l7vs::protocol_module_base*
7833 return dynamic_cast<l7vs::protocol_module_base*>(new l7vs::protocol_module_sessionless());
7837 destroy_module( l7vs::protocol_module_base* in )