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_cr_lf_len = strlen("\r\n\r\n");
1171 const size_t cr_lf_len = strlen("\r\n");
1172 std::string str_value;
1173 const std::string http_header = "";
1174 const std::string content_header = "Content-Length";
1175 thread_data_ptr session_data;
1176 char* buffer1 = NULL;
1177 char* buffer2 = NULL;
1179 CHECK_RESULT_TAG check_result;
1180 session_thread_data_map_it session_thread_it;
1181 recive_data_map_it recive_data_it;
1184 if (recvlen > recvbuffer.size())
1186 std::cerr << "protocol_module_sessionless::handle_client_recv() : Data size bigger than buffer size." << std::endl;
1187 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
1188 formatter % boost::this_thread::get_id();
1189 putLogError(100025, formatter.str(), __FILE__, __LINE__ );
1190 /*-------- DEBUG LOG --------*/
1191 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1193 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1194 "handle_client_recv(const boost::thread::id thread_id, "
1195 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1196 "const size_t recvlen) : return_value = %d. thread id : %d.");
1197 formatter % FINALIZE % boost::this_thread::get_id();
1198 putLogDebug(100039, formatter.str(), __FILE__, __LINE__ );
1200 /*------DEBUG LOG END------*/
1207 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
1209 session_thread_it = session_thread_data_map.find(thread_id);
1210 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
1212 boost::format formatter("Invalid thread id. thread id : %d.");
1213 formatter % boost::this_thread::get_id();
1214 putLogError(100026, formatter.str(), __FILE__, __LINE__ );
1218 session_data = session_thread_it->second;
1222 if (session_data->end_flag == END_FLAG_ON)
1224 status = CLIENT_RECV;
1229 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
1230 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
1232 boost::format formatter("Invalid endpoint. thread id : %d.");
1233 formatter % boost::this_thread::get_id();
1234 putLogError(100027, formatter.str(), __FILE__, __LINE__ );
1238 recive_data& recv_data = recive_data_it->second;
1240 send_status_it it = recv_data.send_status_list.begin();
1241 send_status_it it_end = recv_data.send_status_list.end();
1244 it = std::find_if(it, it_end, data_send_ok());
1245 if (unlikely(it != it_end))
1247 boost::format formatter("Sending data is not correct. thread id : %d.");
1248 formatter % boost::this_thread::get_id();
1249 putLogError(100028, formatter.str(), __FILE__, __LINE__ );
1254 it = recv_data.send_status_list.begin();
1255 it = std::adjacent_find(it, it_end, data_send_repeated());
1256 if (unlikely(it != it_end))
1258 boost::format formatter("Sending data is not correct. thread id : %d.");
1259 formatter % boost::this_thread::get_id();
1260 putLogError(100029, formatter.str(), __FILE__, __LINE__ );
1264 /*-------- DEBUG LOG --------*/
1265 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1267 std::string datadump;
1268 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
1269 "send_rest_size = %d, send_possible_size = %d, "
1270 "send_offset = %d, unsend_size = %d, edit_division = %d.");
1272 for (it = recv_data.send_status_list.begin();
1273 it != recv_data.send_status_list.end();
1276 formatter % i % it->status % it->send_end_size
1277 % it->send_rest_size % it->send_possible_size
1278 % it->send_offset % it->unsend_size % it->edit_division;
1279 datadump += formatter.str();
1282 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1283 "handle_client_recv() : send status list dump : send status list size = %d.%s");
1285 formatter % recv_data.send_status_list.size() % datadump;
1286 putLogDebug(100040, formatter.str(), __FILE__, __LINE__ );
1288 /*------DEBUG LOG END------*/
1290 it = recv_data.send_status_list.begin();
1291 //get original status info
1292 while (it != it_end)
1294 //item status is SEND_END
1295 if (it->status == SEND_END)
1298 recv_data.send_status_list.erase(it++);
1301 //item status is SEND_CONTINUE
1302 else if (it->status == SEND_CONTINUE)
1304 it->send_offset += it->send_end_size;
1305 data_remain_start = it->send_offset;
1308 //item status is SEND_NG
1311 data_remain_start = it->send_offset;
1312 data_remain_size = it->unsend_size;
1318 /*-------- DEBUG LOG --------*/
1319 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1321 std::string datadump;
1322 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
1323 "send_rest_size = %d, send_possible_size = %d, "
1324 "send_offset = %d, unsend_size = %d, edit_division = %d.");
1326 for (it = recv_data.send_status_list.begin();
1327 it != recv_data.send_status_list.end();
1330 formatter % i % it->status % it->send_end_size
1331 % it->send_rest_size % it->send_possible_size
1332 % it->send_offset % it->unsend_size % it->edit_division;
1333 datadump += formatter.str();
1336 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1337 "handle_client_recv() : send status list dump : send status list size = %d.%s");
1339 formatter % recv_data.send_status_list.size() % datadump;
1340 putLogDebug(100041, formatter.str(), __FILE__, __LINE__ );
1342 /*------DEBUG LOG END------*/
1344 //recive buffer process
1345 //buffer rest size < request size
1346 if (recv_data.recive_buffer_rest_size < recvlen)
1348 //buffer max size < remain size + request size
1349 //buffer is need reallocate
1350 if (recv_data.recive_buffer_max_size < data_remain_size + recvlen)
1352 //the buffer's size that will be allocated is exceed the upper limit value
1353 if (MAX_SESSIONLESS_MODULE_BUFFER_SIZE < data_remain_size + recvlen)
1355 std::cerr << "protocol_module_sessionless::handle_client_recv() : the buffer's size that will be allacted is exceed the upper limit value." << std::endl;
1356 boost::format formatter("The buffer's size that will be allocated is exceed the upper limit value. thread id : %d.");
1357 formatter % boost::this_thread::get_id();
1358 putLogError(100030, formatter.str(), __FILE__, __LINE__ );
1359 /*-------- DEBUG LOG --------*/
1360 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1362 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1363 "handle_client_recv(const boost::thread::id thread_id, "
1364 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1365 "const size_t recvlen) : return_value = %d. thread id : %d.");
1366 formatter % FINALIZE % boost::this_thread::get_id();
1367 putLogDebug(100042, formatter.str(), __FILE__, __LINE__ );
1369 /*------DEBUG LOG END------*/
1373 buffer_size = (data_remain_size + recvlen) > MAX_BUFFER_SIZE ? (data_remain_size + recvlen) : MAX_BUFFER_SIZE;
1374 //recive_buffer1's memory allocate and initialization
1375 buffer1 = new char[buffer_size];
1376 /*-------- DEBUG LOG --------*/
1377 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1379 boost::format formatter("new : address = &(%d), size = %lu.");
1380 formatter % static_cast<void*>(buffer1) % buffer_size;
1381 putLogDebug(100043, formatter.str(), __FILE__, __LINE__ );
1383 /*------DEBUG LOG END------*/
1384 memset(buffer1, 0, buffer_size);
1385 //recive_buffer2's memory allocate and initialization
1386 buffer2 = new char[buffer_size];
1387 /*-------- DEBUG LOG --------*/
1388 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1390 boost::format formatter("new : address = &(%d), size = %lu.");
1391 formatter % static_cast<void*>(buffer2) % buffer_size;
1392 putLogDebug(100044, formatter.str(), __FILE__, __LINE__ );
1394 /*------DEBUG LOG END------*/
1395 memset(buffer2, 0, buffer_size);
1397 /*-------- DEBUG LOG --------*/
1398 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1400 std::string datadump;
1401 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
1402 boost::format formatter(
1403 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1404 "handle_client_recv() : before memcpy (data dump) : "
1405 "data begin = %d, data_size = %d, data = %s");
1406 formatter % data_remain_start % data_remain_size % datadump;
1407 putLogDebug(100045, formatter.str(), __FILE__, __LINE__ );
1409 /*------DEBUG LOG END------*/
1410 //copy data from old buffer to new buffer
1411 memcpy(buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
1412 /*-------- DEBUG LOG --------*/
1413 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1415 std::string datadump;
1416 dump_memory(buffer1, data_remain_size, datadump);
1417 boost::format formatter(
1418 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1419 "handle_client_recv() : after memcpy (data dump) : "
1420 "data begin = 0, data_size = %d, data = %s");
1421 formatter % data_remain_size % datadump;
1422 putLogDebug(100046, formatter.str(), __FILE__, __LINE__ );
1424 /*------DEBUG LOG END------*/
1426 /*-------- DEBUG LOG --------*/
1427 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1429 std::string datadump;
1430 dump_memory(recvbuffer.data(), recvlen, datadump);
1431 boost::format formatter(
1432 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1433 "handle_client_recv() : before memcpy (data dump) : "
1434 "data begin = 0, data_size = %d, data = %s");
1435 formatter % recvlen % datadump;
1436 putLogDebug(100047, formatter.str(), __FILE__, __LINE__ );
1438 /*------DEBUG LOG END------*/
1439 memcpy(buffer1 + data_remain_size, recvbuffer.data(), recvlen);
1440 /*-------- DEBUG LOG --------*/
1441 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1443 std::string datadump;
1444 dump_memory(buffer1 + data_remain_size, recvlen, datadump);
1445 boost::format formatter(
1446 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1447 "handle_client_recv() : after memcpy (data dump) : "
1448 "data begin = %d, data_size = %d, data = %s");
1449 formatter % data_remain_size % recvlen % datadump;
1450 putLogDebug(100048, formatter.str(), __FILE__, __LINE__ );
1452 /*------DEBUG LOG END------*/
1453 //free old buffer1 and old buffer2
1454 if (recv_data.recive_buffer1 != NULL)
1456 /*-------- DEBUG LOG --------*/
1457 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1459 boost::format formatter("delete : address = &(%d).");
1460 formatter % static_cast<void*>(recv_data.recive_buffer1);
1461 putLogDebug(100049, formatter.str(), __FILE__,
1464 /*------DEBUG LOG END------*/
1465 delete[] recv_data.recive_buffer1;
1466 recv_data.recive_buffer1 = NULL;
1469 if (recv_data.recive_buffer2 != NULL)
1471 /*-------- DEBUG LOG --------*/
1472 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1474 boost::format formatter("delete : address = &(%d).");
1475 formatter % static_cast<void*>(recv_data.recive_buffer2);
1476 putLogDebug(100050, formatter.str(), __FILE__,
1479 /*------DEBUG LOG END------*/
1480 delete[] recv_data.recive_buffer2;
1481 recv_data.recive_buffer2 = NULL;
1484 //set new buffer pointer
1485 recv_data.recive_buffer1 = buffer1;
1486 recv_data.recive_buffer2 = buffer2;
1487 recv_data.recive_buffer = recv_data.recive_buffer1;
1488 //set new buffer's max size
1489 recv_data.recive_buffer_max_size = buffer_size;
1491 //buffer's max size >= remain data size + requst size
1492 //buffer isn't need reallocate, but switch
1495 //pointer valid check
1496 if (unlikely(recv_data.recive_buffer1 == NULL || recv_data.recive_buffer2 == NULL))
1498 boost::format formatter("Invalid pointer. thread id : %d.");
1499 formatter % boost::this_thread::get_id();
1500 putLogError(100031, formatter.str(), __FILE__, __LINE__ );
1503 //using buffer is buffer1
1504 if (recv_data.recive_buffer == recv_data.recive_buffer1)
1506 //buffer2 initialization
1507 memset(recv_data.recive_buffer2, 0, recv_data.recive_buffer_max_size);
1508 /*-------- DEBUG LOG --------*/
1509 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1511 std::string datadump;
1512 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
1513 boost::format formatter(
1514 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1515 "handle_client_recv() : before memcpy (data dump) : "
1516 "data begin = %d, data_size = %d, data = %s");
1517 formatter % data_remain_start % data_remain_size % datadump;
1518 putLogDebug(100051, formatter.str(), __FILE__, __LINE__ );
1520 /*------DEBUG LOG END------*/
1521 //copy data from buffer1 to buffer2
1522 memcpy(recv_data.recive_buffer2, recv_data.recive_buffer + data_remain_start, data_remain_size);
1523 /*-------- DEBUG LOG --------*/
1524 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1526 std::string datadump;
1527 dump_memory(recv_data.recive_buffer2, recvlen, datadump);
1528 boost::format formatter(
1529 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1530 "handle_client_recv() : after memcpy (data dump) : "
1531 "data begin = 0, data_size = %d, data = %s");
1532 formatter % recvlen % datadump;
1533 putLogDebug(100052, formatter.str(), __FILE__, __LINE__ );
1535 /*------DEBUG LOG END------*/
1536 /*-------- DEBUG LOG --------*/
1537 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1539 std::string datadump;
1540 dump_memory(recvbuffer.data(), recvlen, datadump);
1541 boost::format formatter(
1542 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1543 "handle_client_recv() : before memcpy (data dump) : "
1544 "data begin = 0, data_size = %d, data = %s");
1545 formatter % recvlen % datadump;
1546 putLogDebug(100053, formatter.str(), __FILE__, __LINE__ );
1548 /*------DEBUG LOG END------*/
1549 memcpy(recv_data.recive_buffer2 + data_remain_size, recvbuffer.data(), recvlen);
1550 /*-------- DEBUG LOG --------*/
1551 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1553 std::string datadump;
1554 dump_memory(recv_data.recive_buffer2 + data_remain_size, recvlen, datadump);
1555 boost::format formatter(
1556 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1557 "handle_client_recv() : after memcpy (data dump) : "
1558 "data begin = %d, data_size = %d, data = %s");
1559 formatter % data_remain_size % recvlen % datadump;
1560 putLogDebug(100054, formatter.str(), __FILE__, __LINE__ );
1562 /*------DEBUG LOG END------*/
1563 //set buffer2 as using buffer
1564 recv_data.recive_buffer = recv_data.recive_buffer2;
1566 //using buffer is buffer2
1569 //buffer1 initializtion
1570 memset(recv_data.recive_buffer1, 0, recv_data.recive_buffer_max_size);
1571 /*-------- DEBUG LOG --------*/
1572 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1574 std::string datadump;
1575 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
1576 boost::format formatter(
1577 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1578 "handle_client_recv() : before memcpy (data dump) : "
1579 "data begin = %d, data_size = %d, data = %s");
1580 formatter % data_remain_start % data_remain_size % datadump;
1581 putLogDebug(100055, formatter.str(), __FILE__, __LINE__ );
1583 /*------DEBUG LOG END------*/
1584 //copy data from buffer2 to buffer1
1585 memcpy(recv_data.recive_buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
1586 /*-------- DEBUG LOG --------*/
1587 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1589 std::string datadump;
1590 dump_memory(recv_data.recive_buffer1, data_remain_size, datadump);
1591 boost::format formatter(
1592 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1593 "handle_client_recv() : after memcpy (data dump) : "
1594 "data begin = 0, data_size = %d, data = %s");
1595 formatter % data_remain_size % datadump;
1596 putLogDebug(100056, formatter.str(), __FILE__, __LINE__ );
1598 /*------DEBUG LOG END------*/
1599 /*-------- DEBUG LOG --------*/
1600 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1602 std::string datadump;
1603 dump_memory(recvbuffer.data(), recvlen, datadump);
1604 boost::format formatter(
1605 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1606 "handle_client_recv() : before memcpy (data dump) : "
1607 "data begin = 0, data_size = %d, data = %s");
1608 formatter % recvlen % datadump;
1609 putLogDebug(100057, formatter.str(), __FILE__, __LINE__ );
1611 /*------DEBUG LOG END------*/
1612 memcpy(recv_data.recive_buffer1 + data_remain_size, recvbuffer.data(), recvlen);
1613 /*-------- DEBUG LOG --------*/
1614 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1616 std::string datadump;
1617 dump_memory(recv_data.recive_buffer1 + data_remain_size, recvlen, datadump);
1618 boost::format formatter(
1619 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1620 "handle_client_recv() : after memcpy (data dump) : "
1621 "data begin = %d, data_size = %d, data = %s");
1622 formatter % data_remain_size % recvlen % datadump;
1623 putLogDebug(100058, formatter.str(), __FILE__, __LINE__ );
1625 /*------DEBUG LOG END------*/
1626 //set buffer1 as using buffer
1627 recv_data.recive_buffer = recv_data.recive_buffer1;
1631 //set buffer's rest size
1632 recv_data.recive_buffer_rest_size = recv_data.recive_buffer_max_size - data_remain_size - recvlen;
1634 //remain_size recalc
1635 data_remain_size += recvlen;
1637 send_status_it it_begin = recv_data.send_status_list.begin();
1638 send_status_it it_end = recv_data.send_status_list.end();
1641 for (; it_begin != it_end; ++it_begin)
1643 it_begin->send_offset -= data_remain_start;
1646 //buffer's rest size >= request size
1649 //pointer valid check
1650 if (unlikely(recv_data.recive_buffer == NULL))
1652 boost::format formatter("Invalid pointer. thread id : %d.");
1653 formatter % boost::this_thread::get_id();
1654 putLogError(100032, formatter.str(), __FILE__, __LINE__ );
1657 /*-------- DEBUG LOG --------*/
1658 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1660 std::string datadump;
1661 dump_memory(recvbuffer.data(), recvlen, datadump);
1662 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1663 "handle_client_recv() : before memcpy (data dump) : "
1664 "data begin = 0, data_size = %d, data = %s");
1665 formatter % recvlen % datadump;
1666 putLogDebug(100059, formatter.str(), __FILE__, __LINE__ );
1668 /*------DEBUG LOG END------*/
1669 //copy data from parameter to using buffer
1670 memcpy(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
1671 recvbuffer.data(), recvlen);
1672 /*-------- DEBUG LOG --------*/
1673 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1675 std::string datadump;
1676 dump_memory(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
1678 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1679 "handle_client_recv() : after memcpy (data dump) : "
1680 "data begin = %d, data_size = %d, data = %s");
1681 formatter % (recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size )
1682 % recvlen % datadump;
1683 putLogDebug(100060, formatter.str(), __FILE__, __LINE__ );
1685 /*------DEBUG LOG END------*/
1686 //buffer's rest size recalc
1687 recv_data.recive_buffer_rest_size -= recvlen;
1688 //remain data size recalc
1689 data_remain_size += recvlen;
1692 it = recv_data.send_status_list.begin();
1693 it_end = recv_data.send_status_list.end();
1695 //set request rest size
1696 request_data_remain_size = recvlen;
1698 //original status process
1699 for (; it != it_end; ++it)
1701 //status is SEND_CONTINUE
1702 if (it->status == SEND_CONTINUE)
1704 //send rest size > request size
1705 if (it->send_rest_size > request_data_remain_size)
1707 //send possible size recalc
1708 it->send_possible_size = request_data_remain_size;
1709 //send rest size recalc
1710 it->send_rest_size -= request_data_remain_size;
1711 //send end size recalc
1712 it->send_end_size = 0;
1713 //request size recalc
1714 request_data_remain_size = 0;
1716 //send rest size <= request size
1719 //send possible size recalc
1720 it->send_possible_size = it->send_rest_size;
1721 //send rest size recalc
1722 request_data_remain_size -= it->send_rest_size;
1723 //send end size recalc
1724 it->send_end_size = 0;
1725 //request size recalc
1726 it->send_rest_size = 0;
1728 //set edit_division flag off
1729 it->edit_division = EDIT_DIVISION_NO_EDIT;
1730 //set status SEND_OK
1731 it->status = SEND_OK;
1734 else if (it->status == SEND_NG)
1737 check_result = check_http_method(recv_data.recive_buffer + it->send_offset, data_remain_size);
1738 /*-------- DEBUG LOG --------*/
1739 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1741 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1742 "handle_client_recv() : call check_http_method : "
1743 "return_value = %d. thread id : %d.");
1744 formatter % check_result % boost::this_thread::get_id();
1745 putLogDebug(100061, formatter.str(), __FILE__, __LINE__ );
1747 /*------DEBUG LOG END------*/
1748 //check http method result is OK
1749 if (check_result == CHECK_OK)
1751 //check http version
1752 check_result = check_http_version(recv_data.recive_buffer + it->send_offset, data_remain_size);
1753 /*-------- DEBUG LOG --------*/
1754 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1756 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1757 "handle_client_recv() : call check_http_version : "
1758 "return_value = %d. thread id : %d.");
1759 formatter % check_result % boost::this_thread::get_id();
1760 putLogDebug(100062, formatter.str(), __FILE__, __LINE__ );
1762 /*------DEBUG LOG END------*/
1764 //check method and version result is OK
1765 if (check_result == CHECK_OK)
1767 //search http header
1768 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size, http_header,
1769 header_offset, header_offset_len);
1770 /*-------- DEBUG LOG --------*/
1771 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1773 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1774 "handle_client_recv() : call find_http_header : "
1775 "return_value = %d. thread id : %d.");
1776 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
1777 putLogDebug(100063, formatter.str(), __FILE__, __LINE__ );
1779 /*------DEBUG LOG END------*/
1780 //search http header result is OK
1783 //search Content_Length header
1784 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size,
1785 content_header, content_length_header_offset, content_length_header_len);
1786 /*-------- DEBUG LOG --------*/
1787 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1789 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1790 "handle_client_recv() : call find_http_header : "
1791 "return_value = %d. thread id : %d.");
1792 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
1793 putLogDebug(100064, formatter.str(), __FILE__, __LINE__ );
1795 /*------DEBUG LOG END------*/
1796 //search Content_Length result is OK
1799 //Get Content_Length header's numeric value
1800 for (pos = 0; recv_data.recive_buffer[it->send_offset + content_length_header_offset + pos] != ':' && pos
1801 < content_length_header_len; ++pos)
1803 if (pos == content_length_header_len)
1805 throw std::string("Content_Length field's value is invalid.");
1810 str_value.assign(recv_data.recive_buffer + it->send_offset + content_length_header_offset + pos,
1811 content_length_header_len - pos);
1813 size_t pos_end = str_value.find_last_of('\r');
1814 if (pos_end != std::string::npos)
1816 str_value = str_value.erase(pos_end);
1819 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos);
1821 str_value = str_value.substr(pos);
1825 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
1827 catch (const boost::bad_lexical_cast& ex)
1829 throw std::string("Content_Length field's value is invalid.");
1832 //send_rest_size recalc
1833 //set whole http header's length + Content_Length's value
1834 it->send_rest_size = header_offset + header_offset_len + cr_lf_cr_lf_len + content_len_value;
1836 //search Content_Length result is NG
1839 //send_rest_size recalc
1840 //set whole http header's length
1841 if (header_offset_len == 0)
1843 it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
1846 it->send_rest_size = header_offset + header_offset_len + cr_lf_cr_lf_len;
1849 //set edit_division flag on
1850 it->edit_division = EDIT_DIVISION_EDIT;
1852 //search http header result is NG
1855 //unsend_size recalc
1856 it->unsend_size += request_data_remain_size;
1857 //request data rest size recalc
1858 request_data_remain_size = 0;
1862 //check method and version result is NG
1863 else if (check_result == CHECK_NG)
1865 //set edit_division flag off
1866 it->edit_division = EDIT_DIVISION_NO_EDIT;
1867 //send_rest_size recalc
1868 it->send_rest_size = it->unsend_size + request_data_remain_size;
1870 //check method and version result is CHECK_INPOSSIBLE
1873 //unsend_size recalc
1874 it->unsend_size += request_data_remain_size;
1875 //request data rest size recalc
1876 request_data_remain_size = 0;
1880 //recalc fields value according to send_rest_size and request rest size
1881 if (it->send_rest_size > it->unsend_size + request_data_remain_size)
1883 it->send_possible_size = it->unsend_size + request_data_remain_size;
1884 it->send_rest_size -= (it->unsend_size + request_data_remain_size);
1885 it->send_end_size = 0;
1886 it->unsend_size = 0;
1887 request_data_remain_size = 0;
1891 it->send_possible_size = it->send_rest_size;
1892 request_data_remain_size = it->unsend_size + request_data_remain_size - it->send_rest_size;
1893 it->send_end_size = 0;
1894 it->unsend_size = 0;
1895 it->send_rest_size = 0;
1898 //change status from SEND_NG to SEND_OK
1899 it->status = SEND_OK;
1901 //no request rest data to process
1902 if (request_data_remain_size <= 0)
1907 /*-------- DEBUG LOG --------*/
1908 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1910 std::string datadump;
1911 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
1912 "send_rest_size = %d, send_possible_size = %d, "
1913 "send_offset = %d, unsend_size = %d, edit_division = %d.");
1915 for (it = recv_data.send_status_list.begin();
1916 it != recv_data.send_status_list.end();
1919 formatter % i % it->status % it->send_end_size
1920 % it->send_rest_size % it->send_possible_size
1921 % it->send_offset % it->unsend_size % it->edit_division;
1922 datadump += formatter.str();
1925 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1926 "handle_client_recv() : send status list dump : send status list size = %d.%s");
1928 formatter % recv_data.send_status_list.size() % datadump;
1929 putLogDebug(100065, formatter.str(), __FILE__, __LINE__ );
1931 /*------DEBUG LOG END------*/
1932 //there are still rest data need to process
1933 //new status created and add to status list
1934 while (request_data_remain_size > 0)
1936 //new status created
1937 send_status new_send_state;
1939 new_send_state.edit_division = EDIT_DIVISION_NO_EDIT;
1940 new_send_state.send_end_size = 0;
1941 new_send_state.send_offset = 0;
1942 new_send_state.send_possible_size = 0;
1943 new_send_state.unsend_size = 0;
1944 new_send_state.send_rest_size = 0;
1945 //status initialize to SEND_NG
1946 new_send_state.status = SEND_NG;
1947 //add new status to status_list
1948 recv_data.send_status_list.push_back(new_send_state);
1949 std::list<send_status>::reverse_iterator new_send_it = recv_data.send_status_list.rbegin();
1951 new_send_it->send_offset = recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size
1952 - request_data_remain_size;
1955 check_result = check_http_method(recv_data.recive_buffer + new_send_it->send_offset,
1956 request_data_remain_size);
1957 /*-------- DEBUG LOG --------*/
1958 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1960 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1961 "handle_client_recv() : call check_http_method : "
1962 "return_value = %d. thread id : %d.");
1963 formatter % check_result % boost::this_thread::get_id();
1964 putLogDebug(100066, formatter.str(), __FILE__, __LINE__ );
1966 /*------DEBUG LOG END------*/
1967 //check http method result is OK
1968 if (check_result == CHECK_OK)
1970 //check http version
1971 check_result = check_http_version(recv_data.recive_buffer + new_send_it->send_offset,
1972 request_data_remain_size);
1973 /*-------- DEBUG LOG --------*/
1974 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1976 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1977 "handle_client_recv() : call check_http_version : "
1978 "return_value = %d. thread id : %d.");
1979 formatter % check_result % boost::this_thread::get_id();
1980 putLogDebug(100067, formatter.str(), __FILE__, __LINE__ );
1982 /*------DEBUG LOG END------*/
1984 //check http method and version result is OK
1985 if (check_result == CHECK_OK)
1987 //search whole http header, get whole http header's offset and length
1988 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset, request_data_remain_size,
1989 http_header, header_offset, header_offset_len);
1990 /*-------- DEBUG LOG --------*/
1991 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1993 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1994 "handle_client_recv() : call find_http_header : "
1995 "return_value = %d. thread id : %d.");
1996 formatter % check_result % boost::this_thread::get_id();
1997 putLogDebug(100068, formatter.str(), __FILE__, __LINE__ );
1999 /*------DEBUG LOG END------*/
2000 //searched whole http header
2003 //search ContentLength http header, get ContentLength header's offset and length
2004 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset,
2005 request_data_remain_size, content_header, content_length_header_offset, content_length_header_len);
2006 /*-------- DEBUG LOG --------*/
2007 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2009 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2010 "handle_client_recv() : call find_http_header : "
2011 "return_value = %d. thread id : %d.");
2012 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
2013 putLogDebug(100069, formatter.str(), __FILE__, __LINE__ );
2015 /*------DEBUG LOG END------*/
2017 //searched ContentLength http header
2020 //Get Content_Length header's numeric value
2022 recv_data.recive_buffer[new_send_it->send_offset + content_length_header_offset + pos] != ':'
2023 && pos < content_length_header_len;
2025 if (pos == content_length_header_len)
2027 throw std::string("Content_Length field's value is invalid.");
2032 str_value.assign(recv_data.recive_buffer + new_send_it->send_offset + content_length_header_offset + pos,
2033 content_length_header_len - pos);
2035 size_t pos_end = str_value.find_last_of('\r');
2036 if (pos_end != std::string::npos)
2038 str_value = str_value.erase(pos_end);
2041 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos);
2043 str_value = str_value.substr(pos);
2046 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
2048 catch (const boost::bad_lexical_cast& ex)
2050 throw std::string("Content_Length field's value is invalid.");
2052 //send_rest_size recalc
2053 //set whole http header's + whole http header's length + Content_Length's value
2054 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_cr_lf_len + content_len_value;
2056 //not searched ContentLength http header
2059 //send_rest_size recalc
2060 //set whole http header's + whole http header's length
2061 if (header_offset_len == 0)
2063 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
2067 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_cr_lf_len;
2071 //set edit_division flag on
2072 new_send_it->edit_division = EDIT_DIVISION_EDIT;
2074 //not searched whole http header
2077 new_send_it->unsend_size = request_data_remain_size;
2078 request_data_remain_size = 0;
2082 //check http method or version result is NG
2083 else if (check_result == CHECK_NG)
2085 new_send_it->edit_division = EDIT_DIVISION_NO_EDIT;
2086 new_send_it->send_rest_size = request_data_remain_size;
2089 //check http method or version result is impossible
2092 new_send_it->unsend_size = request_data_remain_size;
2093 request_data_remain_size = 0;
2097 //recalc fields value according to send_rest_size and request rest size
2098 if (new_send_it->send_rest_size > request_data_remain_size)
2100 new_send_it->send_possible_size = request_data_remain_size;
2101 new_send_it->send_rest_size -= request_data_remain_size;
2102 new_send_it->send_end_size = 0;
2103 request_data_remain_size = 0;
2107 new_send_it->send_possible_size = new_send_it->send_rest_size;
2108 request_data_remain_size -= new_send_it->send_rest_size;
2109 new_send_it->send_end_size = 0;
2110 new_send_it->send_rest_size = 0;
2113 //change status from SEND_NG to SEND_OK
2114 new_send_it->status = SEND_OK;
2117 /*-------- DEBUG LOG --------*/
2118 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2120 std::string datadump;
2121 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
2122 "send_rest_size = %d, send_possible_size = %d, "
2123 "send_offset = %d, unsend_size = %d, edit_division = %d.");
2125 for (it = recv_data.send_status_list.begin();
2126 it != recv_data.send_status_list.end();
2129 formatter % i % it->status % it->send_end_size
2130 % it->send_rest_size % it->send_possible_size
2131 % it->send_offset % it->unsend_size % it->edit_division;
2132 datadump += formatter.str();
2135 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2136 "handle_client_recv() : send status list dump : send status list size = %d.%s");
2138 formatter % recv_data.send_status_list.size() % datadump;
2139 putLogDebug(100070, formatter.str(), __FILE__, __LINE__ );
2141 /*------DEBUG LOG END------*/
2142 //search for send_possible item in status list
2143 send_status_it it_find = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
2144 data_send_possible());
2145 //the data that can be sent possible is exist
2146 if (it_find != recv_data.send_status_list.end())
2149 if (session_data->sorry_flag == SORRY_FLAG_ON)
2151 status = SORRYSERVER_CONNECT;
2156 status = REALSERVER_CONNECT;
2159 //the data that can be sent possible is not exist
2162 status = CLIENT_RECV;
2168 /*-------- DEBUG LOG --------*/
2169 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2171 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2172 "handle_client_recv() : catch exception e = %d. thread id : %d.");
2173 formatter % e % boost::this_thread::get_id();
2174 putLogDebug(100071, formatter.str(), __FILE__, __LINE__ );
2176 /*------DEBUG LOG END------*/
2179 catch (const std::string& ex)
2181 std::cerr << "protocol_module_sessionless::handle_client_recv() : exception : " << ex << std::endl;
2182 boost::format formatter("protocol_module_sessionless::handle_client_recv() : exception : %s. thread id : %d.");
2183 formatter % ex.c_str() % boost::this_thread::get_id();
2184 putLogError(100033, formatter.str(), __FILE__, __LINE__ );
2187 catch (const std::bad_alloc&)
2189 std::cerr << "protocol_module_sessionless::handle_client_recv() : exception : Could not allocate memory." << std::endl;
2190 boost::format formatter("Could not allocate memory. thread id : %d.");
2191 formatter % boost::this_thread::get_id();
2192 putLogError(100034, formatter.str(), __FILE__, __LINE__ );
2195 catch (const std::exception& ex)
2197 std::cerr << "protocol_module_sessionless::handle_client_recv() : exception : error = " << ex.what() << "." << std::endl;
2198 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2199 "handle_client_recv() : exception : error = %s. thread id : %d.");
2200 formatter % ex.what() % boost::this_thread::get_id();
2201 putLogError(100035, formatter.str(), __FILE__, __LINE__ );
2207 std::cerr << "protocol_module_sessionless::handle_client_recv() : Unknown exception." << std::endl;
2208 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2209 "protocol_module_sessionless::handle_client_recv() : "
2210 "Unknown exception. thread id : %d.");
2211 formatter % boost::this_thread::get_id();
2212 putLogError(100036, formatter.str(), __FILE__, __LINE__ );
2216 /*-------- DEBUG LOG --------*/
2217 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2219 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2220 "handle_client_recv(const boost::thread::id thread_id, "
2221 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
2222 "const size_t recvlen) : return_value = %d. thread id : %d.");
2223 formatter % status % boost::this_thread::get_id();
2224 putLogDebug(100072, formatter.str(), __FILE__, __LINE__ );
2226 /*------DEBUG LOG END------*/
2231 //! called from after realserver select.use in upstream thread.
2232 //! @param[in] upstream thread id
2233 //! @param[out] realserver TCP endpoint
2234 //! @return session use EVENT mode.
2235 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_select(
2236 const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint & rs_endpoint)
2238 /*-------- DEBUG LOG --------*/
2239 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2241 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2242 "handle_realserver_select(const boost::thread::id thread_id, "
2243 "boost::asio::ip::tcp::endpoint & rs_endpoint) : "
2244 "thread_id = %d, rs_endpoint = [%s]:%d.");
2245 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
2246 putLogDebug(100073, formatter.str(), __FILE__, __LINE__ );
2248 /*------DEBUG LOG END------*/
2249 EVENT_TAG status = FINALIZE;
2250 boost::asio::ip::tcp::endpoint tmp_endpoint;
2251 thread_data_ptr session_data;
2252 session_thread_data_map_it session_thread_it;
2253 session_thread_data_map_it session_thread_it_end;
2254 recive_data_map_it recive_data_it;
2256 if (schedule_tcp.empty())
2258 std::cerr << "protocol_module_sessionless::handle_realserver_select() : Schedule_tcp function is empty." << std::endl;
2259 boost::format formatter("Schedule_tcp function is empty. thread id : %d.");
2260 formatter % boost::this_thread::get_id();
2261 putLogError(100037, formatter.str(), __FILE__, __LINE__ );
2262 /*-------- DEBUG LOG --------*/
2263 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2265 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2266 "handle_realserver_select(const boost::thread::id thread_id, "
2267 "boost::asio::ip::tcp::endpoint & rs_endpoint)"
2268 " : return_value = %d. thread id : %d.");
2269 formatter % FINALIZE % boost::this_thread::get_id();
2270 putLogDebug(100074, formatter.str(), __FILE__, __LINE__ );
2272 /*------DEBUG LOG END------*/
2279 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
2281 session_thread_it = session_thread_data_map.find(thread_id);
2282 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2284 boost::format formatter("Invalid thread id. thread id : %d.");
2285 formatter % boost::this_thread::get_id();
2286 putLogError(100038, formatter.str(), __FILE__, __LINE__ );
2290 session_data = session_thread_it->second;
2293 //call schedule_module's schedule function, get realserver endpoint
2295 rs_list_scoped_lock scoped_lock(rs_list_lock, rs_list_unlock);
2296 schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, rs_endpoint);
2299 /*-------- DEBUG LOG --------*/
2300 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2302 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2303 "handle_realserver_select() : call schedule_tcp : "
2304 "rs_endpoint = [%s]:%d. thread id : %d.");
2305 formatter % rs_endpoint.address().to_string() % rs_endpoint.port() % boost::this_thread::get_id();
2306 putLogDebug(100075, formatter.str(), __FILE__, __LINE__ );
2308 /*------DEBUG LOG END------*/
2311 if (rs_endpoint != tmp_endpoint)
2314 session_data->target_endpoint = rs_endpoint;
2316 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
2317 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
2319 boost::format formatter("Invalid endpoint. thread id : %d.");
2320 formatter % boost::this_thread::get_id();
2321 putLogError(100039, formatter.str(), __FILE__, __LINE__ );
2324 recive_data& recv_data = recive_data_it->second;
2326 send_status_it it = recv_data.send_status_list.begin();
2327 send_status_it it_end = recv_data.send_status_list.end();
2329 it = find_if(it, it_end, data_send_possible());
2332 status = REALSERVER_CONNECT;
2336 status = CLIENT_RECV;
2342 session_data->sorry_flag = SORRY_FLAG_ON;
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() : SORRY_FLAG_ON. thread id : %d.");
2348 formatter % boost::this_thread::get_id();
2349 putLogDebug(100076, formatter.str(), __FILE__, __LINE__ );
2351 /*------DEBUG LOG END------*/
2352 status = SORRYSERVER_SELECT;
2357 /*-------- DEBUG LOG --------*/
2358 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2360 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2361 "handle_realserver_select() : catch exception e = %d. thread id : %d.");
2362 formatter % e % boost::this_thread::get_id();
2363 putLogDebug(100077, formatter.str(), __FILE__, __LINE__ );
2366 /*------DEBUG LOG END------*/
2368 catch (const std::exception& ex)
2370 std::cerr << "protocol_module_sessionless::handle_realserver_select() : exception : error = " << ex.what() << "." << std::endl;
2371 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2372 "handle_realserver_select() : exception : error = %s. thread id : %d.");
2373 formatter % ex.what() % boost::this_thread::get_id();
2374 putLogError(100040, formatter.str(), __FILE__, __LINE__ );
2379 std::cerr << "protocol_module_sessionless::handle_realserver_select() : Unknown exception." << std::endl;
2380 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2381 "protocol_module_sessionless::handle_realserver_select() : "
2382 "Unknown exception. thread id : %d.");
2383 formatter % boost::this_thread::get_id();
2384 putLogError(100041, formatter.str(), __FILE__, __LINE__ );
2388 /*-------- DEBUG LOG --------*/
2389 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2391 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2392 "handle_realserver_select(const boost::thread::id thread_id, "
2393 "boost::asio::ip::tcp::endpoint & rs_endpoint)"
2394 " : return_value = %d. thread id : %d.");
2395 formatter % status % boost::this_thread::get_id();
2396 putLogDebug(100078, formatter.str(), __FILE__, __LINE__ );
2398 /*------DEBUG LOG END------*/
2403 //! called from after realserver select
2404 //! @param[in] upstream thread id
2405 //! @param[out] realserver UDP endpoint
2406 //! @param[out] sendbuffer reference
2407 //! @param[out] send data length
2408 //! @return session use EVENT mode.
2409 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_select(
2410 const boost::thread::id thread_id, boost::asio::ip::udp::endpoint& rs_endpoint, boost::array<char,
2411 MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
2413 /*-------- DEBUG LOG --------*/
2414 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2416 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2417 "handle_realserver_select(const boost::thread::id thread_id, "
2418 "boost::asio::ip::udp::endpoint& rs_endpoint, boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
2419 "size_t& datalen) : "
2420 "return_value = %d. thread id : %d.");
2421 formatter % STOP % boost::this_thread::get_id();
2422 putLogDebug(100079, formatter.str(), __FILE__, __LINE__ );
2424 /*------DEBUG LOG END------*/
2427 //! called from after realserver connect
2428 //! @param[in] upstream thread id
2429 //! @param[out] sendbuffer reference
2430 //! @param[out] send data length
2431 //! @return session use EVENT mode.
2432 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_connect(
2433 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
2435 /*-------- DEBUG LOG --------*/
2436 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2438 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2439 "handle_realserver_connect(const boost::thread::id thread_id, "
2440 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
2442 formatter % thread_id;
2443 putLogDebug(100080, formatter.str(), __FILE__, __LINE__ );
2445 /*------DEBUG LOG END------*/
2447 EVENT_TAG status = FINALIZE;
2449 size_t header_offset = 0;
2450 size_t header_offset_len = 0;
2451 size_t send_buffer_remian_size = 0;
2452 size_t copy_size = 0;
2453 const int send_buffer_end_size = sendbuffer.max_size();
2454 const std::string http_header = "";
2455 const std::string str_forword_for = "X-Forwarded-For";
2456 thread_data_ptr session_data;
2457 session_thread_data_map_it session_thread_it;
2458 recive_data_map_it recive_data_it;
2463 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
2466 session_thread_it = session_thread_data_map.find(thread_id);
2467 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2469 boost::format formatter("Invalid thread id. thread id : %d.");
2470 formatter % boost::this_thread::get_id();
2471 putLogError(100042, formatter.str(), __FILE__, __LINE__ );
2475 session_data = session_thread_it->second;
2479 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
2480 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
2482 boost::format formatter("Invalid endpoint. thread id : %d.");
2483 formatter % boost::this_thread::get_id();
2484 putLogError(100043, formatter.str(), __FILE__, __LINE__ );
2488 //recive_buffer pointer check
2489 recive_data& recv_data = recive_data_it->second;
2490 if (unlikely(recv_data.recive_buffer == NULL))
2492 boost::format formatter("Invalid pointer. thread id : %d.");
2493 formatter % boost::this_thread::get_id();
2494 putLogError(100044, formatter.str(), __FILE__, __LINE__ );
2499 send_status_it it = recv_data.send_status_list.begin();
2500 send_status_it it_end = recv_data.send_status_list.end();
2501 it = find_if(it, it_end, data_send_possible());
2502 if (unlikely(it == it_end))
2504 boost::format formatter("Sending possible data is not existed. thread id : %d.");
2505 formatter % boost::this_thread::get_id();
2506 putLogError(100045, formatter.str(), __FILE__, __LINE__ );
2510 //send buffer rest size initialization
2511 send_buffer_remian_size = send_buffer_end_size;
2513 //edit_division flag on
2514 if (it->edit_division == EDIT_DIVISION_EDIT && forwarded_for == FORWARDED_FOR_ON)
2516 //edit list is empty
2517 if (it->edit_data_list.empty())
2521 edata.data_size = 0;
2522 edata.insert_posission = 0;
2523 edata.replace_size = 0;
2524 //search X-Forwarded-For header
2525 ret = find_http_header(recv_data.recive_buffer + it->send_offset, it->send_possible_size,
2526 str_forword_for, header_offset, header_offset_len);
2527 /*-------- DEBUG LOG --------*/
2528 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2530 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2531 "handle_realserver_connect() : call find_http_header : "
2532 "return_value = %d. thread id : %d.");
2533 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
2534 putLogDebug(100081, formatter.str(), __FILE__, __LINE__ );
2536 /*------DEBUG LOG END------*/
2537 //search http header result is OK
2540 //edit X-Forwarded-For header, set it to edata.data
2541 edata.data.assign(recv_data.recive_buffer + it->send_offset + header_offset, header_offset_len);
2543 edata.data += session_data->client_endpoint_tcp.address().to_string();
2544 //save new X-Forwarded-For header offset
2545 edata.insert_posission = header_offset;
2546 //save new X-Forwarded-For header length
2547 edata.data_size = edata.data.size();
2548 //save old X-Forwarded-For header length
2549 edata.replace_size = header_offset_len;
2551 //search http header result is NG
2554 //search whole http header, get whole http header's offset and length
2555 ret = find_http_header(recv_data.recive_buffer + it->send_offset, it->send_possible_size, "",
2556 header_offset, header_offset_len);
2557 /*-------- DEBUG LOG --------*/
2558 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2560 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2561 "handle_realserver_connect() : call find_http_header : "
2562 "return_value = %d. thread id : %d.");
2563 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
2564 putLogDebug(100082, formatter.str(), __FILE__, __LINE__ );
2566 /*------DEBUG LOG END------*/
2569 boost::format formatter("find_http_header() function failure. thread id : %d.");
2570 formatter % boost::this_thread::get_id();
2571 putLogError(100046, formatter.str(), __FILE__, __LINE__ );
2572 /*-------- DEBUG LOG --------*/
2573 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2575 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2576 "handle_realserver_connect(const boost::thread::id thread_id, "
2577 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
2578 "size_t& datalen) : return_value = %d. thread id : %d.");
2579 formatter % FINALIZE % boost::this_thread::get_id();
2580 putLogDebug(100083, formatter.str(), __FILE__, __LINE__ );
2582 /*------DEBUG LOG END------*/
2585 //create X-Forwarded-For header, put it to edata.data
2586 edata.data = str_forword_for;
2588 edata.data += session_data->client_endpoint_tcp.address().to_string();
2589 edata.data += "\r\n";
2590 //save new X-Forwarded-For header offset
2591 edata.insert_posission = header_offset;
2592 //save new X-Forwarded-For header length
2593 edata.data_size = edata.data.size();
2594 //save old X-Forwarded-For header length
2595 edata.replace_size = 0;
2598 //add to edit_data_list
2599 it->edit_data_list.push_back(edata);
2602 /*-------- DEBUG LOG --------*/
2603 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2605 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2606 "handle_realserver_connect() : Copy data loop start. thread id : %d.");
2607 formatter % boost::this_thread::get_id();
2608 putLogDebug(100084, formatter.str(), __FILE__, __LINE__ );
2610 /*------DEBUG LOG END------*/
2613 //edit_data_list is empty
2614 if (it->edit_data_list.empty())
2616 //set edit_division flag on
2617 it->edit_division = EDIT_DIVISION_NO_EDIT;
2619 if (send_buffer_remian_size > 0 && it->send_possible_size > 0)
2621 //send_buffer_remian_size is larger
2622 if (send_buffer_remian_size >= it->send_possible_size)
2624 copy_size = it->send_possible_size;
2625 /*-------- DEBUG LOG --------*/
2626 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2628 std::string datadump;
2629 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
2630 it->send_possible_size, datadump);
2631 boost::format formatter(
2632 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2633 "handle_realserver_connect() : before memcpy (data dump) : "
2634 "data begin = %d, data_size = %d, data = %s");
2635 formatter % (it->send_offset + it->send_end_size)
2636 % copy_size % datadump;
2637 putLogDebug(100085, formatter.str(), __FILE__, __LINE__ );
2639 /*------DEBUG LOG END------*/
2640 //copy data from recive_buffer to sendbuffer by sending_possible size
2641 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2642 recv_data.recive_buffer + it->send_offset + it->send_end_size,
2643 it->send_possible_size);
2644 /*-------- DEBUG LOG --------*/
2645 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2647 std::string datadump;
2648 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2649 it->send_possible_size, datadump);
2651 boost::format formatter(
2652 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2653 "handle_realserver_connect() : after memcpy (data dump) : "
2654 "data begin = %d, data_size = %d, data = %s");
2655 formatter % (send_buffer_end_size - send_buffer_remian_size)
2656 % copy_size % datadump;
2657 putLogDebug(100086, formatter.str(), __FILE__, __LINE__ );
2659 /*------DEBUG LOG END------*/
2661 it->send_end_size += copy_size;
2662 it->send_possible_size = 0;
2663 send_buffer_remian_size -= copy_size;
2665 //send_possible_size is larger
2668 copy_size = send_buffer_remian_size;
2669 /*-------- DEBUG LOG --------*/
2670 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2672 std::string datadump;
2673 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
2674 copy_size, datadump);
2676 boost::format formatter(
2677 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2678 "handle_realserver_connect() : before memcpy (data dump) : "
2679 "data begin = %d, data_size = %d, data = %s");
2680 formatter % (it->send_offset + it->send_end_size)
2681 % copy_size % datadump;
2682 putLogDebug(100087, formatter.str(), __FILE__, __LINE__ );
2684 /*------DEBUG LOG END------*/
2685 //copy data from recive_buffer to sendbuffer by send buffer rest size
2686 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2687 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
2688 /*-------- DEBUG LOG --------*/
2689 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2691 std::string datadump;
2692 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2693 copy_size, datadump);
2695 boost::format formatter(
2696 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2697 "handle_realserver_connect() : after memcpy (data dump) : "
2698 "data begin = %d, data_size = %d, data = %s");
2699 formatter % (send_buffer_end_size - send_buffer_remian_size)
2700 % copy_size % datadump;
2701 putLogDebug(100088, formatter.str(), __FILE__, __LINE__ );
2703 /*------DEBUG LOG END------*/
2704 it->send_end_size += copy_size;
2705 it->send_possible_size -= copy_size;
2706 send_buffer_remian_size = 0;
2711 //edit_data_list is not empty
2714 //find the item in the list which has mininum insert_posission
2715 std::list<edit_data>::iterator edit_min = std::min_element(it->edit_data_list.begin(),
2716 it->edit_data_list.end());
2717 //send_buffer_remian_size is larger than data that before X-Forwarded-For
2718 if (send_buffer_remian_size >= edit_min->insert_posission - it->send_end_size)
2720 //copy data before X-Forwarded-For
2721 copy_size = edit_min->insert_posission - it->send_end_size;
2722 /*-------- DEBUG LOG --------*/
2723 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2725 std::string datadump;
2726 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
2727 copy_size, datadump);
2729 boost::format formatter(
2730 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2731 "handle_realserver_connect() : before memcpy (data dump) : "
2732 "data begin = %d, data_size = %d, data = %s");
2733 formatter % (it->send_offset + it->send_end_size)
2734 % copy_size % datadump;
2735 putLogDebug(100089, formatter.str(), __FILE__, __LINE__ );
2737 /*------DEBUG LOG END------*/
2738 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2739 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
2740 /*-------- DEBUG LOG --------*/
2741 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2743 std::string datadump;
2744 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2745 copy_size, datadump);
2746 boost::format formatter(
2747 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2748 "handle_realserver_connect() : after memcpy (data dump) : "
2749 "data begin = %d, data_size = %d, data = %s");
2750 formatter % (send_buffer_end_size - send_buffer_remian_size)
2751 % copy_size % datadump;
2752 putLogDebug(100090, formatter.str(), __FILE__, __LINE__ );
2754 /*------DEBUG LOG END------*/
2755 it->send_end_size += copy_size;
2756 it->send_possible_size -= copy_size;
2757 send_buffer_remian_size -= copy_size;
2759 //there is remain buffer for copy X-Forwarded-For
2760 if (send_buffer_remian_size >= edit_min->data_size)
2762 /*-------- DEBUG LOG --------*/
2763 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2765 std::string datadump;
2766 dump_memory(edit_min->data.c_str(),
2767 edit_min->data_size, datadump);
2769 boost::format formatter(
2770 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2771 "handle_realserver_connect() : before memcpy (data dump) : "
2772 "data begin = 0, data_size = %d, data = %s");
2773 formatter % edit_min->data_size % datadump;
2774 putLogDebug(100091, formatter.str(), __FILE__, __LINE__ );
2776 /*------DEBUG LOG END------*/
2777 //copy X-Forwarded-For
2778 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2779 edit_min->data.c_str(), edit_min->data_size);
2780 /*-------- DEBUG LOG --------*/
2781 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2783 std::string datadump;
2784 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2785 edit_min->data_size, datadump);
2786 boost::format formatter(
2787 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2788 "handle_realserver_connect() : after memcpy (data dump) : "
2789 "data begin = %d, data_size = %d, data = %s");
2790 formatter % (send_buffer_end_size - send_buffer_remian_size)
2791 % edit_min->data_size % datadump;
2792 putLogDebug(100092, formatter.str(), __FILE__, __LINE__ );
2794 /*------DEBUG LOG END------*/
2795 it->send_end_size += edit_min->replace_size;
2796 it->send_possible_size -= edit_min->replace_size;
2797 send_buffer_remian_size -= edit_min->data_size;
2798 it->edit_data_list.erase(edit_min);
2806 //data that before X-Forwarded-For is larger than send_buffer_remian_size
2809 copy_size = send_buffer_remian_size;
2810 /*-------- DEBUG LOG --------*/
2811 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2813 std::string datadump;
2814 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
2815 copy_size, datadump);
2817 boost::format formatter(
2818 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2819 "handle_realserver_connect() : before memcpy (data dump) : "
2820 "data begin = %d, data_size = %d, data = %s");
2821 formatter % (it->send_offset + it->send_end_size)
2822 % copy_size % datadump;
2823 putLogDebug(100093, formatter.str(), __FILE__, __LINE__ );
2825 /*------DEBUG LOG END------*/
2826 //copy data as large as possible
2827 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2828 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
2829 /*-------- DEBUG LOG --------*/
2830 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2832 std::string datadump;
2833 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2834 copy_size, datadump);
2836 boost::format formatter(
2837 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2838 "handle_realserver_connect() : after memcpy (data dump) : "
2839 "data begin = %d, data_size = %d, data = %s");
2840 formatter % (send_buffer_end_size - send_buffer_remian_size)
2841 % copy_size % datadump;
2842 putLogDebug(100094, formatter.str(), __FILE__, __LINE__ );
2844 /*------DEBUG LOG END------*/
2846 it->send_end_size += copy_size;
2847 it->send_possible_size -= copy_size;
2848 send_buffer_remian_size -= copy_size;
2853 /*-------- DEBUG LOG --------*/
2854 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2856 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2857 "handle_realserver_connect() : Copy data loop end. thread id : %d.");
2858 formatter % boost::this_thread::get_id();
2859 putLogDebug(100095, formatter.str(), __FILE__, __LINE__ );
2861 /*------DEBUG LOG END------*/
2863 //edit_division flag is off
2866 //copy data as large as possible
2867 //send_possible_size is larger
2868 if (send_buffer_remian_size >= it->send_possible_size)
2870 copy_size = it->send_possible_size;
2871 /*-------- DEBUG LOG --------*/
2872 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2874 std::string datadump;
2875 dump_memory(recv_data.recive_buffer + it->send_offset,
2876 copy_size, datadump);
2877 boost::format formatter(
2878 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2879 "handle_realserver_connect() : before memcpy (data dump) : "
2880 "data begin = %d, data_size = %d, data = %s");
2881 formatter % it->send_offset
2882 % copy_size % datadump;
2883 putLogDebug(100096, formatter.str(), __FILE__, __LINE__ );
2885 /*------DEBUG LOG END------*/
2886 //copy data by send_possible size
2887 memcpy(sendbuffer.data(), recv_data.recive_buffer + it->send_offset, copy_size);
2888 /*-------- DEBUG LOG --------*/
2889 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2891 std::string datadump;
2892 dump_memory(sendbuffer.data(), copy_size, datadump);
2893 boost::format formatter(
2894 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2895 "handle_realserver_connect() : after memcpy (data dump) : "
2896 "data begin = 0, data_size = %d, data = %s");
2897 formatter % copy_size % datadump;
2898 putLogDebug(100097, formatter.str(), __FILE__, __LINE__ );
2900 /*------DEBUG LOG END------*/
2901 it->send_end_size = copy_size;
2902 it->send_possible_size = 0;
2903 send_buffer_remian_size -= copy_size;
2905 //buffer rest size is larger
2908 /*-------- DEBUG LOG --------*/
2909 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2911 std::string datadump;
2912 dump_memory(recv_data.recive_buffer + it->send_offset, send_buffer_remian_size, datadump);
2914 boost::format formatter(
2915 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2916 "handle_realserver_connect() : before memcpy (data dump) : "
2917 "data begin = %d, data_size = %d, data = %s");
2918 formatter % it->send_offset
2919 % send_buffer_remian_size % datadump;
2920 putLogDebug(100098, formatter.str(), __FILE__, __LINE__ );
2922 /*------DEBUG LOG END------*/
2923 //copy data by buffer rest size
2924 memcpy(sendbuffer.data(), recv_data.recive_buffer + it->send_offset, send_buffer_remian_size);
2925 /*-------- DEBUG LOG --------*/
2926 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2928 std::string datadump;
2929 dump_memory(sendbuffer.data(), send_buffer_remian_size, datadump);
2930 boost::format formatter(
2931 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2932 "handle_realserver_connect() : after memcpy (data dump) : "
2933 "data begin = 0, data_size = %d, data = %s");
2934 formatter % send_buffer_remian_size % datadump;
2935 putLogDebug(100099, formatter.str(), __FILE__, __LINE__ );
2937 /*------DEBUG LOG END------*/
2938 it->send_end_size = send_buffer_remian_size;
2939 it->send_possible_size -= send_buffer_remian_size;
2940 send_buffer_remian_size = 0;
2944 //set copyed data length
2945 datalen = send_buffer_end_size - send_buffer_remian_size;
2946 status = REALSERVER_SEND;
2950 /*-------- DEBUG LOG --------*/
2951 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2953 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2954 "handle_realserver_connect() : catch exception e = %d. thread id : %d.");
2955 formatter % e % boost::this_thread::get_id();
2956 putLogDebug(100100, formatter.str(), __FILE__, __LINE__ );
2959 /*------DEBUG LOG END------*/
2961 catch (const std::exception& ex)
2963 std::cerr << "protocol_module_sessionless::handle_realserver_connect() : exception : error = " << ex.what() << "." << std::endl;
2964 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2965 "handle_realserver_connect() : exception : error = %s. thread id : %d.");
2966 formatter % ex.what() % boost::this_thread::get_id();
2967 putLogError(100047, formatter.str(), __FILE__, __LINE__ );
2972 std::cerr << "protocol_module_sessionless::handle_realserver_connect() : Unknown exception." << std::endl;
2973 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2974 "handle_realserver_connect() : Unknown exception. thread id : %d.");
2975 formatter % boost::this_thread::get_id();
2976 putLogError(100048, formatter.str(), __FILE__, __LINE__ );
2980 /*-------- DEBUG LOG --------*/
2981 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2983 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2984 "handle_realserver_connect(const boost::thread::id thread_id, "
2985 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
2986 "size_t& datalen) : return_value = %d. thread id : %d.");
2987 formatter % status % boost::this_thread::get_id();
2988 putLogDebug(100101, formatter.str(), __FILE__, __LINE__ );
2990 /*------DEBUG LOG END------*/
2995 //! called from after realserver connection fail
2996 //! @param[in] upstream thread id
2997 //! @param[in] fail realserver endpoint reference
2998 //! @return session use EVENT mode.
2999 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_connection_fail(
3000 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint)
3002 /*-------- DEBUG LOG --------*/
3003 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3005 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3006 "handle_realserver_connection_fail(const boost::thread::id thread_id, "
3007 "const boost::asio::ip::tcp::endpoint & rs_endpoint) : "
3008 "thread_id = %d, rs_endpoint = [%s]:%d.");
3009 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
3010 putLogDebug(100102, formatter.str(), __FILE__, __LINE__ );
3012 /*------DEBUG LOG END------*/
3014 EVENT_TAG status = FINALIZE;
3015 thread_data_ptr session_data;
3016 session_thread_data_map_it session_thread_it;
3020 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
3022 session_thread_it = session_thread_data_map.find(thread_id);
3023 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3025 boost::format formatter("Invalid thread id. thread id : %d.");
3026 formatter % boost::this_thread::get_id();
3027 putLogError(100049, formatter.str(), __FILE__, __LINE__ );
3031 session_data = session_thread_it->second;
3034 session_data->end_flag = END_FLAG_ON;
3035 /*-------- DEBUG LOG --------*/
3036 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3038 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3039 "handle_realserver_connection_fail() : END_FLAG_ON. thread id : %d.");
3040 formatter % boost::this_thread::get_id();
3041 putLogDebug(100103, formatter.str(), __FILE__, __LINE__ );
3043 /*------DEBUG LOG END------*/
3044 status = CLIENT_DISCONNECT;
3048 /*-------- DEBUG LOG --------*/
3049 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3051 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3052 "handle_realserver_connection_fail() : catch exception e = %d. thread id : %d.");
3053 formatter % e % boost::this_thread::get_id();
3054 putLogDebug(100104, formatter.str(), __FILE__, __LINE__ );
3057 /*------DEBUG LOG END------*/
3059 catch (std::exception& ex)
3061 std::cerr << "protocol_module_sessionless::handle_realserver_connection_fail() : exception : error = " << ex.what() << "." << std::endl;
3062 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3063 "handle_realserver_connection_fail() : exception : error = %s. thread id : %d.");
3064 formatter % ex.what() % boost::this_thread::get_id();
3065 putLogError(100050, formatter.str(), __FILE__, __LINE__ );
3070 std::cerr << "protocol_module_sessionless::handle_realserver_connection_fail() : Unknown exception." << std::endl;
3071 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3072 "handle_realserver_connection_fail() : Unknown exception. thread id : %d.");
3073 formatter % boost::this_thread::get_id();
3074 putLogError(100051, formatter.str(), __FILE__, __LINE__ );
3078 /*-------- DEBUG LOG --------*/
3079 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3081 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3082 "handle_realserver_connection_fail(const boost::thread::id thread_id, "
3083 "const boost::asio::ip::tcp::endpoint & rs_endpoint) : return_value = %d. thread id : %d.");
3084 formatter % status % boost::this_thread::get_id();
3085 putLogDebug(100105, formatter.str(), __FILE__, __LINE__ );
3087 /*------DEBUG LOG END------*/
3090 //! called from after realserver send.
3091 //! @param[in] upstream thread id
3092 //! @return session use EVENT mode.
3093 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_send(
3094 const boost::thread::id thread_id)
3096 /*-------- DEBUG LOG --------*/
3097 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3099 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3100 "handle_realserver_send(const boost::thread::id thread_id) : "
3102 formatter % thread_id;
3103 putLogDebug(100106, formatter.str(), __FILE__, __LINE__ );
3105 /*------DEBUG LOG END------*/
3106 EVENT_TAG status = FINALIZE;
3107 thread_data_ptr session_data;
3108 session_thread_data_map_it session_thread_it;
3109 recive_data_map_it recive_data_it;
3114 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
3117 session_thread_it = session_thread_data_map.find(thread_id);
3118 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3120 boost::format formatter("Invalid thread id. thread id : %d.");
3121 formatter % boost::this_thread::get_id();
3122 putLogError(100052, formatter.str(), __FILE__, __LINE__ );
3126 session_data = session_thread_it->second;
3130 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
3131 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
3133 boost::format formatter("Invalid endpoint. thread id : %d.");
3134 formatter % boost::this_thread::get_id();
3135 putLogError(100053, formatter.str(), __FILE__, __LINE__ );
3139 recive_data& recv_data = recive_data_it->second;
3141 send_status_it it = recv_data.send_status_list.begin();
3142 send_status_it it_end = recv_data.send_status_list.end();
3145 it = std::adjacent_find(it, it_end, data_send_list_incorrect());
3146 if (unlikely(it != it_end))
3148 boost::format formatter("Sending possible data is invalid. thread id : %d.");
3149 formatter % boost::this_thread::get_id();
3150 putLogError(100054, formatter.str(), __FILE__, __LINE__ );
3155 it = recv_data.send_status_list.begin();
3156 it = std::find_if(it, it_end, data_send_ok());
3157 if (unlikely(it == it_end))
3159 boost::format formatter("Sending possible data is not existed. thread id : %d.");
3160 formatter % boost::this_thread::get_id();
3161 putLogError(100055, formatter.str(), __FILE__, __LINE__ );
3165 //sending possible data is exist
3166 if (it->send_possible_size > 0)
3168 //status remain SEND_OK
3169 it->status = SEND_OK;
3171 it->send_offset += it->send_end_size;
3173 //insert_posission recalc
3174 for (std::list<edit_data>::iterator list_it = it->edit_data_list.begin(); list_it
3175 != it->edit_data_list.end(); ++list_it)
3177 list_it->insert_posission -= it->send_end_size;
3180 //send_end_size recalc
3181 it->send_end_size = 0;
3183 //sending possible data is not exist
3186 //can recive from client continue
3187 if (it->send_rest_size > 0)
3189 //change status from SEND_OK to SEND_CONTINUE
3190 it->status = SEND_CONTINUE;
3192 //can not recive from client continue
3195 //change status from SEND_OK to SEND_END
3196 it->status = SEND_END;
3200 it = recv_data.send_status_list.begin();
3201 it = find_if(it, it_end, data_send_ok());
3202 //send_ok item is exist
3205 status = REALSERVER_CONNECT;
3207 //send_ok item is exist
3210 status = CLIENT_RECV;
3216 /*-------- DEBUG LOG --------*/
3217 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3219 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3220 "handle_realserver_send() : catch exception e = %d. thread id : %d.");
3221 formatter % e % boost::this_thread::get_id();
3222 putLogDebug(100107, formatter.str(), __FILE__, __LINE__ );
3225 /*------DEBUG LOG END------*/
3227 catch (const std::exception& ex)
3229 std::cerr << "protocol_module_sessionless::handle_realserver_send() : exception : error = " << ex.what() << "." << std::endl;
3230 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3231 "handle_realserver_send() : exception : error = %s. thread id : %d.");
3232 formatter % ex.what() % boost::this_thread::get_id();
3233 putLogError(100056, formatter.str(), __FILE__, __LINE__ );
3239 std::cerr << "protocol_module_sessionless::handle_realserver_send() : Unknown exception." << std::endl;
3240 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3241 "handle_realserver_send() : Unknown exception. thread id : %d.");
3242 formatter % boost::this_thread::get_id();
3243 putLogError(100057, formatter.str(), __FILE__, __LINE__ );
3247 /*-------- DEBUG LOG --------*/
3248 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3250 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3251 "handle_realserver_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
3252 formatter % status % boost::this_thread::get_id();
3253 putLogDebug(100108, formatter.str(), __FILE__, __LINE__ );
3255 /*------DEBUG LOG END------*/
3260 //! called from after sorryserver select
3261 //! @param[in] upstream thread id
3262 //! @param[in] sorryserver endpiont reference
3263 //! @return session use EVENT mode.
3264 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_select(
3265 const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint& sorry_endpoint)
3267 /*-------- DEBUG LOG --------*/
3268 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3270 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3271 "handle_sorryserver_select(const boost::thread::id thread_id, "
3272 "boost::asio::ip::tcp::endpoint& sorry_endpoint) : "
3273 "thread_id = %d, sorry_endpoint = [%s]:%d.");
3274 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port();
3275 putLogDebug(100109, formatter.str(), __FILE__, __LINE__ );
3277 /*------DEBUG LOG END------*/
3278 EVENT_TAG status = FINALIZE;
3279 boost::asio::ip::tcp::endpoint client_endpoint;
3281 thread_data_ptr session_data;
3282 session_thread_data_map_it session_thread_it;
3283 recive_data_map_it recive_data_it;
3287 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
3289 session_thread_it = session_thread_data_map.find(thread_id);
3290 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second== NULL))
3292 boost::format formatter("Invalid thread id. thread id : %d.");
3293 formatter % boost::this_thread::get_id();
3294 putLogError(100058, formatter.str(), __FILE__, __LINE__ );
3298 session_data = session_thread_it->second;
3299 //set sorry_endpoint
3300 session_data->target_endpoint = sorry_endpoint;
3303 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
3304 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
3306 boost::format formatter("Invalid endpoint. thread id : %d.");
3307 formatter % boost::this_thread::get_id();
3308 putLogError(100059, formatter.str(), __FILE__, __LINE__ );
3312 recive_data& recv_data = recive_data_it->second;
3314 send_status_it it = recv_data.send_status_list.begin();
3315 send_status_it it_end = recv_data.send_status_list.end();
3317 it = find_if(it, it_end, data_send_possible());
3320 status = SORRYSERVER_CONNECT;
3324 status = CLIENT_RECV;
3330 /*-------- DEBUG LOG --------*/
3331 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3333 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3334 "handle_sorryserver_select() : catch exception e = %d. thread id : %d.");
3335 formatter % e % boost::this_thread::get_id();
3336 putLogDebug(100110, formatter.str(), __FILE__, __LINE__ );
3339 /*------DEBUG LOG END------*/
3341 catch (const std::bad_alloc& ex)
3343 std::cerr << "protocol_module_sessionless::handle_sorryserver_select() : exception : Could not allocate memory." << std::endl;
3344 boost::format formatter("Could not allocate memory. thread id : %d.");
3345 formatter % boost::this_thread::get_id();
3346 putLogError(100060, formatter.str(), __FILE__, __LINE__ );
3349 catch (const std::exception& ex)
3351 std::cerr << "protocol_module_sessionless::handle_sorryserver_select() : exception : error = " << ex.what() << "." << std::endl;
3352 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3353 "handle_sorryserver_select() : exception : error = %s. thread id : %d.");
3354 formatter % ex.what() % boost::this_thread::get_id();
3355 putLogError(100061, formatter.str(), __FILE__, __LINE__ );
3360 std::cerr << "protocol_module_sessionless::handle_sorryserver_select() : Unknown exception." << std::endl;
3361 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3362 "handle_sorryserver_select() : Unknown exception. thread id : %d.");
3363 formatter % boost::this_thread::get_id();
3364 putLogError(100062, formatter.str(), __FILE__, __LINE__ );
3368 /*-------- DEBUG LOG --------*/
3369 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3373 "out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3374 "handle_sorryserver_select(const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint& sorry_endpoint) : return_value = %d."
3375 " thread id : %d.");
3376 formatter % status % boost::this_thread::get_id();
3377 putLogDebug(100111, formatter.str(), __FILE__, __LINE__ );
3379 /*------DEBUG LOG END------*/
3383 //! called from after sorryserver connect
3384 //! @param[in] upstream thread id
3385 //! @param[out] send buffer reference.
3386 //! @param[out] send length
3387 //! @return session use EVENT mode.
3388 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_connect(
3389 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
3391 /*-------- DEBUG LOG --------*/
3392 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3394 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3395 "handle_sorryserver_connect(const boost::thread::id thread_id, "
3396 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
3398 formatter % thread_id;
3399 putLogDebug(100112, formatter.str(), __FILE__, __LINE__ );
3401 /*------DEBUG LOG END------*/
3402 EVENT_TAG status = FINALIZE;
3404 size_t header_offset = 0;
3405 size_t header_offset_len = 0;
3406 size_t url_offset = 0;
3407 size_t url_offset_len = 0;
3408 size_t send_buffer_remian_size = 0;
3409 size_t copy_size = 0;
3410 const int send_buffer_end_size = sendbuffer.max_size();
3411 const std::string http_header = "";
3412 const std::string str_forword_for = "X-Forwarded-For";
3413 thread_data_ptr session_data;
3414 session_thread_data_map_it session_thread_it;
3415 recive_data_map_it recive_data_it;
3420 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
3423 session_thread_it = session_thread_data_map.find(thread_id);
3424 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3426 boost::format formatter("Invalid thread id. thread id : %d.");
3427 formatter % boost::this_thread::get_id();
3428 putLogError(100063, formatter.str(), __FILE__, __LINE__ );
3432 session_data = session_thread_it->second;
3436 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
3437 if (unlikely(recive_data_it
3438 == session_data->recive_data_map.end()))
3440 boost::format formatter("Invalid endpoint. thread id : %d.");
3441 formatter % boost::this_thread::get_id();
3442 putLogError(100064, formatter.str(), __FILE__, __LINE__ );
3446 //recive_buffer pointer check
3447 recive_data& recv_data = recive_data_it->second;
3448 if (unlikely(recv_data.recive_buffer == NULL))
3450 boost::format formatter("Invalid pointer. thread id : %d.");
3451 formatter % boost::this_thread::get_id();
3452 putLogError(100065, formatter.str(), __FILE__, __LINE__ );
3457 send_status_it it = recv_data.send_status_list.begin();
3458 send_status_it it_end = recv_data.send_status_list.end();
3460 it = find_if(it, it_end, data_send_possible());
3461 if (unlikely(it == it_end))
3463 boost::format formatter("Sending possible data is not existed. thread id : %d.");
3464 formatter % boost::this_thread::get_id();
3465 putLogError(100066, formatter.str(), __FILE__, __LINE__ );
3469 //send buffer rest size initialization
3470 send_buffer_remian_size = send_buffer_end_size;
3472 //edit_division flag on
3473 if (it->edit_division == EDIT_DIVISION_EDIT)
3475 //edit list is empty
3476 if (it->edit_data_list.empty())
3480 edata.data_size = 0;
3481 edata.insert_posission = 0;
3482 edata.replace_size = 0;
3484 if (strlen(sorry_uri.data()) > 0)
3486 ret = find_uri(recv_data.recive_buffer + it->send_offset, it->send_possible_size, url_offset,
3488 /*-------- DEBUG LOG --------*/
3489 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3491 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3492 "handle_sorryserver_connect() : call find_uri : "
3493 "return_value = %d. thread id : %d.");
3494 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
3495 putLogDebug(100113, formatter.str(), __FILE__, __LINE__ );
3497 /*------DEBUG LOG END------*/
3498 //search http header result is OK
3501 //edit sorry_uri, put it to edata.data
3502 edata.data = sorry_uri.data();
3503 //save new uri offset
3504 edata.insert_posission = url_offset;
3505 //save new uri length
3506 edata.data_size = edata.data.size();
3507 //save old uri length
3508 edata.replace_size = url_offset_len;
3509 //add to edit_data_list
3510 it->edit_data_list.push_back(edata);
3514 if (forwarded_for == FORWARDED_FOR_ON)
3516 //search X-Forwarded-For header
3517 ret = find_http_header(recv_data.recive_buffer + it->send_offset, it->send_possible_size,
3518 str_forword_for.c_str(), header_offset, header_offset_len);
3519 /*-------- DEBUG LOG --------*/
3520 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3522 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3523 "handle_sorryserver_connect() : call find_http_header : "
3524 "return_value = %d. thread id : %d.");
3525 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
3526 putLogDebug(100114, formatter.str(), __FILE__, __LINE__ );
3528 /*------DEBUG LOG END------*/
3530 //search http header result is OK
3533 //edit X-Forwarded-For header, put it to edata.data
3534 edata.data.assign(recv_data.recive_buffer + it->send_offset + header_offset, header_offset_len);
3536 edata.data += session_data->client_endpoint_tcp.address().to_string();
3537 //save new X-Forwarded-For header offset
3538 edata.insert_posission = header_offset;
3539 //save new X-Forwarded-For header length
3540 edata.data_size = edata.data.size();
3541 //save old X-Forwarded-For header length
3542 edata.replace_size = header_offset_len;
3544 //search http header result is NG
3547 //search whole http header, get whole http header's offset and length
3548 ret = find_http_header(recv_data.recive_buffer + it->send_offset, it->send_possible_size, "",
3549 header_offset, header_offset_len);
3550 /*-------- DEBUG LOG --------*/
3551 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3553 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3554 "handle_sorryserver_connect() : call find_http_header : "
3555 "return_value = %d. thread id : %d.");
3556 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
3557 putLogDebug(100115, formatter.str(), __FILE__, __LINE__ );
3559 /*------DEBUG LOG END------*/
3562 boost::format formatter("find_http_header() function failure. thread id : %d.");
3563 formatter % boost::this_thread::get_id();
3564 putLogError(100067, formatter.str(), __FILE__, __LINE__ );
3565 /*-------- DEBUG LOG --------*/
3566 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3568 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3569 "handle_sorryserver_connect(const boost::thread::id thread_id, "
3570 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
3571 "size_t& datalen) : return_value = %d. thread id : %d.");
3572 formatter % FINALIZE % boost::this_thread::get_id();
3573 putLogDebug(100116, formatter.str(), __FILE__, __LINE__ );
3575 /*------DEBUG LOG END------*/
3578 //create X-Forwarded-For header, set it to edata.data
3579 edata.data = str_forword_for;
3581 edata.data += session_data->client_endpoint_tcp.address().to_string();
3582 edata.data += "\r\n";
3583 //save new X-Forwarded-For header offset
3584 edata.insert_posission = header_offset;
3585 //save new X-Forwarded-For header length
3586 edata.data_size = edata.data.size();
3587 //save old X-Forwarded-For header length
3588 edata.replace_size = 0;
3591 //add to edit_data_list
3592 it->edit_data_list.push_back(edata);
3596 /*-------- DEBUG LOG --------*/
3597 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3599 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3600 "handle_sorryserver_connect() : Copy data loop start. thread id : %d.");
3601 formatter % boost::this_thread::get_id();
3602 putLogDebug(100117, formatter.str(), __FILE__, __LINE__ );
3604 /*------DEBUG LOG END------*/
3607 //edit_data_list is empty
3608 if (it->edit_data_list.empty())
3610 //set edit_division flag off
3611 it->edit_division = EDIT_DIVISION_NO_EDIT;
3613 if (send_buffer_remian_size > 0 && it->send_possible_size > 0)
3615 //send_buffer_remian_size is larger
3616 if (send_buffer_remian_size > it->send_possible_size)
3618 //copy data from recive_buffer to sendbuffer by sending_possible size
3619 copy_size = it->send_possible_size;
3620 /*-------- DEBUG LOG --------*/
3621 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3623 std::string datadump;
3624 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
3625 copy_size, datadump);
3626 boost::format formatter(
3627 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3628 "handle_sorryserver_connect() : before memcpy (data dump) : "
3629 "data begin = %d, data_size = %d, data = %s");
3630 formatter % (it->send_offset + it->send_end_size)
3631 % copy_size % datadump;
3632 putLogDebug(100118, formatter.str(), __FILE__, __LINE__ );
3634 /*------DEBUG LOG END------*/
3635 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3636 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
3637 /*-------- DEBUG LOG --------*/
3638 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3640 std::string datadump;
3641 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3642 copy_size, datadump);
3643 boost::format formatter(
3644 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3645 "handle_sorryserver_connect() : after memcpy (data dump) : "
3646 "data begin = %d, data_size = %d, data = %s");
3647 formatter % (send_buffer_end_size - send_buffer_remian_size)
3648 % copy_size % datadump;
3649 putLogDebug(100119, formatter.str(), __FILE__, __LINE__ );
3651 /*------DEBUG LOG END------*/
3652 it->send_end_size += copy_size;
3653 it->send_possible_size = 0;
3654 send_buffer_remian_size -= copy_size;
3656 //send_possible_size is larger
3659 copy_size = send_buffer_remian_size;
3660 /*-------- DEBUG LOG --------*/
3661 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3663 std::string datadump;
3664 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
3665 copy_size, datadump);
3666 boost::format formatter(
3667 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3668 "handle_sorryserver_connect() : before memcpy (data dump) : "
3669 "data begin = %d, data_size = %d, data = %s");
3670 formatter % (it->send_offset + it->send_end_size)
3671 % copy_size % datadump;
3672 putLogDebug(100120, formatter.str(), __FILE__, __LINE__ );
3674 /*------DEBUG LOG END------*/
3675 //copy data from recive_buffer to sendbuffer by send buffer rest size
3676 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3677 recv_data.recive_buffer + it->send_offset + it->send_end_size,
3679 /*-------- DEBUG LOG --------*/
3680 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3682 std::string datadump;
3683 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3684 copy_size, datadump);
3685 boost::format formatter(
3686 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3687 "handle_sorryserver_connect() : after memcpy (data dump) : "
3688 "data begin = %d, data_size = %d, data = %s");
3689 formatter % (send_buffer_end_size - send_buffer_remian_size)
3690 % copy_size % datadump;
3691 putLogDebug(100121, formatter.str(), __FILE__, __LINE__ );
3693 /*------DEBUG LOG END------*/
3694 it->send_end_size += copy_size;
3695 it->send_possible_size -= copy_size;
3696 send_buffer_remian_size = 0;
3702 //edit_data_list is not empty
3705 //search item which insert_posission is mininum
3706 std::list<edit_data>::iterator edit_min = std::min_element(it->edit_data_list.begin(),
3707 it->edit_data_list.end());
3708 //send_buffer_remian_size is larger than data that before X-Forwarded-For/uri
3709 if (send_buffer_remian_size >= edit_min->insert_posission - it->send_end_size)
3711 //copy data before X-Forwarded-For/url
3712 copy_size = edit_min->insert_posission - it->send_end_size;
3713 /*-------- DEBUG LOG --------*/
3714 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3716 std::string datadump;
3717 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
3718 copy_size, datadump);
3720 boost::format formatter(
3721 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3722 "handle_sorryserver_connect() : before memcpy (data dump) : "
3723 "data begin = %d, data_size = %d, data = %s");
3724 formatter % (it->send_offset + it->send_end_size)
3725 % copy_size % datadump;
3726 putLogDebug(100122, formatter.str(), __FILE__, __LINE__ );
3728 /*------DEBUG LOG END------*/
3729 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3730 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
3731 /*-------- DEBUG LOG --------*/
3732 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3734 std::string datadump;
3735 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3736 copy_size, datadump);
3737 boost::format formatter(
3738 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3739 "handle_sorryserver_connect() : after memcpy (data dump) : "
3740 "data begin = %d, data_size = %d, data = %s");
3741 formatter % (send_buffer_end_size - send_buffer_remian_size)
3742 % copy_size % datadump;
3743 putLogDebug(100123, formatter.str(), __FILE__, __LINE__ );
3745 /*------DEBUG LOG END------*/
3746 it->send_end_size += copy_size;
3747 it->send_possible_size -= copy_size;
3748 send_buffer_remian_size -= copy_size;
3750 //there is remain buffer for copy X-Forwarded-For/url
3751 if (send_buffer_remian_size >= edit_min->data_size)
3753 /*-------- DEBUG LOG --------*/
3754 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3756 std::string datadump;
3757 dump_memory(edit_min->data.c_str(),
3758 edit_min->data_size, datadump);
3759 boost::format formatter(
3760 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3761 "handle_sorryserver_connect() : before memcpy (data dump) : "
3762 "data begin = 0, data_size = %d, data = %s");
3763 formatter % edit_min->data_size % datadump;
3764 putLogDebug(100124, formatter.str(), __FILE__, __LINE__ );
3766 /*------DEBUG LOG END------*/
3767 //copy X-Forwarded-For/uri
3768 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3769 edit_min->data.c_str(), edit_min->data_size);
3770 /*-------- DEBUG LOG --------*/
3771 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3773 std::string datadump;
3774 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3775 edit_min->data_size, datadump);
3777 boost::format formatter(
3778 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3779 "handle_sorryserver_connect() : after memcpy (data dump) : "
3780 "data begin = %d, data_size = %d, data = %s");
3781 formatter % (send_buffer_end_size - send_buffer_remian_size)
3782 % edit_min->data_size % datadump;
3783 putLogDebug(100125, formatter.str(), __FILE__, __LINE__ );
3785 /*------DEBUG LOG END------*/
3786 it->send_end_size += edit_min->replace_size;
3787 it->send_possible_size -= edit_min->replace_size;
3788 send_buffer_remian_size -= edit_min->data_size;
3789 it->edit_data_list.erase(edit_min);
3797 //data that before X-Forwarded-For/uri is larger than send_buffer_remian_size
3800 copy_size = send_buffer_remian_size;
3801 /*-------- DEBUG LOG --------*/
3802 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3804 std::string datadump;
3805 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3806 copy_size, datadump);
3808 boost::format formatter(
3809 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3810 "handle_sorryserver_connect() : before memcpy (data dump) : "
3811 "data begin = %d, data_size = %d, data = %s");
3812 formatter % (it->send_offset + it->send_end_size)
3813 % copy_size % datadump;
3814 putLogDebug(100126, formatter.str(), __FILE__, __LINE__ );
3816 /*------DEBUG LOG END------*/
3817 //copy data as large as possible
3818 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3819 recv_data.recive_buffer + it->send_offset + it->send_end_size, send_buffer_remian_size);
3820 /*-------- DEBUG LOG --------*/
3821 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3823 std::string datadump;
3824 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3825 copy_size, datadump);
3827 boost::format formatter(
3828 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3829 "handle_sorryserver_connect() : after memcpy (data dump) : "
3830 "data begin = %d, data_size = %d, data = %s");
3831 formatter % (send_buffer_end_size - send_buffer_remian_size)
3832 % copy_size % datadump;
3833 putLogDebug(100127, formatter.str(), __FILE__, __LINE__ );
3835 /*------DEBUG LOG END------*/
3836 it->send_end_size += copy_size;
3837 it->send_possible_size -= copy_size;
3838 send_buffer_remian_size -= copy_size;
3843 /*-------- DEBUG LOG --------*/
3844 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3846 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3847 "handle_sorryserver_connect() : Copy data loop end. thread id : %d.");
3848 formatter % boost::this_thread::get_id();
3849 putLogDebug(100128, formatter.str(), __FILE__, __LINE__ );
3851 /*------DEBUG LOG END------*/
3853 //edit_division flag is off
3856 //copy data as large as possible
3857 //send_possible_size is larger
3858 if (send_buffer_remian_size >= it->send_possible_size)
3860 copy_size = it->send_possible_size;
3861 /*-------- DEBUG LOG --------*/
3862 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3864 std::string datadump;
3865 dump_memory(recv_data.recive_buffer+ it->send_offset, copy_size, datadump);
3867 boost::format formatter(
3868 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3869 "handle_sorryserver_connect() : before memcpy (data dump) : "
3870 "data begin = %d, data_size = %d, data = %s");
3871 formatter % it->send_offset
3872 % copy_size % datadump;
3873 putLogDebug(100129, formatter.str(), __FILE__, __LINE__ );
3875 /*------DEBUG LOG END------*/
3876 //copy data by send_possible size
3877 memcpy(sendbuffer.data(), recv_data.recive_buffer
3878 + it->send_offset, copy_size);
3879 /*-------- DEBUG LOG --------*/
3880 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3882 std::string datadump;
3883 dump_memory(sendbuffer.data(), copy_size, datadump);
3885 boost::format formatter(
3886 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3887 "handle_sorryserver_connect() : after memcpy (data dump) : "
3888 "data begin = 0, data_size = %d, data = %s");
3889 formatter % copy_size % datadump;
3890 putLogDebug(100130, formatter.str(), __FILE__, __LINE__ );
3892 /*------DEBUG LOG END------*/
3893 it->send_end_size = it->send_possible_size;
3894 it->send_possible_size = 0;
3895 send_buffer_remian_size -= copy_size;
3897 //buffer rest size is larger
3900 /*-------- DEBUG LOG --------*/
3901 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3903 std::string datadump;
3904 dump_memory(recv_data.recive_buffer+ it->send_offset, send_buffer_remian_size, datadump);
3906 boost::format formatter(
3907 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3908 "handle_sorryserver_connect() : before memcpy (data dump) : "
3909 "data begin = %d, data_size = %d, data = %s");
3910 formatter % it->send_offset
3911 % send_buffer_remian_size % datadump;
3912 putLogDebug(100131, formatter.str(), __FILE__, __LINE__ );
3914 /*------DEBUG LOG END------*/
3915 //copy data by buffer rest size
3916 memcpy(sendbuffer.data(), recv_data.recive_buffer
3917 + it->send_offset, send_buffer_remian_size);
3918 /*-------- DEBUG LOG --------*/
3919 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3921 std::string datadump;
3922 dump_memory(sendbuffer.data(), send_buffer_remian_size, datadump);
3924 boost::format formatter(
3925 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3926 "handle_sorryserver_connect() : after memcpy (data dump) : "
3927 "data begin = 0, data_size = %d, data = %s");
3928 formatter % send_buffer_remian_size % datadump;
3929 putLogDebug(100132, formatter.str(), __FILE__, __LINE__ );
3931 /*------DEBUG LOG END------*/
3932 it->send_end_size = send_buffer_remian_size;
3933 it->send_possible_size -= send_buffer_remian_size;
3934 send_buffer_remian_size = 0;
3938 //set copyed data length
3939 datalen = send_buffer_end_size - send_buffer_remian_size;
3941 status = SORRYSERVER_SEND;
3946 /*-------- DEBUG LOG --------*/
3947 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3949 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3950 "handle_sorryserver_connect() : catch exception e = %d. thread id : %d.");
3951 formatter % e % boost::this_thread::get_id();
3952 putLogDebug(100133, formatter.str(), __FILE__, __LINE__ );
3955 /*------DEBUG LOG END------*/
3957 catch (const std::exception& ex)
3959 std::cerr << "protocol_module_sessionless::handle_sorryserver_connect() : exception : error = " << ex.what() << "." << std::endl;
3960 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3961 "handle_sorryserver_connect() : exception : error = %s. thread id : %d.");
3962 formatter % ex.what() % boost::this_thread::get_id();
3963 putLogError(100068, formatter.str(), __FILE__, __LINE__ );
3968 std::cerr << "protocol_module_sessionless::handle_sorryserver_connect() : Unknown exception." << std::endl;
3969 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3970 "handle_sorryserver_connect() : Unknown exception. thread id : %d.");
3971 formatter % boost::this_thread::get_id();
3972 putLogError(100069, formatter.str(), __FILE__, __LINE__ );
3976 /*-------- DEBUG LOG --------*/
3977 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3979 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3980 "handle_sorryserver_connect(const boost::thread::id thread_id, "
3981 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
3982 "size_t& datalen) : return_value = %d. thread id : %d.");
3983 formatter % status % boost::this_thread::get_id();
3984 putLogDebug(100134, formatter.str(), __FILE__, __LINE__ );
3986 /*------DEBUG LOG END------*/
3991 //! called from after sorryserver connection fail
3992 //! @param[in] upstream thread id
3993 //! @param[in] sorryserver endpoint reference.
3994 //! @return session use EVENT mode.
3995 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_connection_fail(
3996 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint)
3998 /*-------- DEBUG LOG --------*/
3999 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4001 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4002 "handle_sorryserver_connection_fail(const boost::thread::id thread_id, "
4003 "const boost::asio::ip::tcp::endpoint & sorry_endpoint) : "
4004 "thread_id = %d, sorry_endpoint = [%s]:%d.");
4005 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port();
4006 putLogDebug(100135, formatter.str(), __FILE__, __LINE__ );
4008 /*------DEBUG LOG END------*/
4010 EVENT_TAG status = FINALIZE;
4011 thread_data_ptr session_data;
4012 session_thread_data_map_it session_thread_it;
4016 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
4018 session_thread_it = session_thread_data_map.find(thread_id);
4019 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
4021 boost::format formatter("Invalid thread id. thread id : %d.");
4022 formatter % boost::this_thread::get_id();
4023 putLogError(100070, formatter.str(), __FILE__, __LINE__ );
4027 session_data = session_thread_it->second;
4030 session_data->end_flag = END_FLAG_ON;
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() : END_FLAG_ON. thread id : %d.");
4036 formatter % boost::this_thread::get_id();
4037 putLogDebug(100136, formatter.str(), __FILE__, __LINE__ );
4039 /*------DEBUG LOG END------*/
4041 status = CLIENT_DISCONNECT;
4045 /*-------- DEBUG LOG --------*/
4046 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4048 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4049 "handle_sorryserver_connection_fail() : catch exception e = %d. thread id : %d.");
4050 formatter % e % boost::this_thread::get_id();
4051 putLogDebug(100137, formatter.str(), __FILE__, __LINE__ );
4054 /*------DEBUG LOG END------*/
4056 catch (const std::exception& ex)
4058 std::cerr << "protocol_module_sessionless::handle_sorryserver_connection_fail() : exception : error=" << ex.what() << "." << std::endl;
4059 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4060 "handle_sorryserver_connection_fail() : exception : error = %s. thread id : %d.");
4061 formatter % ex.what() % boost::this_thread::get_id();
4062 putLogError(100071, formatter.str(), __FILE__, __LINE__ );
4067 std::cerr << "protocol_module_sessionless::handle_sorryserver_connection_fail() : Unknown exception." << std::endl;
4068 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4069 "handle_sorryserver_connection_fail() : Unknown exception. thread id : %d.");
4070 formatter % boost::this_thread::get_id();
4071 putLogError(100072, formatter.str(), __FILE__, __LINE__ );
4075 /*-------- DEBUG LOG --------*/
4076 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4080 "out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4081 "handle_sorryserver_connection_fail( const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint) : return_value = %d."
4082 " thread id : %d.");
4083 formatter % status % boost::this_thread::get_id();
4084 putLogDebug(100138, formatter.str(), __FILE__, __LINE__ );
4086 /*------DEBUG LOG END------*/
4090 //! called from after sorryserver send
4091 //! @param[in] upstream thread id
4092 //! @return session use EVENT mode.
4093 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_send(
4094 const boost::thread::id thread_id)
4096 /*-------- DEBUG LOG --------*/
4097 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4099 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4100 "handle_sorryserver_send(const boost::thread::id thread_id) : "
4102 formatter % thread_id;
4103 putLogDebug(100139, formatter.str(), __FILE__, __LINE__ );
4105 /*------DEBUG LOG END------*/
4106 EVENT_TAG status = FINALIZE;
4107 thread_data_ptr session_data;
4108 session_thread_data_map_it session_thread_it;
4109 recive_data_map_it recive_data_it;
4114 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
4117 session_thread_it = session_thread_data_map.find(thread_id);
4118 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
4120 boost::format formatter("Invalid thread id. thread id : %d.");
4121 formatter % boost::this_thread::get_id();
4122 putLogError(100073, formatter.str(), __FILE__, __LINE__ );
4126 session_data = session_thread_it->second;
4130 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
4131 if (unlikely(recive_data_it
4132 == session_data->recive_data_map.end()))
4134 boost::format formatter("Invalid endpoint. thread id : %d.");
4135 formatter % boost::this_thread::get_id();
4136 putLogError(100074, formatter.str(), __FILE__, __LINE__ );
4140 recive_data& recv_data = recive_data_it->second;
4142 send_status_it it = recv_data.send_status_list.begin();
4143 send_status_it it_end = recv_data.send_status_list.end();
4145 it = std::adjacent_find(it, it_end, data_send_list_incorrect());
4146 if (unlikely(it != it_end))
4148 boost::format formatter("Sending possible data is invalid. thread id : %d.");
4149 formatter % boost::this_thread::get_id();
4150 putLogError(100075, formatter.str(), __FILE__, __LINE__ );
4155 it = recv_data.send_status_list.begin();
4156 it = find_if(it, it_end, data_send_ok());
4157 if (unlikely(it == it_end))
4159 boost::format formatter("Sending possible data is not existed. thread id : %d.");
4160 formatter % boost::this_thread::get_id();
4161 putLogError(100076, formatter.str(), __FILE__, __LINE__ );
4165 //sending possible data is exist
4166 if (it->send_possible_size > 0)
4168 //status remain SEND_OK
4169 it->status = SEND_OK;
4171 it->send_offset += it->send_end_size;
4173 //insert_posission recalc
4174 for (std::list<edit_data>::iterator list_it = it->edit_data_list.begin(); list_it
4175 != it->edit_data_list.end(); ++list_it)
4177 list_it->insert_posission -= it->send_end_size;
4180 //send_end_size recalc
4181 it->send_end_size = 0;
4183 //sending possible data is not exist
4186 //can recive from clent continue
4187 if (it->send_rest_size > 0)
4189 //change status from SEND_OK to SEND_CONTINUE
4190 it->status = SEND_CONTINUE;
4192 //can not recive from clent continue
4195 //change status from SEND_OK to SEND_END
4196 it->status = SEND_END;
4200 it = recv_data.send_status_list.begin();
4201 it = find_if(it, it_end, data_send_ok());
4202 //send_ok item is exist
4205 status = SORRYSERVER_CONNECT;
4207 //send_ok item is exist
4210 status = CLIENT_RECV;
4216 /*-------- DEBUG LOG --------*/
4217 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4219 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4220 "handle_sorryserver_send() : catch exception e = %d. thread id : %d.");
4221 formatter % e % boost::this_thread::get_id();
4222 putLogDebug(100140, formatter.str(), __FILE__, __LINE__ );
4225 /*------DEBUG LOG END------*/
4227 catch (const std::exception& ex)
4229 std::cerr << "protocol_module_sessionless::handle_sorryserver_send() : exception : error = " << ex.what() << "." << std::endl;
4230 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4231 "handle_sorryserver_send() : exception : error = %s. thread id : %d.");
4232 formatter % ex.what() % boost::this_thread::get_id();
4233 putLogError(100077, formatter.str(), __FILE__, __LINE__ );
4239 std::cerr << "protocol_module_sessionless::handle_sorryserver_send() : Unknown exception." << std::endl;
4240 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4241 "handle_sorryserver_send() : Unknown exception. thread id : %d.");
4242 formatter % boost::this_thread::get_id();
4243 putLogError(100078, formatter.str(), __FILE__, __LINE__ );
4247 /*-------- DEBUG LOG --------*/
4248 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4250 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4251 "handle_sorryserver_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
4252 formatter % status % boost::this_thread::get_id();
4253 putLogDebug(100141, formatter.str(), __FILE__, __LINE__ );
4255 /*------DEBUG LOG END------*/
4260 //! called from after realserver recive.for UDP
4261 //! @param[in] downstream thread id
4262 //! @param[in] realserver UDP endpoint reference
4263 //! @param[in] recive from realserver buffer reference
4264 //! @param[in] recv data length
4265 //! @return session use EVENT mode.
4266 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_recv(
4267 const boost::thread::id thread_id, const boost::asio::ip::udp::endpoint& rs_endpoint, const boost::array<char,
4268 MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
4270 /*-------- DEBUG LOG --------*/
4271 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4273 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4274 "handle_realserver_recv(const boost::thread::id thread_id, "
4275 "const boost::asio::ip::udp::endpoint& rs_endpoint, "
4276 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4277 "const size_t recvlen) : "
4278 "return_value = %d. thread id : %d.");
4279 formatter % STOP % boost::this_thread::get_id();
4280 putLogDebug(100142, formatter.str(), __FILE__, __LINE__ );
4282 /*------DEBUG LOG END------*/
4286 //! called from after realserver recvive for TCP/IP
4287 //! @param[in] downstream thread id
4288 //! @param[in] realserver TCP/IP endpoint reference
4289 //! @param[in] realserver recive buffer reference.
4290 //! @param[in] recv data length
4291 //! @return session use EVENT mode.
4292 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_recv(
4293 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint& rs_endpoint, const boost::array<char,
4294 MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
4296 /*-------- DEBUG LOG --------*/
4297 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4299 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
4301 dump_memory(recvbuffer.data(), buffer_size, buffer);
4302 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4303 "handle_realserver_recv(const boost::thread::id thread_id, "
4304 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
4305 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4306 "const size_t recvlen) : thread_id = %d, rs_endpoint = [%s]:%d, recvbuffer = %s, recvlen = %d.");
4307 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port()
4309 putLogDebug(100143, formatter.str(), __FILE__, __LINE__ );
4311 /*------DEBUG LOG END------*/
4313 EVENT_TAG status = FINALIZE;
4314 size_t data_remain_start = 0;
4315 size_t data_remain_size = 0;
4316 size_t request_data_remain_size = 0;
4317 size_t header_offset = 0;
4318 size_t header_offset_len = 0;
4319 size_t content_length_header_offset = 0;
4320 size_t content_length_header_len = 0;
4321 size_t content_len_value = 0;
4323 size_t buffer_size = 0;
4324 const size_t cr_lf_cr_lf_len = strlen("\r\n\r\n");
4325 const size_t cr_lf_len = strlen("\r\n");
4326 thread_data_ptr session_data;
4327 char* buffer1 = NULL;
4328 char* buffer2 = NULL;
4329 std::string str_value;
4330 const std::string http_header = "";
4331 const std::string content_header = "Content-Length";
4333 CHECK_RESULT_TAG check_result;
4334 session_thread_data_map_it session_thread_it;
4335 recive_data_map_it recive_data_it;
4338 if (recvlen > recvbuffer.size())
4340 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : Data size bigger than buffer size." << std::endl;
4341 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
4342 formatter % boost::this_thread::get_id();
4343 putLogError(100079, formatter.str(), __FILE__, __LINE__ );
4344 /*-------- DEBUG LOG --------*/
4345 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4347 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4348 "handle_realserver_recv(const boost::thread::id thread_id, "
4349 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
4350 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4351 "const size_t recvlen) : return_value = %d. thread id : %d.");
4352 formatter % FINALIZE % boost::this_thread::get_id();
4353 putLogDebug(100144, formatter.str(), __FILE__, __LINE__ );
4355 /*------DEBUG LOG END------*/
4362 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
4364 session_thread_it = session_thread_data_map.find(thread_id);
4365 if (unlikely(session_thread_it == session_thread_data_map.end()
4366 ||session_thread_it->second == NULL))
4368 boost::format formatter("Invalid thread id. thread id : %d.");
4369 formatter % boost::this_thread::get_id();
4370 putLogError(100080, formatter.str(), __FILE__, __LINE__ );
4374 session_data = session_thread_it->second;
4377 recive_data_it = session_data->recive_data_map.find(rs_endpoint);
4378 if (recive_data_it == session_data->recive_data_map.end())
4380 recive_data recv_data;
4381 session_data->recive_data_map[rs_endpoint] = recv_data;
4384 session_data->target_endpoint = rs_endpoint;
4386 recive_data& recv_data = session_data->recive_data_map[rs_endpoint];
4388 send_status_it it = recv_data.send_status_list.begin();
4389 send_status_it it_end = recv_data.send_status_list.end();
4392 it = std::find_if(it, it_end, data_send_ok());
4393 if (unlikely(it != it_end))
4395 boost::format formatter("Sending data is not correct. thread id : %d.");
4396 formatter % boost::this_thread::get_id();
4397 putLogError(100081, formatter.str(), __FILE__, __LINE__ );
4402 it = recv_data.send_status_list.begin();
4403 it = std::adjacent_find(it, it_end, data_send_repeated());
4404 if (unlikely(it != it_end))
4406 boost::format formatter("Sending data is not correct. thread id : %d.");
4407 formatter % boost::this_thread::get_id();
4408 putLogError(100082, formatter.str(), __FILE__, __LINE__ );
4412 /*-------- DEBUG LOG --------*/
4413 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4415 std::string datadump;
4416 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
4417 "send_rest_size = %d, send_possible_size = %d, "
4418 "send_offset = %d, unsend_size = %d, edit_division = %d.");
4420 for (it = recv_data.send_status_list.begin();
4421 it != recv_data.send_status_list.end();
4424 formatter % i % it->status % it->send_end_size
4425 % it->send_rest_size % it->send_possible_size
4426 % it->send_offset % it->unsend_size % it->edit_division;
4427 datadump += formatter.str();
4430 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4431 "handle_realserver_recv() : send status list dump : send status list size = %d.%s");
4433 formatter % recv_data.send_status_list.size() % datadump;
4434 putLogDebug(100145, formatter.str(), __FILE__, __LINE__ );
4436 /*------DEBUG LOG END------*/
4437 it = recv_data.send_status_list.begin();
4438 //get original status info
4439 while (it != it_end)
4441 //item status is SEND_END
4442 if (it->status == SEND_END)
4445 recv_data.send_status_list.erase(it++);
4448 //item status is SEND_CONTINUE
4449 else if (it->status == SEND_CONTINUE)
4451 it->send_offset += it->send_end_size;
4452 data_remain_start = it->send_offset;
4455 //item status is SEND_NG
4458 data_remain_start = it->send_offset;
4459 data_remain_size = it->unsend_size;
4465 /*-------- DEBUG LOG --------*/
4466 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4468 std::string datadump;
4469 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
4470 "send_rest_size = %d, send_possible_size = %d, "
4471 "send_offset = %d, unsend_size = %d, edit_division = %d.");
4473 for (it = recv_data.send_status_list.begin();
4474 it != recv_data.send_status_list.end();
4477 formatter % i % it->status % it->send_end_size
4478 % it->send_rest_size % it->send_possible_size
4479 % it->send_offset % it->unsend_size % it->edit_division;
4480 datadump += formatter.str();
4483 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4484 "handle_realserver_recv() : send status list dump : send status list size = %d.%s");
4486 formatter % recv_data.send_status_list.size() % datadump;
4487 putLogDebug(100146, formatter.str(), __FILE__, __LINE__ );
4489 /*------DEBUG LOG END------*/
4490 //recive buffer process
4491 //buffer rest size < request size
4492 if (recv_data.recive_buffer_rest_size < recvlen)
4494 //buffer max size < remain size + request size
4495 //buffer is need reallocate
4496 if (recv_data.recive_buffer_max_size < data_remain_size + recvlen)
4498 //the buffer's size that will be allocated is exceed the upper limit value
4499 if (MAX_SESSIONLESS_MODULE_BUFFER_SIZE < data_remain_size + recvlen)
4501 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : the buffer's size that will be allacted is exceed the upper limit value." << std::endl;
4502 boost::format formatter("The buffer's size that will be allocated is exceed the upper limit value. thread id : %d.");
4503 formatter % boost::this_thread::get_id();
4504 putLogError(100083, formatter.str(), __FILE__, __LINE__ );
4506 /*-------- DEBUG LOG --------*/
4507 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4509 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4510 "handle_realserver_recv(const boost::thread::id thread_id, "
4511 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
4512 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4513 "const size_t recvlen) : return_value = %d. thread id : %d.");
4514 formatter % FINALIZE % boost::this_thread::get_id();
4515 putLogDebug(100147, formatter.str(), __FILE__, __LINE__ );
4517 /*------DEBUG LOG END------*/
4521 //recive_buffer1's memory allocate and initialization
4522 buffer_size = (data_remain_size + recvlen) > MAX_BUFFER_SIZE ? (data_remain_size + recvlen) : MAX_BUFFER_SIZE;
4523 buffer1 = new char[buffer_size];
4524 /*-------- DEBUG LOG --------*/
4525 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4527 boost::format formatter("new : address = &(%d), size = %lu.");
4528 formatter % static_cast<void*>(buffer1) % buffer_size;
4529 putLogDebug(100148, formatter.str(), __FILE__, __LINE__ );
4531 /*-------- DEBUG LOG --------*/
4532 memset(buffer1, 0, buffer_size);
4533 //recive_buffer2's memory allocate and initialization
4534 buffer2 = new char[buffer_size];
4535 /*-------- DEBUG LOG --------*/
4536 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4538 boost::format formatter("new : address = &(%d), size = %lu.");
4539 formatter % static_cast<void*>(buffer2) % buffer_size;
4540 putLogDebug(100149, formatter.str(), __FILE__, __LINE__ );
4542 /*-------- DEBUG LOG END--------*/
4543 memset(buffer2, 0, buffer_size);
4545 /*-------- DEBUG LOG --------*/
4546 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4548 std::string datadump;
4549 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
4551 boost::format formatter(
4552 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4553 "handle_realserver_recv() : before memcpy (data dump) : "
4554 "data begin = %d, data_size = %d, data = %s");
4555 formatter % data_remain_start % data_remain_size % datadump;
4556 putLogDebug(100150, formatter.str(), __FILE__, __LINE__ );
4558 /*------DEBUG LOG END------*/
4559 //copy data from old buffer to new buffer
4560 memcpy(buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
4561 /*-------- DEBUG LOG --------*/
4562 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4564 std::string datadump;
4565 dump_memory(buffer1, data_remain_size, datadump);
4567 boost::format formatter(
4568 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4569 "handle_realserver_recv() : after memcpy (data dump) : "
4570 "data begin = 0, data_size = %d, data = %s");
4571 formatter % data_remain_size % datadump;
4572 putLogDebug(100151, formatter.str(), __FILE__, __LINE__ );
4574 /*------DEBUG LOG END------*/
4576 /*-------- DEBUG LOG --------*/
4577 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4579 std::string datadump;
4580 dump_memory(recvbuffer.data(), recvlen, datadump);
4581 boost::format formatter(
4582 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4583 "handle_realserver_recv() : before memcpy (data dump) : "
4584 "data begin = 0, data_size = %d, data = %s");
4585 formatter % recvlen % datadump;
4586 putLogDebug(100152, formatter.str(), __FILE__, __LINE__ );
4588 /*------DEBUG LOG END------*/
4589 memcpy(buffer1 + data_remain_size, recvbuffer.data(), recvlen);
4590 /*-------- DEBUG LOG --------*/
4591 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4593 std::string datadump;
4594 dump_memory(buffer1 + data_remain_size, recvlen, datadump);
4595 boost::format formatter(
4596 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4597 "handle_realserver_recv() : after memcpy (data dump) : "
4598 "data begin = %d, data_size = %d, data = %s");
4599 formatter % data_remain_size % recvlen % datadump;
4600 putLogDebug(100153, formatter.str(), __FILE__, __LINE__ );
4602 /*------DEBUG LOG END------*/
4603 //free old buffer1 and old buffer2
4604 if (recv_data.recive_buffer1 != 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_buffer1);
4611 putLogDebug(100154, formatter.str(), __FILE__,
4614 /*------DEBUG LOG END------*/
4615 delete[] recv_data.recive_buffer1;
4616 recv_data.recive_buffer1 = NULL;
4619 if (recv_data.recive_buffer2 != NULL)
4621 /*-------- DEBUG LOG --------*/
4622 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4624 boost::format formatter("delete : address = &(%d).");
4625 formatter % static_cast<void*>(recv_data.recive_buffer2);
4626 putLogDebug(100155, formatter.str(), __FILE__,
4629 /*------DEBUG LOG END------*/
4630 delete[] recv_data.recive_buffer2;
4631 recv_data.recive_buffer2 = NULL;
4634 //set new buffer pointer
4635 recv_data.recive_buffer1 = buffer1;
4636 recv_data.recive_buffer2 = buffer2;
4637 recv_data.recive_buffer = recv_data.recive_buffer1;
4638 //set new buffer's max size
4639 recv_data.recive_buffer_max_size = buffer_size;
4641 //buffer's max size >= remain data size + requst size
4642 //buffer isn't need reallocate, but switch
4645 //pointer valid check
4646 if (unlikely(recv_data.recive_buffer1 == NULL || recv_data.recive_buffer2 == NULL))
4648 boost::format formatter("Invalid pointer. thread id : %d.");
4649 formatter % boost::this_thread::get_id();
4650 putLogError(100084, formatter.str(), __FILE__, __LINE__ );
4653 //using buffer is buffer1
4654 if (recv_data.recive_buffer == recv_data.recive_buffer1)
4656 //buffer2 initialization
4657 memset(recv_data.recive_buffer2, 0, recv_data.recive_buffer_max_size);
4658 /*-------- DEBUG LOG --------*/
4659 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4661 std::string datadump;
4662 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
4663 boost::format formatter(
4664 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4665 "handle_realserver_recv() : before memcpy (data dump) : "
4666 "data begin = %d, data_size = %d, data = %s");
4667 formatter % data_remain_start % data_remain_size % datadump;
4668 putLogDebug(100156, formatter.str(), __FILE__, __LINE__ );
4670 /*------DEBUG LOG END------*/
4671 //copy data from buffer1 to buffer2
4672 memcpy(recv_data.recive_buffer2, recv_data.recive_buffer + data_remain_start, data_remain_size);
4673 /*-------- DEBUG LOG --------*/
4674 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4676 std::string datadump;
4677 dump_memory(recv_data.recive_buffer2, data_remain_size, datadump);
4678 boost::format formatter(
4679 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4680 "handle_realserver_recv() : after memcpy (data dump) : "
4681 "data begin = 0, data_size = %d, data = %s");
4682 formatter % data_remain_size % datadump;
4683 putLogDebug(100157, formatter.str(), __FILE__, __LINE__ );
4685 /*------DEBUG LOG END------*/
4686 /*-------- DEBUG LOG --------*/
4687 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4689 std::string datadump;
4690 dump_memory(recvbuffer.data(), recvlen, datadump);
4691 boost::format formatter(
4692 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4693 "handle_realserver_recv() : before memcpy (data dump) : "
4694 "data begin = 0, data_size = %d, data = %s");
4695 formatter % data_remain_size % datadump;
4696 putLogDebug(100158, formatter.str(), __FILE__, __LINE__ );
4698 /*------DEBUG LOG END------*/
4699 memcpy(recv_data.recive_buffer2 + data_remain_size, recvbuffer.data(), recvlen);
4700 /*-------- DEBUG LOG --------*/
4701 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4703 std::string datadump;
4704 dump_memory(recv_data.recive_buffer2 + data_remain_size, recvlen, datadump);
4706 boost::format formatter(
4707 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4708 "handle_realserver_recv() : after memcpy (data dump) : "
4709 "data begin = %d, data_size = %d, data = %s");
4710 formatter % data_remain_size % recvlen % datadump;
4711 putLogDebug(100159, formatter.str(), __FILE__, __LINE__ );
4713 /*------DEBUG LOG END------*/
4714 //set buffer2 as using buffer
4715 recv_data.recive_buffer = recv_data.recive_buffer2;
4717 //using buffer is buffer2
4720 //buffer1 initialization
4721 memset(recv_data.recive_buffer1, 0, recv_data.recive_buffer_max_size);
4722 /*-------- DEBUG LOG --------*/
4723 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4725 std::string datadump;
4726 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
4728 boost::format formatter(
4729 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4730 "handle_realserver_recv() : before memcpy (data dump) : "
4731 "data begin = %d, data_size = %d, data = %s");
4732 formatter % data_remain_start % data_remain_size % datadump;
4733 putLogDebug(100160, formatter.str(), __FILE__, __LINE__ );
4735 /*------DEBUG LOG END------*/
4736 //copy data from buffer2 to buffer1
4737 memcpy(recv_data.recive_buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
4738 /*-------- DEBUG LOG --------*/
4739 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4741 std::string datadump;
4742 dump_memory(recv_data.recive_buffer1, data_remain_size, datadump);
4744 boost::format formatter(
4745 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4746 "handle_realserver_recv() : after memcpy (data dump) : "
4747 "data begin = 0, data_size = %d, data = %s");
4748 formatter % data_remain_size % datadump;
4749 putLogDebug(100161, formatter.str(), __FILE__, __LINE__ );
4751 /*------DEBUG LOG END------*/
4752 /*-------- DEBUG LOG --------*/
4753 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4755 std::string datadump;
4756 dump_memory(recvbuffer.data(), recvlen, datadump);
4758 boost::format formatter(
4759 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4760 "handle_realserver_recv() : before memcpy (data dump) : "
4761 "data begin = 0, data_size = %d, data = %s");
4762 formatter % recvlen % datadump;
4763 putLogDebug(100162, formatter.str(), __FILE__, __LINE__ );
4765 /*------DEBUG LOG END------*/
4766 memcpy(recv_data.recive_buffer1 + data_remain_size, recvbuffer.data(), recvlen);
4767 /*-------- DEBUG LOG --------*/
4768 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4770 std::string datadump;
4771 dump_memory(recv_data.recive_buffer1 + data_remain_size, recvlen, datadump);
4773 boost::format formatter(
4774 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4775 "handle_realserver_recv() : after memcpy (data dump) : "
4776 "data begin = %d, data_size = %d, data = %s");
4777 formatter % data_remain_size % recvlen % datadump;
4778 putLogDebug(100163, formatter.str(), __FILE__, __LINE__ );
4780 /*------DEBUG LOG END------*/
4781 //set buffer1 as using buffer
4782 recv_data.recive_buffer = recv_data.recive_buffer1;
4786 //set buffer's rest size
4787 recv_data.recive_buffer_rest_size = recv_data.recive_buffer_max_size - data_remain_size - recvlen;
4789 //remain_size recalc
4790 data_remain_size += recvlen;
4792 send_status_it it_begin = recv_data.send_status_list.begin();
4793 send_status_it it_end = recv_data.send_status_list.end();
4795 for (; it_begin != it_end; ++it_begin)
4797 it_begin->send_offset -= data_remain_start;
4800 //buffer's rest size >= request size
4804 //pointer valid check
4805 if (unlikely(recv_data.recive_buffer == NULL))
4807 boost::format formatter("Invalid pointer. thread id : %d.");
4808 formatter % boost::this_thread::get_id();
4809 putLogError(100085, formatter.str(), __FILE__, __LINE__ );
4812 /*-------- DEBUG LOG --------*/
4813 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4815 std::string datadump;
4816 dump_memory(recvbuffer.data(), recvlen, datadump);
4817 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4818 "handle_realserver_recv() : before memcpy (data dump) : "
4819 "data begin = 0, data_size = %d, data = %s");
4820 formatter % recvlen % datadump;
4821 putLogDebug(100164, formatter.str(), __FILE__, __LINE__ );
4823 /*------DEBUG LOG END------*/
4825 //copy data from parameter to using buffer
4826 memcpy(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
4827 recvbuffer.data(), recvlen);
4828 /*-------- DEBUG LOG --------*/
4829 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4831 std::string datadump;
4832 dump_memory(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
4834 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4835 "handle_realserver_recv() : before memcpy (data dump) : "
4836 "data begin = %d, data_size = %d, data = %s");
4837 formatter % (recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size )
4838 % recvlen % datadump;
4839 putLogDebug(100165, formatter.str(), __FILE__, __LINE__ );
4841 /*------DEBUG LOG END------*/
4842 //buffer's rest size recalc
4843 recv_data.recive_buffer_rest_size -= recvlen;
4844 //remain data size recalc
4845 data_remain_size += recvlen;
4848 it = recv_data.send_status_list.begin();
4849 it_end = recv_data.send_status_list.end();
4850 //request rest size initialization
4851 request_data_remain_size = recvlen;
4852 //original status process
4853 for (; it != it_end; ++it)
4855 //status is SEND_CONTINUE
4856 if (it->status == SEND_CONTINUE)
4858 //send rest size > request size
4859 if (it->send_rest_size > request_data_remain_size)
4861 //send possible size recalc
4862 it->send_possible_size = request_data_remain_size;
4863 //send rest size recalc
4864 it->send_rest_size -= request_data_remain_size;
4865 //send end size recalc
4866 it->send_end_size = 0;
4867 //request size recalc
4868 request_data_remain_size = 0;
4870 //send rest size <= request size
4873 //send possible size recalc
4874 it->send_possible_size = it->send_rest_size;
4875 //send rest size recalc
4876 request_data_remain_size -= it->send_rest_size;
4877 //send end size recalc
4878 it->send_end_size = 0;
4879 //request size recalc
4880 it->send_rest_size = 0;
4882 //change status from SEND_CONTINUE to SEND_OK
4883 it->status = SEND_OK;
4886 else if (it->status == SEND_NG)
4889 check_result = check_status_code(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_method : "
4895 "return_value = %d. thread id : %d.");
4896 formatter % check_result % boost::this_thread::get_id();
4897 putLogDebug(100166, formatter.str(), __FILE__, __LINE__ );
4899 /*------DEBUG LOG END------*/
4900 //check http method result is OK
4901 if (check_result == CHECK_OK)
4903 //check http version
4904 check_result = check_http_version(recv_data.recive_buffer + it->send_offset, data_remain_size);
4905 /*-------- DEBUG LOG --------*/
4906 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4908 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4909 "handle_realserver_recv() : call check_http_version : "
4910 "return_value = %d. thread id : %d.");
4911 formatter % check_result % boost::this_thread::get_id();
4912 putLogDebug(100167, formatter.str(), __FILE__, __LINE__ );
4914 /*------DEBUG LOG END------*/
4916 //check method and version result is OK
4917 if (check_result == CHECK_OK)
4919 //search http header
4920 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size, http_header,
4921 header_offset, header_offset_len);
4922 /*-------- DEBUG LOG --------*/
4923 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4925 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4926 "handle_realserver_recv() : call find_http_header : "
4927 "return_value = %d. thread id : %d.");
4928 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
4929 putLogDebug(100168, formatter.str(), __FILE__, __LINE__ );
4931 /*------DEBUG LOG END------*/
4932 //search http header result is OK
4935 //search Content_Length header
4936 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size,
4937 content_header, content_length_header_offset, content_length_header_len);
4938 /*-------- DEBUG LOG --------*/
4939 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4941 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4942 "handle_realserver_recv() : call find_http_header : "
4943 "return_value = %d. thread id : %d.");
4944 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
4945 putLogDebug(100169, formatter.str(), __FILE__, __LINE__ );
4947 /*------DEBUG LOG END------*/
4948 //search Content_Length result is OK
4951 //Get Content_Length header's numeric value
4952 for (pos = 0; recv_data.recive_buffer[it->send_offset + content_length_header_offset + pos] != ':' && pos
4953 < content_length_header_len; ++pos)
4955 if (pos == content_length_header_len)
4957 throw std::string("Content_Length field's value is invalid.");
4962 str_value.assign(recv_data.recive_buffer + it->send_offset + content_length_header_offset + pos,
4963 content_length_header_len - pos);
4965 size_t pos_end = str_value.find_last_of('\r');
4966 if (pos_end != std::string::npos)
4968 str_value = str_value.erase(pos_end);
4971 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos)
4974 str_value = str_value.substr(pos);
4978 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
4980 catch (const boost::bad_lexical_cast& ex)
4982 throw std::string("Content_Length field's value is invalid.");
4984 //send_rest_size recalc
4985 //set whole http header's length + Content_Length's value
4986 it->send_rest_size = header_offset + header_offset_len + cr_lf_cr_lf_len + content_len_value;
4988 //search Content_Length result is NG
4991 //send_rest_size recalc
4992 //set whole http header's length
4993 if (header_offset_len == 0)
4995 it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
4998 it->send_rest_size = header_offset + header_offset_len + cr_lf_cr_lf_len;
5002 //search http header result is NG
5005 it->unsend_size += request_data_remain_size;
5006 request_data_remain_size = 0;
5010 //check method and version result is NG
5011 else if (check_result == CHECK_NG)
5013 //send_rest_size recalc
5014 it->send_rest_size = it->unsend_size + request_data_remain_size;
5016 //check method and version result is CHECK_INPOSSIBLE
5019 it->unsend_size += request_data_remain_size;
5020 request_data_remain_size = 0;
5024 //recalc fields value according to send_rest_size and request rest size
5025 if (it->send_rest_size > it->unsend_size + request_data_remain_size)
5027 it->send_possible_size = it->unsend_size+ request_data_remain_size;
5028 it->send_rest_size -= (it->unsend_size + request_data_remain_size);
5029 it->send_end_size = 0;
5030 it->unsend_size = 0;
5031 request_data_remain_size = 0;
5035 it->send_possible_size = it->send_rest_size;
5036 request_data_remain_size = it->unsend_size + request_data_remain_size - it->send_rest_size;
5037 it->send_end_size = 0;
5038 it->unsend_size = 0;
5039 it->send_rest_size = 0;
5042 //change status from SEND_NG to SEND_OK
5043 it->status = SEND_OK;
5045 //no request rest data to process
5046 if (request_data_remain_size <= 0)
5052 /*-------- DEBUG LOG --------*/
5053 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5055 std::string datadump;
5056 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
5057 "send_rest_size = %d, send_possible_size = %d, "
5058 "send_offset = %d, unsend_size = %d, edit_division = %d.");
5060 for (it = recv_data.send_status_list.begin();
5061 it != recv_data.send_status_list.end();
5064 formatter % i % it->status % it->send_end_size
5065 % it->send_rest_size % it->send_possible_size
5066 % it->send_offset % it->unsend_size % it->edit_division;
5067 datadump += formatter.str();
5070 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5071 "handle_realserver_recv() : send status list dump : send status list size = %d.%s");
5073 formatter % recv_data.send_status_list.size() % datadump;
5074 putLogDebug(100170, formatter.str(), __FILE__, __LINE__ );
5076 /*------DEBUG LOG END------*/
5077 //there are still rest data need to process
5078 //new status created and add to status list
5079 while (request_data_remain_size > 0)
5081 //new status created
5082 send_status new_send_state;
5083 new_send_state.edit_division = EDIT_DIVISION_NO_EDIT;
5084 new_send_state.send_end_size = 0;
5085 new_send_state.send_offset = 0;
5086 new_send_state.send_possible_size = 0;
5087 new_send_state.unsend_size = 0;
5088 new_send_state.send_rest_size = 0;
5089 //status initialize to SEND_NG
5090 new_send_state.status = SEND_NG;
5091 //add new status to status_list
5092 recv_data.send_status_list.push_back(new_send_state);
5093 std::list<send_status>::reverse_iterator new_send_it = recv_data.send_status_list.rbegin();
5095 new_send_it->send_offset = recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size
5096 - request_data_remain_size;
5099 check_result = check_status_code(recv_data.recive_buffer + new_send_it->send_offset,
5100 request_data_remain_size);
5101 /*-------- DEBUG LOG --------*/
5102 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5104 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5105 "handle_realserver_recv() : call check_http_method : "
5106 "return_value = %d. thread id : %d.");
5107 formatter % check_result % boost::this_thread::get_id();
5108 putLogDebug(100171, formatter.str(), __FILE__, __LINE__ );
5110 /*------DEBUG LOG END------*/
5111 //check http method result is OK
5112 if (check_result == CHECK_OK)
5114 //check http version
5115 check_result = check_http_version(recv_data.recive_buffer + new_send_it->send_offset,
5116 request_data_remain_size);
5117 /*-------- DEBUG LOG --------*/
5118 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5120 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5121 "handle_realserver_recv() : call check_http_version : "
5122 "return_value = %d. thread id : %d.");
5123 formatter % check_result % boost::this_thread::get_id();
5124 putLogDebug(100172, formatter.str(), __FILE__, __LINE__ );
5126 /*------DEBUG LOG END------*/
5128 //check http method and version result is OK
5129 if (check_result == CHECK_OK)
5131 //search whole http header, get whole http header's offset and length
5132 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset, request_data_remain_size,
5133 http_header, header_offset, header_offset_len);
5134 /*-------- DEBUG LOG --------*/
5135 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5137 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5138 "handle_realserver_recv() : call find_http_header : "
5139 "return_value = %d. thread id : %d.");
5140 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
5141 putLogDebug(100173, formatter.str(), __FILE__, __LINE__ );
5143 /*------DEBUG LOG END------*/
5144 //searched whole http header
5147 //search ContentLength http header, get ContentLength header's offset and length
5148 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset,
5149 request_data_remain_size, content_header, content_length_header_offset, content_length_header_len);
5150 /*-------- DEBUG LOG --------*/
5151 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5153 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5154 "handle_realserver_recv() : call find_http_header : "
5155 "return_value = %d. thread id : %d.");
5156 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
5157 putLogDebug(100174, formatter.str(), __FILE__, __LINE__ );
5159 /*------DEBUG LOG END------*/
5161 //searched ContentLength http header
5164 //Get Content_Length header's numeric value
5165 for (pos = 0; recv_data.recive_buffer[new_send_it->send_offset + content_length_header_offset + pos] != ':'
5166 && pos < content_length_header_len; ++pos)
5168 if (pos == content_length_header_len)
5170 throw std::string("Content_Length field's value is invalid.");
5175 str_value.assign(recv_data.recive_buffer + new_send_it->send_offset + content_length_header_offset + pos,
5176 content_length_header_len - pos);
5178 size_t pos_end = str_value.find_last_of('\r');
5179 if (pos_end != std::string::npos)
5181 str_value = str_value.erase(pos_end);
5184 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos)
5187 str_value = str_value.substr(pos);
5190 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
5192 catch (const boost::bad_lexical_cast& ex)
5194 throw std::string("Content_Length field's value is invalid.");
5196 //send_rest_size recalc
5197 //set whole http header's + whole http header's length + Content_Length's value
5198 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_cr_lf_len + content_len_value;
5200 //not searched ContentLength http header
5203 //send_rest_size recalc
5204 //set whole http header's + whole http header's length
5205 if (header_offset_len == 0)
5207 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
5211 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_cr_lf_len;
5216 //not searched whole http header
5219 new_send_it->unsend_size = request_data_remain_size;
5220 request_data_remain_size = 0;
5224 //check http method or version result is NG
5225 else if (check_result == CHECK_NG)
5227 new_send_it->send_rest_size = request_data_remain_size;
5229 //check http method or version result is impossible
5232 new_send_it->unsend_size = request_data_remain_size;
5233 request_data_remain_size = 0;
5237 //recalc fields value according to send_rest_size and request rest size
5238 if (new_send_it->send_rest_size > request_data_remain_size)
5240 new_send_it->send_possible_size = request_data_remain_size;
5241 new_send_it->send_rest_size -= request_data_remain_size;
5242 new_send_it->send_end_size = 0;
5243 new_send_it->send_end_size = 0;
5244 request_data_remain_size = 0;
5248 new_send_it->send_possible_size = new_send_it->send_rest_size;
5249 request_data_remain_size -= new_send_it->send_rest_size;
5250 new_send_it->send_end_size = 0;
5251 new_send_it->send_rest_size = 0;
5254 //change status from SEND_NG to SEND_OK
5255 new_send_it->status = SEND_OK;
5257 /*-------- DEBUG LOG --------*/
5258 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5260 std::string datadump;
5261 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
5262 "send_rest_size = %d, send_possible_size = %d, "
5263 "send_offset = %d, unsend_size = %d, edit_division = %d.");
5265 for (it = recv_data.send_status_list.begin();
5266 it != recv_data.send_status_list.end();
5269 formatter % i % it->status % it->send_end_size
5270 % it->send_rest_size % it->send_possible_size
5271 % it->send_offset % it->unsend_size % it->edit_division;
5272 datadump += formatter.str();
5275 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5276 "handle_realserver_recv() : send status list dump : send status list size = %d.%s");
5278 formatter % recv_data.send_status_list.size() % datadump;
5279 putLogDebug(100175, formatter.str(), __FILE__, __LINE__ );
5281 /*------DEBUG LOG END------*/
5283 //search for send_possible item in status list
5284 send_status_it it_find = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
5285 data_send_possible());
5286 //the data that can be sent possible is exist
5287 if (it_find != recv_data.send_status_list.end())
5289 status = CLIENT_CONNECTION_CHECK;
5291 //the data that can be sent possible is not exist
5294 status = REALSERVER_RECV;
5299 /*-------- DEBUG LOG --------*/
5300 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5302 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5303 "handle_realserver_recv() : catch exception e = %d. thread id : %d.");
5304 formatter % e % boost::this_thread::get_id();
5305 putLogDebug(100176, formatter.str(), __FILE__, __LINE__ );
5307 /*------DEBUG LOG END------*/
5310 catch (const std::string& ex)
5312 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : exception : " << ex << std::endl;
5313 boost::format formatter("protocol_module_sessionless::handle_realserver_recv() : exception : %s. thread id : %d.");
5314 formatter % ex.c_str() % boost::this_thread::get_id();
5315 putLogError(100086, formatter.str(), __FILE__, __LINE__ );
5318 catch (const std::bad_alloc&)
5320 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : exception : Could not allocate memory." << std::endl;
5321 boost::format formatter("Could not allocate memory. thread id : %d.");
5322 formatter % boost::this_thread::get_id();
5323 putLogError(100087, formatter.str(), __FILE__, __LINE__ );
5326 catch (const std::exception& ex)
5328 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : exception : error = " << ex.what() << "." << std::endl;
5329 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5330 "handle_realserver_recv() : exception : error = %s. thread id : %d.");
5331 formatter % ex.what() % boost::this_thread::get_id();
5332 putLogError(100088, formatter.str(), __FILE__, __LINE__ );
5338 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : Unknown exception." << std::endl;
5339 boost::format formatter("function : protocol_module_base::EVENT_TAG "
5340 "protocol_module_sessionless::handle_realserver_recv() : "
5341 "Unknown exception. thread id : %d.");
5342 formatter % boost::this_thread::get_id();
5343 putLogError(100089, formatter.str(), __FILE__, __LINE__ );
5347 /*-------- DEBUG LOG --------*/
5348 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5350 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5351 "handle_realserver_recv(const boost::thread::id thread_id, "
5352 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
5353 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5354 "const size_t recvlen) : return_value = %d. thread id : %d.");
5355 formatter % status % boost::this_thread::get_id();
5356 putLogDebug(100177, formatter.str(), __FILE__, __LINE__ );
5358 /*------DEBUG LOG END------*/
5365 //! called from after sorryserver recive
5366 //! @param[in] downstream thread id
5367 //! @param[in] sorryserver endpoint reference
5368 //! @param[in] recive from realserver buffer reference.
5369 //! @param[in] recv data length
5370 //! @return session use EVENT mode
5371 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_recv(
5372 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint& sorry_endpoint, const boost::array<
5373 char, MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
5375 /*-------- DEBUG LOG --------*/
5376 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5378 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
5380 dump_memory(recvbuffer.data(), buffer_size, buffer);
5381 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5382 "handle_sorryserver_recv(const boost::thread::id thread_id, "
5383 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
5384 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5385 "const size_t recvlen) : thread_id = %d, sorry_endpoint = [%s]:%d, recvbuffer = %s, recvlen = %d.");
5386 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port()
5388 putLogDebug(100178, formatter.str(), __FILE__, __LINE__ );
5390 /*------DEBUG LOG END------*/
5392 EVENT_TAG status = FINALIZE;
5393 size_t data_remain_start = 0;
5394 size_t data_remain_size = 0;
5395 size_t request_data_remain_size = 0;
5396 size_t header_offset = 0;
5397 size_t header_offset_len = 0;
5398 size_t content_length_header_offset = 0;
5399 size_t content_length_header_len = 0;
5400 size_t content_len_value = 0;
5402 size_t buffer_size = 0;
5403 const size_t cr_lf_cr_lf_len = strlen("\r\n\r\n");
5404 const size_t cr_lf_len = strlen("\r\n");
5405 std::string str_value;
5406 const std::string http_header = "";
5407 const std::string content_header = "Content-Length";
5408 thread_data_ptr session_data;
5409 char* buffer1 = NULL;
5410 char* buffer2 = NULL;
5412 CHECK_RESULT_TAG check_result;
5413 session_thread_data_map_it session_thread_it;
5414 recive_data_map_it recive_data_it;
5417 if (recvlen > recvbuffer.size())
5419 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : Data size bigger than buffer size." << std::endl;
5420 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
5421 formatter % boost::this_thread::get_id();
5422 putLogError(100090, formatter.str(), __FILE__,
5424 /*-------- DEBUG LOG --------*/
5425 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5427 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5428 "handle_sorryserver_recv(const boost::thread::id thread_id, "
5429 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
5430 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5431 "const size_t recvlen) : return_value = %d. thread id : %d.");
5432 formatter % FINALIZE % boost::this_thread::get_id();
5433 putLogDebug(100179, formatter.str(), __FILE__, __LINE__ );
5435 /*------DEBUG LOG END------*/
5442 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
5444 session_thread_it = session_thread_data_map.find(thread_id);
5445 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
5447 boost::format formatter("Invalid thread id. thread id : %d.");
5448 formatter % boost::this_thread::get_id();
5449 putLogError(100091, formatter.str(), __FILE__, __LINE__ );
5453 session_data = session_thread_it->second;
5456 recive_data_it = session_data->recive_data_map.find(sorry_endpoint);
5457 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
5459 recive_data recv_data;
5460 session_data->recive_data_map[sorry_endpoint] = recv_data;
5463 session_data->target_endpoint = sorry_endpoint;
5465 recive_data& recv_data = session_data->recive_data_map[sorry_endpoint];
5468 send_status_it it = recv_data.send_status_list.begin();
5469 send_status_it it_end = recv_data.send_status_list.end();
5470 it = std::find_if(it, it_end, data_send_ok());
5471 if (unlikely(it != it_end))
5473 boost::format formatter("Sending data is invalid. thread id : %d.");
5474 formatter % boost::this_thread::get_id();
5475 putLogError(100092, formatter.str(), __FILE__, __LINE__ );
5480 it = recv_data.send_status_list.begin();
5481 it = std::adjacent_find(it, it_end, data_send_repeated());
5482 if (unlikely(it != it_end))
5484 boost::format formatter("Sending data is invalid. thread id : %d.");
5485 formatter % boost::this_thread::get_id();
5486 putLogError(100093, formatter.str(), __FILE__, __LINE__ );
5490 /*-------- DEBUG LOG --------*/
5491 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5493 std::string datadump;
5494 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
5495 "send_rest_size = %d, send_possible_size = %d, "
5496 "send_offset = %d, unsend_size = %d, edit_division = %d.");
5498 for (it = recv_data.send_status_list.begin();
5499 it != recv_data.send_status_list.end();
5502 formatter % i % it->status % it->send_end_size
5503 % it->send_rest_size % it->send_possible_size
5504 % it->send_offset % it->unsend_size % it->edit_division;
5505 datadump += formatter.str();
5508 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5509 "handle_sorryserver_recv() : send status list dump : send status list size = %d.%s");
5511 formatter % recv_data.send_status_list.size() % datadump;
5512 putLogDebug(100180, formatter.str(), __FILE__, __LINE__ );
5514 /*------DEBUG LOG END------*/
5516 it = recv_data.send_status_list.begin();
5517 //get original status info
5518 while (it != it_end)
5520 //item status is SEND_END
5521 if (it->status == SEND_END)
5524 recv_data.send_status_list.erase(it++);
5527 //item status is SEND_CONTINUE
5528 else if (it->status == SEND_CONTINUE)
5530 it->send_offset += it->send_end_size;
5531 data_remain_start = it->send_offset;
5534 //item status is SEND_NG
5537 data_remain_start = it->send_offset;
5538 data_remain_size = it->unsend_size;
5544 /*-------- DEBUG LOG --------*/
5545 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5547 std::string datadump;
5548 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
5549 "send_rest_size = %d, send_possible_size = %d, "
5550 "send_offset = %d, unsend_size = %d, edit_division = %d.");
5552 for (it = recv_data.send_status_list.begin();
5553 it != recv_data.send_status_list.end();
5556 formatter % i % it->status % it->send_end_size
5557 % it->send_rest_size % it->send_possible_size
5558 % it->send_offset % it->unsend_size % it->edit_division;
5559 datadump += formatter.str();
5562 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5563 "handle_sorryserver_recv() : send status list dump : send status list size = %d.%s");
5565 formatter % recv_data.send_status_list.size() % datadump;
5566 putLogDebug(100181, formatter.str(), __FILE__, __LINE__ );
5568 /*------DEBUG LOG END------*/
5569 //recive buffer process
5570 //buffer rest size < request size
5571 if (recv_data.recive_buffer_rest_size < recvlen)
5573 //buffer max size < remain size + request size
5574 //buffer is need reallocate
5575 if (recv_data.recive_buffer_max_size < data_remain_size + recvlen)
5577 //the buffer's size that will be allocated is exceed the upper limit value
5578 if (MAX_SESSIONLESS_MODULE_BUFFER_SIZE < data_remain_size + recvlen)
5580 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : the buffer's size that will be allacted is exceed the upper limit value." << std::endl;
5581 boost::format formatter("The buffer's size that will be allocated is exceed the upper limit value. thread id : %d.");
5582 formatter % boost::this_thread::get_id();
5583 putLogError(100094, formatter.str(), __FILE__, __LINE__ );
5584 /*-------- DEBUG LOG --------*/
5585 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5587 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5588 "handle_sorryserver_recv(const boost::thread::id thread_id, "
5589 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
5590 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5591 "const size_t recvlen) : return_value = %d. thread id : %d.");
5592 formatter % FINALIZE % boost::this_thread::get_id();
5593 putLogDebug(100182, formatter.str(), __FILE__, __LINE__ );
5595 /*------DEBUG LOG END------*/
5598 //recive_buffer1's memory allocate and initialization
5599 buffer_size = (data_remain_size + recvlen) > MAX_BUFFER_SIZE ? (data_remain_size + recvlen) : MAX_BUFFER_SIZE;
5600 buffer1 = new char[buffer_size];
5601 /*-------- DEBUG LOG --------*/
5602 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5604 boost::format formatter("new : address = &(%d), size = %lu.");
5605 formatter % static_cast<void*>(buffer1) % buffer_size;
5606 putLogDebug(100183, formatter.str(), __FILE__, __LINE__ );
5608 /*-------- DEBUG LOG END--------*/
5609 memset(buffer1, 0, buffer_size);
5610 //recive_buffer2's memory allocate and initialization
5611 buffer2 = new char[buffer_size];
5612 /*-------- DEBUG LOG --------*/
5613 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5615 boost::format formatter("new : address = &(%d), size = %lu.");
5616 formatter % static_cast<void*>(buffer2) % buffer_size;
5617 putLogDebug(100184, formatter.str(), __FILE__, __LINE__ );
5619 /*-------- DEBUG LOG END--------*/
5620 memset(buffer2, 0, buffer_size);
5622 /*-------- DEBUG LOG --------*/
5623 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5625 std::string datadump;
5626 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
5627 boost::format formatter(
5628 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5629 "handle_sorryserver_recv() : before memcpy (data dump) : "
5630 "data begin = %d, data_size = %d, data = %s");
5631 formatter % data_remain_start % data_remain_size % datadump;
5632 putLogDebug(100185, formatter.str(), __FILE__, __LINE__ );
5634 /*------DEBUG LOG END------*/
5635 //copy data from old buffer to new buffer
5636 memcpy(buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
5637 /*-------- DEBUG LOG --------*/
5638 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5640 std::string datadump;
5641 dump_memory(buffer1, data_remain_size, datadump);
5642 boost::format formatter(
5643 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5644 "handle_sorryserver_recv() : after memcpy (data dump) : "
5645 "data begin = 0, data_size = %d, data = %s");
5646 formatter % data_remain_size % datadump;
5647 putLogDebug(100186, formatter.str(), __FILE__, __LINE__ );
5649 /*------DEBUG LOG END------*/
5651 /*-------- DEBUG LOG --------*/
5652 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5654 std::string datadump;
5655 dump_memory(recvbuffer.data(), recvlen, datadump);
5656 boost::format formatter(
5657 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5658 "handle_sorryserver_recv() : before memcpy (data dump) : "
5659 "data begin = 0, data_size = %d, data = %s");
5660 formatter % recvlen % datadump;
5661 putLogDebug(100187, formatter.str(), __FILE__, __LINE__ );
5663 /*------DEBUG LOG END------*/
5664 memcpy(buffer1 + data_remain_size, recvbuffer.data(), recvlen);
5665 /*-------- DEBUG LOG --------*/
5666 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5668 std::string datadump;
5669 dump_memory(buffer1 + data_remain_size, recvlen, datadump);
5670 boost::format formatter(
5671 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5672 "handle_sorryserver_recv() : after memcpy (data dump) : "
5673 "data begin = %d, data_size = %d, data = %s");
5674 formatter % data_remain_size % recvlen % datadump;
5675 putLogDebug(100188, formatter.str(), __FILE__, __LINE__ );
5677 /*------DEBUG LOG END------*/
5678 //free old buffer1 and old buffer2
5679 if (recv_data.recive_buffer1 != NULL)
5681 /*-------- DEBUG LOG --------*/
5682 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5684 boost::format formatter("delete : address = &(%d).");
5685 formatter % static_cast<void*>(recv_data.recive_buffer1);
5686 putLogDebug(100189, formatter.str(), __FILE__,
5689 /*------DEBUG LOG END------*/
5690 delete[] recv_data.recive_buffer1;
5691 recv_data.recive_buffer1 = NULL;
5694 if (recv_data.recive_buffer2 != NULL)
5696 /*-------- DEBUG LOG --------*/
5697 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5699 boost::format formatter("delete : address = &(%d).");
5700 formatter % static_cast<void*>(recv_data.recive_buffer2);
5701 putLogDebug(100190, formatter.str(), __FILE__,
5704 /*------DEBUG LOG END------*/
5705 delete[] recv_data.recive_buffer2;
5706 recv_data.recive_buffer2 = NULL;
5709 //set new buffer pointer
5710 recv_data.recive_buffer1 = buffer1;
5711 recv_data.recive_buffer2 = buffer2;
5712 recv_data.recive_buffer = recv_data.recive_buffer1;
5713 //set new buffer's max size
5714 recv_data.recive_buffer_max_size = buffer_size;
5716 //buffer's max size >= remain data size + requst size
5717 //buffer isn't need reallocate, but switch
5720 //pointer valid check
5721 if (unlikely(recv_data.recive_buffer1 == NULL || recv_data.recive_buffer2 == NULL))
5723 boost::format formatter("Invalid pointer. thread id : %d.");
5724 formatter % boost::this_thread::get_id();
5725 putLogError(100095, formatter.str(), __FILE__, __LINE__ );
5728 //using buffer is buffer1
5729 if (recv_data.recive_buffer == recv_data.recive_buffer1)
5731 //buffer2 initialization
5732 memset(recv_data.recive_buffer2, 0, recv_data.recive_buffer_max_size);
5733 /*-------- DEBUG LOG --------*/
5734 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5736 std::string datadump;
5737 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
5738 boost::format formatter(
5739 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5740 "handle_sorryserver_recv() : before memcpy (data dump) : "
5741 "data begin = %d, data_size = %d, data = %s");
5742 formatter % data_remain_start % data_remain_size % datadump;
5743 putLogDebug(100191, formatter.str(), __FILE__, __LINE__ );
5745 /*------DEBUG LOG END------*/
5746 //copy data from buffer1 to buffer2
5747 memcpy(recv_data.recive_buffer2, recv_data.recive_buffer + data_remain_start, data_remain_size);
5748 /*-------- DEBUG LOG --------*/
5749 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5751 std::string datadump;
5752 dump_memory(recv_data.recive_buffer2, data_remain_size, datadump);
5753 boost::format formatter(
5754 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5755 "handle_sorryserver_recv() : after memcpy (data dump) : "
5756 "data begin = 0, data_size = %d, data = %s");
5757 formatter % data_remain_size % datadump;
5758 putLogDebug(100192, formatter.str(), __FILE__, __LINE__ );
5760 /*------DEBUG LOG END------*/
5761 /*-------- DEBUG LOG --------*/
5762 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5764 std::string datadump;
5765 dump_memory(recvbuffer.data(), recvlen, datadump);
5766 boost::format formatter(
5767 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5768 "handle_sorryserver_recv() : before memcpy (data dump) : "
5769 "data begin = 0, data_size = %d, data = %s");
5770 formatter % recvlen % datadump;
5771 putLogDebug(100193, formatter.str(), __FILE__, __LINE__ );
5773 /*------DEBUG LOG END------*/
5774 memcpy(recv_data.recive_buffer2 + data_remain_size, recvbuffer.data(), recvlen);
5775 /*-------- DEBUG LOG --------*/
5776 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5778 std::string datadump;
5779 dump_memory(recv_data.recive_buffer2 + data_remain_size, recvlen, datadump);
5780 boost::format formatter(
5781 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5782 "handle_sorryserver_recv() : after memcpy (data dump) : "
5783 "data begin = %d, data_size = %d, data = %s");
5784 formatter % data_remain_size % recvlen % datadump;
5785 putLogDebug(100194, formatter.str(), __FILE__, __LINE__ );
5787 /*------DEBUG LOG END------*/
5788 //set buffer2 as using buffer
5789 recv_data.recive_buffer = recv_data.recive_buffer2;
5791 //using buffer is buffer2
5794 //buffer1 initializtion
5795 memset(recv_data.recive_buffer1, 0, recv_data.recive_buffer_max_size);
5796 /*-------- DEBUG LOG --------*/
5797 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5799 std::string datadump;
5800 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
5801 boost::format formatter(
5802 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5803 "handle_sorryserver_recv() : before memcpy (data dump) : "
5804 "data begin = %d, data_size = %d, data = %s");
5805 formatter % data_remain_start % data_remain_size % datadump;
5806 putLogDebug(100195, formatter.str(), __FILE__, __LINE__ );
5808 /*------DEBUG LOG END------*/
5809 //copy data from buffer2 to buffer1
5810 memcpy(recv_data.recive_buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
5811 /*-------- DEBUG LOG --------*/
5812 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5814 std::string datadump;
5815 dump_memory(recv_data.recive_buffer1, data_remain_size, datadump);
5816 boost::format formatter(
5817 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5818 "handle_sorryserver_recv() : after memcpy (data dump) : "
5819 "data begin = 0, data_size = %d, data = %s");
5820 formatter % data_remain_size % datadump;
5821 putLogDebug(100196, formatter.str(), __FILE__, __LINE__ );
5823 /*------DEBUG LOG END------*/
5825 /*-------- DEBUG LOG --------*/
5826 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5828 std::string datadump;
5829 dump_memory(recvbuffer.data(), recvlen, datadump);
5830 boost::format formatter(
5831 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5832 "handle_sorryserver_recv() : before memcpy (data dump) : "
5833 "data begin = 0, data_size = %d, data = %s");
5834 formatter % recvlen % datadump;
5835 putLogDebug(100197, formatter.str(), __FILE__, __LINE__ );
5837 /*------DEBUG LOG END------*/
5838 memcpy(recv_data.recive_buffer1 + data_remain_size, recvbuffer.data(), recvlen);
5839 /*-------- DEBUG LOG --------*/
5840 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5842 std::string datadump;
5843 dump_memory(recv_data.recive_buffer1 + data_remain_size, recvlen, datadump);
5844 boost::format formatter(
5845 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5846 "handle_sorryserver_recv() : after memcpy (data dump) : "
5847 "data begin = %d, data_size = %d, data = %s");
5848 formatter % data_remain_size % recvlen % datadump;
5849 putLogDebug(100198, formatter.str(), __FILE__, __LINE__ );
5851 /*------DEBUG LOG END------*/
5852 //set buffer1 as using buffer
5853 recv_data.recive_buffer = recv_data.recive_buffer1;
5857 //set buffer's rest size
5858 recv_data.recive_buffer_rest_size = recv_data.recive_buffer_max_size - data_remain_size - recvlen;
5860 //remain_size recalc
5861 data_remain_size += recvlen;
5863 send_status_it it_begin = recv_data.send_status_list.begin();
5864 send_status_it it_end = recv_data.send_status_list.end();
5866 for (; it_begin != it_end; ++it_begin)
5868 it_begin->send_offset -= data_remain_start;
5871 //buffer's rest size >= request size
5875 //pointer valid check
5876 if (unlikely(recv_data.recive_buffer == NULL))
5878 boost::format formatter("Invalid pointer. thread id : %d");
5879 formatter % boost::this_thread::get_id();
5880 putLogError(100096, formatter.str(), __FILE__, __LINE__ );
5883 /*-------- DEBUG LOG --------*/
5884 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5886 std::string datadump;
5887 dump_memory(recvbuffer.data(), recvlen, datadump);
5888 boost::format formatter(
5889 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5890 "handle_sorryserver_recv() : before memcpy (data dump) : "
5891 "data begin = 0, data_size = %d, data = %s");
5892 formatter % recvlen % datadump;
5893 putLogDebug(100199, formatter.str(), __FILE__, __LINE__ );
5895 /*------DEBUG LOG END------*/
5897 //copy data from parameter to using buffer
5898 memcpy(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
5899 recvbuffer.data(), recvlen);
5900 /*-------- DEBUG LOG --------*/
5901 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5903 std::string datadump;
5904 dump_memory(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size, recvlen, datadump);
5905 boost::format formatter(
5906 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5907 "handle_sorryserver_recv() : after memcpy (data dump) : "
5908 "data begin = %d, data_size = %d, data = %s");
5909 formatter % (recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size) % recvlen % datadump;
5910 putLogDebug(100200, formatter.str(), __FILE__, __LINE__ );
5912 /*------DEBUG LOG END------*/
5913 //buffer's rest size recalc
5914 recv_data.recive_buffer_rest_size -= recvlen;
5915 //remain data size recalc
5916 data_remain_size += recvlen;
5919 it = recv_data.send_status_list.begin();
5920 it_end = recv_data.send_status_list.end();
5921 //request rest size initialization
5922 request_data_remain_size = recvlen;
5923 //original status process
5924 for (; it != it_end; ++it)
5926 //status is SEND_CONTINUE
5927 if (it->status == SEND_CONTINUE)
5930 if (it->send_rest_size > request_data_remain_size)
5932 it->send_possible_size = request_data_remain_size;
5933 it->send_rest_size -= request_data_remain_size;
5934 it->send_end_size = 0;
5935 request_data_remain_size = 0;
5939 it->send_possible_size = it->send_rest_size;
5940 request_data_remain_size -= it->send_rest_size;
5941 it->send_end_size = 0;
5942 it->send_rest_size = 0;
5945 //change status from SEND_CONTINUE to SEND_OK
5946 it->status = SEND_OK;
5949 else if (it->status == SEND_NG)
5952 check_result = check_status_code(recv_data.recive_buffer + it->send_offset, data_remain_size);
5953 /*-------- DEBUG LOG --------*/
5954 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5956 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5957 "handle_sorryserver_recv() : call check_status_code : "
5958 "return_value = %d. thread id : %d.");
5959 formatter % check_result % boost::this_thread::get_id();
5960 putLogDebug(100201, formatter.str(), __FILE__, __LINE__ );
5962 /*------DEBUG LOG END------*/
5963 //check http method result is OK
5964 if (check_result == CHECK_OK)
5966 //check http version
5967 check_result = check_http_version(recv_data.recive_buffer + it->send_offset, data_remain_size);
5968 /*-------- DEBUG LOG --------*/
5969 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5971 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5972 "handle_sorryserver_recv() : call check_http_version : "
5973 "return_value = %d. thread id : %d.");
5974 formatter % check_result % boost::this_thread::get_id();
5975 putLogDebug(100202, formatter.str(), __FILE__, __LINE__ );
5977 /*------DEBUG LOG END------*/
5979 //check method and version result is OK
5980 if (check_result == CHECK_OK)
5982 //search http header
5983 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size, http_header,
5984 header_offset, header_offset_len);
5985 /*-------- DEBUG LOG --------*/
5986 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5988 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5989 "handle_sorryserver_recv() : call find_http_header : "
5990 "return_value = %d. thread id : %d.");
5991 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
5992 putLogDebug(100203, formatter.str(), __FILE__, __LINE__ );
5994 /*------DEBUG LOG END------*/
5995 //search http header result is OK
5998 //search Content_Length header
5999 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size,
6000 content_header, content_length_header_offset, content_length_header_len);
6001 /*-------- DEBUG LOG --------*/
6002 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6004 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6005 "handle_sorryserver_recv() : call find_http_header : "
6006 "return_value = %d. thread id : %d.");
6007 formatter % static_cast<int>(bret) %boost::this_thread::get_id();
6008 putLogDebug(100204, formatter.str(), __FILE__, __LINE__ );
6010 /*------DEBUG LOG END------*/
6011 //search Content_Length result is OK
6014 //Get Content_Length header's numeric value
6015 for (pos = 0; recv_data.recive_buffer[it->send_offset + content_length_header_offset + pos] != ':' && pos
6016 < content_length_header_len; ++pos)
6018 if (pos == content_length_header_len)
6020 throw std::string("Content_Length field's value is invalid.");
6025 str_value.assign(recv_data.recive_buffer + it->send_offset + content_length_header_offset + pos,
6026 content_length_header_len - pos);
6028 size_t pos_end = str_value.find_last_of('\r');
6029 if (pos_end != std::string::npos)
6031 str_value = str_value.erase(pos_end);
6034 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos)
6037 str_value = str_value.substr(pos);
6041 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
6043 catch (const boost::bad_lexical_cast& ex)
6045 throw std::string("Content_Length field's value is invalid.");
6047 //send_rest_size recalc
6048 //set whole http header's length + Content_Length's value
6049 it->send_rest_size = header_offset + header_offset_len + cr_lf_cr_lf_len + content_len_value;
6051 //search Content_Length result is NG
6054 //send_rest_size recalc
6055 //set whole http header's length
6056 if (header_offset_len == 0)
6058 it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
6062 it->send_rest_size = header_offset + header_offset_len + cr_lf_cr_lf_len;
6066 //search http header result is NG
6069 it->unsend_size += request_data_remain_size;
6070 request_data_remain_size = 0;
6074 //check method or version result is NG
6075 else if (check_result == CHECK_NG)
6077 it->send_rest_size = it->unsend_size+request_data_remain_size;
6079 //check method and version result is CHECK_INPOSSIBLE
6082 it->unsend_size += request_data_remain_size;
6083 request_data_remain_size = 0;
6087 //recalc fields value according to send_rest_size and request rest size
6088 if (it->send_rest_size > it->unsend_size + request_data_remain_size)
6090 it->send_possible_size = it->unsend_size + request_data_remain_size;
6091 it->send_rest_size -= (it->unsend_size + request_data_remain_size);
6092 it->send_end_size = 0;
6093 it->unsend_size = 0;
6094 request_data_remain_size = 0;
6098 it->send_possible_size = it->send_rest_size;
6099 request_data_remain_size = it->unsend_size + request_data_remain_size - it->send_rest_size;
6100 it->send_end_size = 0;
6101 it->unsend_size = 0;
6102 it->send_rest_size = 0;
6105 //change status from SEND_NG to SEND_OK
6106 it->status = SEND_OK;
6108 //no request rest data to process
6109 if (request_data_remain_size <= 0)
6114 /*-------- DEBUG LOG --------*/
6115 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6117 std::string datadump;
6118 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
6119 "send_rest_size = %d, send_possible_size = %d, "
6120 "send_offset = %d, unsend_size = %d, edit_division = %d.");
6122 for (it = recv_data.send_status_list.begin();
6123 it != recv_data.send_status_list.end();
6126 formatter % i % it->status % it->send_end_size
6127 % it->send_rest_size % it->send_possible_size
6128 % it->send_offset % it->unsend_size % it->edit_division;
6129 datadump += formatter.str();
6132 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6133 "handle_sorryserver_recv() : send status list dump : send status list size = %d.%s");
6135 formatter % recv_data.send_status_list.size() % datadump;
6136 putLogDebug(100205, formatter.str(), __FILE__, __LINE__ );
6138 /*------DEBUG LOG END------*/
6140 //there are still rest data need to process
6141 //new status created and add to status list
6142 while (request_data_remain_size > 0)
6144 //new status created
6145 send_status new_send_state;
6146 new_send_state.edit_division = EDIT_DIVISION_NO_EDIT;
6147 new_send_state.send_end_size = 0;
6148 new_send_state.send_offset = 0;
6149 new_send_state.send_possible_size = 0;
6150 new_send_state.unsend_size = 0;
6151 new_send_state.send_rest_size = 0;
6152 //status initialize to SEND_NG
6153 new_send_state.status = SEND_NG;
6154 //add new status to status_list
6155 recv_data.send_status_list.push_back(new_send_state);
6156 std::list<send_status>::reverse_iterator new_send_it = recv_data.send_status_list.rbegin();
6158 new_send_it->send_offset = recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size
6159 - request_data_remain_size;
6162 check_result = check_status_code(recv_data.recive_buffer + new_send_it->send_offset,
6163 request_data_remain_size);
6164 /*-------- DEBUG LOG --------*/
6165 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6167 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6168 "handle_sorryserver_recv() : call check_status_code : "
6169 "return_value = %d. thread id : %d.");
6170 formatter % check_result % boost::this_thread::get_id();
6171 putLogDebug(100206, formatter.str(), __FILE__, __LINE__ );
6173 /*------DEBUG LOG END------*/
6174 //check http method result is OK
6175 if (check_result == CHECK_OK)
6177 //check http version
6178 check_result = check_http_version(recv_data.recive_buffer + new_send_it->send_offset,
6179 request_data_remain_size);
6180 /*-------- DEBUG LOG --------*/
6181 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6183 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6184 "handle_sorryserver_recv() : call check_http_version : "
6185 "return_value = %d. thread id : %d.");
6186 formatter % check_result % boost::this_thread::get_id();
6187 putLogDebug(100207, formatter.str(), __FILE__, __LINE__ );
6189 /*------DEBUG LOG END------*/
6191 //check http method and version result is OK
6192 if (check_result == CHECK_OK)
6194 //search whole http header, get whole http header's offset and length
6195 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset, request_data_remain_size,
6196 http_header, header_offset, header_offset_len);
6197 /*-------- DEBUG LOG --------*/
6198 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6200 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6201 "handle_sorryserver_recv() : call find_http_header : "
6202 "return_value = %d. thread id : %d.");
6203 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
6204 putLogDebug(100208, formatter.str(), __FILE__, __LINE__ );
6206 /*------DEBUG LOG END------*/
6207 //searched whole http header
6210 //search ContentLength http header, get ContentLength header's offset and length
6211 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset,
6212 request_data_remain_size, content_header, content_length_header_offset, content_length_header_len);
6213 /*-------- DEBUG LOG --------*/
6214 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6216 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6217 "handle_sorryserver_recv() : call find_http_header : "
6218 "return_value = %d. thread id : %d.");
6219 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
6220 putLogDebug(100209, formatter.str(), __FILE__, __LINE__ );
6222 /*------DEBUG LOG END------*/
6224 //searched ContentLength http header
6227 //Get Content_Length header's numeric value
6228 for (pos = 0; recv_data.recive_buffer[new_send_it->send_offset + content_length_header_offset + pos] != ':'
6229 && pos < content_length_header_len; ++pos)
6231 if (pos == content_length_header_len)
6233 throw std::string("Content_Length field's value is invalid.");
6237 str_value.assign(recv_data.recive_buffer + new_send_it->send_offset + content_length_header_offset + pos,
6238 content_length_header_len - pos);
6240 size_t pos_end = str_value.find_last_of('\r');
6241 if (pos_end != std::string::npos)
6243 str_value = str_value.erase(pos_end);
6246 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos)
6249 str_value = str_value.substr(pos);
6252 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
6254 catch (const boost::bad_lexical_cast& ex)
6256 throw std::string("Content_Length field's value is invalid.");
6258 //send_rest_size recalc
6259 //set whole http header's + whole http header's length + Content_Length's value
6260 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_cr_lf_len + content_len_value;
6262 //not searched ContentLength http header
6265 //send_rest_size recalc
6266 //set whole http header's + whole http header's length
6267 if (header_offset_len == 0)
6269 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
6273 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_cr_lf_len;
6279 //not searched whole http header
6282 new_send_it->unsend_size = request_data_remain_size;
6283 request_data_remain_size = 0;
6287 //check http method or version result is NG
6288 else if (check_result == CHECK_NG)
6290 new_send_it->send_rest_size = request_data_remain_size;
6292 //check http method or version result is impossible
6295 new_send_it->unsend_size = request_data_remain_size;
6296 request_data_remain_size = 0;
6300 //recalc fields value according to send_rest_size and request rest size
6301 if (new_send_it->send_rest_size > request_data_remain_size)
6303 new_send_it->send_possible_size = request_data_remain_size;
6304 new_send_it->send_rest_size -= request_data_remain_size;
6305 new_send_it->send_end_size = 0;
6306 request_data_remain_size = 0;
6310 new_send_it->send_possible_size = new_send_it->send_rest_size;
6311 request_data_remain_size -= new_send_it->send_rest_size;
6312 new_send_it->send_end_size = 0;
6313 new_send_it->send_rest_size = 0;
6316 //change status from SEND_NG to SEND_OK
6317 new_send_it->status = SEND_OK;
6319 /*-------- DEBUG LOG --------*/
6320 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6322 std::string datadump;
6323 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
6324 "send_rest_size = %d, send_possible_size = %d, "
6325 "send_offset = %d, unsend_size = %d, edit_division = %d.");
6327 for (it = recv_data.send_status_list.begin();
6328 it != recv_data.send_status_list.end();
6331 formatter % i % it->status % it->send_end_size
6332 % it->send_rest_size % it->send_possible_size
6333 % it->send_offset % it->unsend_size % it->edit_division;
6334 datadump += formatter.str();
6337 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6338 "handle_sorryserver_recv() : send status list dump : send status list size = %d.%s");
6340 formatter % recv_data.send_status_list.size() % datadump;
6341 putLogDebug(100210, formatter.str(), __FILE__, __LINE__ );
6343 /*------DEBUG LOG END------*/
6345 //search for send_possible item in status list
6346 send_status_it it_find = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
6347 data_send_possible());
6348 //the data that can be sent possible is exist
6349 if (it_find != recv_data.send_status_list.end())
6351 status = CLIENT_CONNECTION_CHECK;
6353 //the data that can be sent possible is not exist
6356 status = SORRYSERVER_RECV;
6361 /*-------- DEBUG LOG --------*/
6362 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6364 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6365 "handle_sorryserver_recv() : catch exception e = %d. thread id : %d.");
6366 formatter % e % boost::this_thread::get_id();
6367 putLogDebug(100211, formatter.str(), __FILE__, __LINE__ );
6369 /*------DEBUG LOG END------*/
6372 catch (const std::string& ex)
6374 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : exception : " << ex << std::endl;
6375 boost::format formatter("protocol_module_sessionless::handle_sorryserver_recv() : exception : %s. thread id : %d.");
6376 formatter % ex.c_str() % boost::this_thread::get_id();
6377 putLogError(100097, formatter.str(), __FILE__, __LINE__ );
6380 catch (const std::bad_alloc&)
6382 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : exception : Could not allocate memory." << std::endl;
6383 boost::format formatter("Could not allocate memory. thread id : %d.");
6384 formatter % boost::this_thread::get_id();
6385 putLogError(100098, formatter.str(), __FILE__, __LINE__ );
6388 catch (const std::exception& ex)
6390 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : exception : error = " << ex.what() << "." << std::endl;
6391 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6392 "handle_sorryserver_recv() : exception : error = %s. thread id : %d.");
6393 formatter % ex.what() % boost::this_thread::get_id();
6394 putLogError(100099, formatter.str(), __FILE__, __LINE__ );
6400 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : Unknown exception." << std::endl;
6401 boost::format formatter("function : protocol_module_base::EVENT_TAG "
6402 "protocol_module_sessionless::handle_sorryserver_recv() : "
6403 "Unknown exception. thread id : %d.");
6404 formatter % boost::this_thread::get_id();
6405 putLogError(100100, formatter.str(), __FILE__, __LINE__ );
6409 /*-------- DEBUG LOG --------*/
6410 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6412 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6413 "handle_sorryserver_recv(const boost::thread::id thread_id, "
6414 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
6415 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
6416 "const size_t recvlen) : return_value = %d. thread id : %d.");
6417 formatter % status % boost::this_thread::get_id();
6418 putLogDebug(100212, formatter.str(), __FILE__, __LINE__ );
6420 /*------DEBUG LOG END------*/
6425 //! called from UPSTEEARM thread. make module original message.
6426 //! @param[in] downstream thread id.
6427 //! @return session use EVENT mode
6428 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_response_send_inform(
6429 const boost::thread::id thread_id)
6431 /*-------- DEBUG LOG --------*/
6432 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6434 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6435 "handle_response_send_inform(const boost::thread::id thread_id) : "
6436 "return_value = %d. thread id : %d.");
6437 formatter % STOP % boost::this_thread::get_id();
6438 putLogDebug(100213, formatter.str(), __FILE__, __LINE__ );
6440 /*------DEBUG LOG END------*/
6444 //! called from after client connection check. use TCP/IP only. create client send message.
6445 //! @param[in] downstream thread id
6446 //! @param[out] send budffer reference
6447 //! @param[out] send data length
6448 //! @return session use EVENT mode
6449 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_connection_check(
6450 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
6453 /*-------- DEBUG LOG --------*/
6454 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6456 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6457 "handle_client_connection_check(const boost::thread::id thread_id, "
6458 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
6460 formatter % thread_id;
6461 putLogDebug(100214, formatter.str(), __FILE__, __LINE__ );
6463 /*------DEBUG LOG END------*/
6465 EVENT_TAG status = FINALIZE;
6466 size_t send_buffer_size = sendbuffer.max_size();
6467 thread_data_ptr session_data;
6468 session_thread_data_map_it session_thread_it;
6469 recive_data_map_it recive_data_it;
6474 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
6476 session_thread_it = session_thread_data_map.find(thread_id);
6477 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
6479 boost::format formatter("Invalid thread id. thread id : %d.");
6480 formatter % boost::this_thread::get_id();
6481 putLogError(100101, formatter.str(), __FILE__, __LINE__ );
6485 session_data = session_thread_it->second;
6488 recive_data_it = session_data->recive_data_map.find(session_data->target_endpoint);
6489 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
6491 boost::format formatter("Invalid endpoint. thread id : %d.");
6492 formatter % boost::this_thread::get_id();
6493 putLogError(100102, formatter.str(), __FILE__, __LINE__ );
6497 recive_data& recv_data = recive_data_it->second;
6499 //get the data that can be sent possible
6500 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
6501 data_send_possible());
6502 if (unlikely(it == recv_data.send_status_list.end()))
6504 boost::format formatter("Sending possible data is not existed. thread id : %d.");
6505 formatter % boost::this_thread::get_id();
6506 putLogError(100103, formatter.str(), __FILE__, __LINE__ );
6510 //buffer size >= sending_possible size
6511 if (send_buffer_size > it->send_possible_size)
6513 /*-------- DEBUG LOG --------*/
6514 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6516 std::string datadump;
6517 dump_memory(recv_data.recive_buffer + it->send_offset, it->send_possible_size, datadump);
6519 boost::format formatter(
6520 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6521 "handle_client_connection_check() : before memcpy (data dump) : "
6522 "data begin = %d, data_size = %d, data = %s");
6523 formatter % it->send_offset % (it->send_possible_size) % datadump;
6524 putLogDebug(100215, formatter.str(), __FILE__, __LINE__ );
6526 /*------DEBUG LOG END------*/
6527 //copy data from recive_buffer to sendbuffer by sending_possible size
6528 memcpy(sendbuffer.data(), recv_data.recive_buffer + it->send_offset, it->send_possible_size);
6529 /*-------- DEBUG LOG --------*/
6530 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6532 std::string datadump;
6533 dump_memory(sendbuffer.data(), it->send_possible_size, datadump);
6535 boost::format formatter(
6536 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6537 "handle_client_connection_check() : after memcpy (data dump) : "
6538 "data begin = 0, data_size = %d, data = %s");
6539 formatter % (it->send_possible_size) % datadump;
6540 putLogDebug(100216, formatter.str(), __FILE__, __LINE__ );
6542 /*------DEBUG LOG END------*/
6543 //send_end_size recalc
6544 it->send_end_size = it->send_possible_size;
6545 //set copyed data length
6546 datalen = it->send_possible_size;
6547 //sending_possible size recalc
6548 it->send_possible_size = 0;
6550 //buffer size < sending_possible size
6553 /*-------- DEBUG LOG --------*/
6554 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6556 std::string datadump;
6557 dump_memory(recv_data.recive_buffer + it->send_offset, send_buffer_size, datadump);
6559 boost::format formatter(
6560 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6561 "handle_client_connection_check() : before memcpy (data dump) : "
6562 "data begin = %d, data_size = %d, data = %s");
6563 formatter % it->send_offset % send_buffer_size % datadump;
6564 putLogDebug(100217, formatter.str(), __FILE__, __LINE__ );
6566 /*------DEBUG LOG END------*/
6567 //copy data from recive_buffer to sendbuffer by buffer size
6568 memcpy(sendbuffer.data(), recv_data.recive_buffer + it->send_offset, send_buffer_size);
6569 /*-------- DEBUG LOG --------*/
6570 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6572 std::string datadump;
6573 dump_memory(sendbuffer.data(), send_buffer_size, datadump);
6575 boost::format formatter(
6576 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6577 "handle_client_connection_check() : after memcpy (data dump) : "
6578 "data begin = 0, data_size = %d, data = %s");
6579 formatter % send_buffer_size % datadump;
6580 putLogDebug(100218, formatter.str(), __FILE__, __LINE__ );
6582 /*------DEBUG LOG END------*/
6583 //send_end_size recalc
6584 it->send_end_size = send_buffer_size;
6585 //sending_possible size recalc
6586 it->send_possible_size -= send_buffer_size;
6587 //set copyed data length
6588 datalen = send_buffer_size;
6591 status = CLIENT_SEND;
6595 /*-------- DEBUG LOG --------*/
6596 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6598 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6599 "handle_client_connection_check() : catch exception e = %d. thread id : %d.");
6600 formatter % e % boost::this_thread::get_id();
6601 putLogDebug(100219, formatter.str(), __FILE__, __LINE__ );
6603 /*------DEBUG LOG END------*/
6606 catch (const std::exception& ex)
6608 std::cerr << "protocol_module_sessionless::handle_client_connection_check() : exception : error = " << ex.what() << "." << std::endl;
6609 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6610 "handle_client_connection_check() : exception : error = %s. thread id : %d.");
6611 formatter % ex.what() % boost::this_thread::get_id();
6612 putLogError(100104, formatter.str(), __FILE__, __LINE__ );
6617 std::cerr << "protocol_module_sessionless::handle_client_connection_check() : Unknown exception." << std::endl;
6618 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6619 "handle_client_connection_check() : Unknown exception. thread id : %d.");
6620 formatter % boost::this_thread::get_id();
6621 putLogError(100105, formatter.str(), __FILE__, __LINE__ );
6625 /*-------- DEBUG LOG --------*/
6626 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6628 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6629 "handle_client_connection_check(const boost::thread::id thread_id, "
6630 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)"
6631 " : return_value = %d. thread id : %d.");
6632 formatter % status % boost::this_thread::get_id();
6633 putLogDebug(100220, formatter.str(), __FILE__, __LINE__ );
6635 /*------DEBUG LOG END------*/
6639 //! called from after client select. use UDP only
6640 //! @param[in] downstream thread id
6641 //! @param[in] client udp endpoint
6642 //! @param[out] send buffer reference
6643 //! @param[out] send data length
6644 //! @return session use EVENT mode
6645 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_select(
6646 const boost::thread::id thread_id, boost::asio::ip::udp::endpoint& cl_endpoint, boost::array<char,
6647 MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
6649 /*-------- DEBUG LOG --------*/
6650 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6652 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6653 "handle_client_select(const boost::thread::id thread_id, "
6654 "boost::asio::ip::udp::endpoint& cl_endpoint, "
6655 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
6656 "size_t& datalen) : "
6657 "return_value = %d. thread id : %d.");
6658 formatter % STOP % boost::this_thread::get_id();
6659 putLogDebug(100221, formatter.str(), __FILE__, __LINE__ );
6661 /*------DEBUG LOG END------*/
6665 //! called from after client send
6666 //! @param[in] downstream thread id
6667 //! @return session use EVENT mode
6668 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_send(
6669 const boost::thread::id thread_id)
6671 /*-------- DEBUG LOG --------*/
6672 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6674 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6675 "handle_client_send(const boost::thread::id thread_id) : "
6677 formatter % thread_id;
6678 putLogDebug(100222, formatter.str(), __FILE__, __LINE__ );
6680 /*------DEBUG LOG END------*/
6681 EVENT_TAG status = FINALIZE;
6682 thread_data_ptr session_data;
6683 session_thread_data_map_it session_thread_it;
6684 recive_data_map_it recive_data_it;
6689 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
6691 session_thread_it = session_thread_data_map.find(thread_id);
6692 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
6694 boost::format formatter("Invalid thread id. thread id : %d.");
6695 formatter % boost::this_thread::get_id();
6696 putLogError(100106, formatter.str(), __FILE__, __LINE__ );
6699 session_data = session_thread_it->second;
6702 recive_data_it = session_data->recive_data_map.find(session_data->target_endpoint);
6703 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
6705 boost::format formatter("Invalid endpoint. thread id : %d.");
6706 formatter % boost::this_thread::get_id();
6707 putLogError(100107, formatter.str(), __FILE__, __LINE__ );
6711 recive_data& recv_data = recive_data_it->second;
6713 send_status_it it = recv_data.send_status_list.begin();
6714 send_status_it it_end = recv_data.send_status_list.end();
6717 it = std::adjacent_find(it, it_end, data_send_list_incorrect());
6718 if (unlikely(it != it_end))
6720 boost::format formatter("Sending possible data is invalid. thread id : %d.");
6721 formatter % boost::this_thread::get_id();
6722 putLogError(100108, formatter.str(), __FILE__, __LINE__ );
6726 it = recv_data.send_status_list.begin();
6727 it = find_if(it, it_end, data_send_ok());
6728 if (unlikely(it == it_end))
6730 boost::format formatter("Sending possible data is not existed. thread id : %d.");
6731 formatter % boost::this_thread::get_id();
6732 putLogError(100109, formatter.str(), __FILE__, __LINE__ );
6736 //sending possible data is exist
6737 if (it->send_possible_size > 0)
6739 //status remain SEND_OK
6740 it->status = SEND_OK;
6742 it->send_offset += it->send_end_size;
6743 //send_end_size recalc
6744 it->send_end_size = 0;
6746 //sending possible data is not exist
6749 //can recive from clent continue
6750 if (it->send_rest_size > 0)
6752 //change status from SEND_OK to SEND_CONTINUE
6753 it->status = SEND_CONTINUE;
6755 //can not recive from clent continue
6758 //change status from SEND_OK to SEND_END
6759 it->status = SEND_END;
6763 it = recv_data.send_status_list.begin();
6764 it = find_if(it, it_end, data_send_ok());
6765 //send_ok item is exist
6768 status = CLIENT_CONNECTION_CHECK;
6770 //send_ok item is not exist
6774 if (session_data->end_flag == END_FLAG_ON)
6776 status = CLIENT_DISCONNECT;
6782 if (session_data->sorry_flag == SORRY_FLAG_ON)
6784 status = SORRYSERVER_RECV;
6789 status = REALSERVER_RECV;
6796 /*-------- DEBUG LOG --------*/
6797 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6799 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6800 "handle_client_send() : catch exception e = %d. thread id : %d.");
6801 formatter % e % boost::this_thread::get_id();
6802 putLogDebug(100223, formatter.str(), __FILE__, __LINE__ );
6804 /*------DEBUG LOG END------*/
6807 catch (const std::exception& ex)
6809 std::cerr << "protocol_module_sessionless::handle_client_send() : exception : error = " << ex.what() << "." << std::endl;
6810 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6811 "handle_client_send() : exception : error = %s. thread id : %d.");
6812 formatter % ex.what() % boost::this_thread::get_id();
6813 putLogError(100110, formatter.str(), __FILE__, __LINE__ );
6818 std::cerr << "protocol_module_sessionless::handle_client_send() : Unknown exception." << std::endl;
6819 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6820 "handle_client_send() : Unknown exception. thread id : %d.");
6821 formatter % boost::this_thread::get_id();
6822 putLogError(100111, formatter.str(), __FILE__, __LINE__ );
6826 /*-------- DEBUG LOG --------*/
6827 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6829 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6830 "handle_client_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
6831 formatter % status % boost::this_thread::get_id();
6832 putLogDebug(100224, formatter.str(), __FILE__, __LINE__ );
6834 /*------DEBUG LOG END------*/
6839 //! call from client disconnect event. use upstream thread and downstream thread.
6840 //! @param[in] upstream and downstream thread id( check! one thread one event! )
6841 //! @return session use EVENT mode
6842 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_disconnect(
6843 const boost::thread::id thread_id)
6845 /*-------- DEBUG LOG --------*/
6846 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6848 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6849 "handle_client_disconnect(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
6850 formatter % FINALIZE % boost::this_thread::get_id();
6851 putLogDebug(100225, formatter.str(), __FILE__, __LINE__ );
6853 /*------DEBUG LOG END------*/
6857 //! call from sorry mode event. use upstream thread and downstream thread
6858 //! @param[in] upstream and downstream thread id( check! one thread one event and first time call pattern )
6859 //! @return session use EVENT mode
6860 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorry_enable(
6861 const boost::thread::id thread_id)
6863 /*-------- DEBUG LOG --------*/
6864 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6866 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6867 "handle_sorry_enable(const boost::thread::id thread_id) : "
6869 formatter % thread_id;
6870 putLogDebug(100226, formatter.str(), __FILE__, __LINE__ );
6872 /*------DEBUG LOG END------*/
6874 EVENT_TAG status = FINALIZE;
6875 boost::asio::ip::tcp::endpoint endpoint;
6876 bool send_possible = false;
6877 bool send_continue = false;
6878 bool send_disable = false;
6879 thread_data_ptr session_data;
6880 session_thread_data_map_it session_thread_it;
6881 recive_data_map_it recive_data_it;
6886 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
6888 session_thread_it = session_thread_data_map.find(thread_id);
6889 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
6891 boost::format formatter("Invalid thread id. thread id : %d.");
6892 formatter % boost::this_thread::get_id();
6893 putLogError(100112, formatter.str(), __FILE__, __LINE__ );
6897 session_data = session_thread_it->second;
6900 endpoint = session_data->thread_division == THREAD_DIVISION_UP_STREAM ? session_data->client_endpoint_tcp
6901 : session_data->target_endpoint;
6902 recive_data_it = session_data->recive_data_map.find(endpoint);
6903 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
6905 //must be down thread
6906 if (unlikely(session_data->thread_division == THREAD_DIVISION_UP_STREAM))
6908 boost::format formatter("Invalid endpoint. thread id : %d.");
6909 formatter % boost::this_thread::get_id();
6910 putLogError(100113, formatter.str(), __FILE__, __LINE__ );
6913 session_data->sorry_flag = SORRY_FLAG_ON;
6914 /*-------- DEBUG LOG --------*/
6915 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6917 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6918 "handle_sorry_enable() : SORRY_FLAG_ON. thread id : %d.");
6919 formatter % boost::this_thread::get_id();
6920 putLogDebug(100227, formatter.str(), __FILE__, __LINE__ );
6922 /*------DEBUG LOG END------*/
6923 status = SORRYSERVER_RECV;
6927 recive_data& recv_data = recive_data_it->second;
6929 //get this thread sending possible data
6930 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
6931 data_send_possible());
6932 if (it != recv_data.send_status_list.end())
6934 send_possible = true;
6937 it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_continue());
6938 if (it != recv_data.send_status_list.end())
6940 send_continue = true;
6943 it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_disable());
6944 if (it != recv_data.send_status_list.end())
6946 send_disable = true;
6950 if (session_data->thread_division == THREAD_DIVISION_UP_STREAM)
6952 //accept_end_flag is off
6953 if (session_data->accept_end_flag == ACCEPT_END_FLAG_OFF)
6956 session_data->sorry_flag = SORRY_FLAG_ON;
6957 /*-------- DEBUG LOG --------*/
6958 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6960 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6961 "handle_sorry_enable() : SORRY_FLAG_ON. thread id : %d.");
6962 formatter % boost::this_thread::get_id();
6963 putLogDebug(100228, formatter.str(), __FILE__, __LINE__ );
6965 /*------DEBUG LOG END------*/
6968 //accept_end_flag is on
6972 if (session_data->sorry_flag == SORRY_FLAG_ON)
6976 status = SORRYSERVER_CONNECT;
6980 status = SORRYSERVER_SELECT;
6984 //set sorry flag off
6987 //the data that can be sent continue is exist
6991 session_data->end_flag = END_FLAG_ON;
6992 /*-------- DEBUG LOG --------*/
6993 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6995 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6996 "handle_sorry_enable() : END_FLAG_ON. thread id : %d.");
6997 formatter % boost::this_thread::get_id();
6998 putLogDebug(100229, formatter.str(), __FILE__, __LINE__ );
7000 /*------DEBUG LOG END------*/
7001 status = REALSERVER_DISCONNECT;
7003 //the data that can be sent continue is not exist
7006 //set sorryserver_switch_flag on
7007 session_data->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_ON;
7008 /*-------- DEBUG LOG --------*/
7009 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7011 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7012 "handle_sorry_enable() : SORRYSERVER_SWITCH_FLAG_ON. thread id : %d.");
7013 formatter % boost::this_thread::get_id();
7014 putLogDebug(100230, formatter.str(), __FILE__, __LINE__ );
7016 /*------DEBUG LOG END------*/
7018 session_data->sorry_flag = SORRY_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() : SORRY_FLAG_ON. thread id : %d.");
7024 formatter % boost::this_thread::get_id();
7025 putLogDebug(100231, formatter.str(), __FILE__, __LINE__ );
7027 /*------DEBUG LOG END------*/
7028 status = REALSERVER_DISCONNECT;
7037 if (session_data->sorry_flag == SORRY_FLAG_ON)
7039 //sending possible data is exist
7042 status = CLIENT_CONNECTION_CHECK;
7044 //sending possible data is not exist
7047 status = SORRYSERVER_RECV;
7054 session_data->sorry_flag = SORRY_FLAG_ON;
7055 /*-------- DEBUG LOG --------*/
7056 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7058 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7059 "handle_sorry_enable() : SORRY_FLAG_ON. thread id : %d.");
7060 formatter % boost::this_thread::get_id();
7061 putLogDebug(100232, formatter.str(), __FILE__, __LINE__ );
7063 /*------DEBUG LOG END------*/
7064 session_data->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_ON;
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() : SORRYSERVER_SWITCH_FLAG_ON. thread id : %d.");
7070 formatter % boost::this_thread::get_id();
7071 putLogDebug(100233, formatter.str(), __FILE__, __LINE__ );
7073 /*------DEBUG LOG END------*/
7075 //sending ng data is exist or send_rest_size > 0
7079 session_data->end_flag = END_FLAG_ON;
7080 /*-------- DEBUG LOG --------*/
7081 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7083 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7084 "handle_sorry_enable() : END_FLAG_ON. thread id : %d.");
7085 formatter % boost::this_thread::get_id();
7086 putLogDebug(100234, formatter.str(), __FILE__, __LINE__ );
7088 /*------DEBUG LOG END------*/
7089 status = REALSERVER_DISCONNECT;
7094 //sending possible data is exist
7097 status = CLIENT_CONNECTION_CHECK;
7099 //sending possible data is not exist
7102 status = SORRYSERVER_RECV;
7111 /*-------- DEBUG LOG --------*/
7112 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7114 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7115 "handle_sorry_enable() : catch exception e = %d. thread id : %d.");
7116 formatter % e % boost::this_thread::get_id();
7117 putLogDebug(100235, formatter.str(), __FILE__, __LINE__ );
7119 /*------DEBUG LOG END------*/
7122 catch (const std::exception& ex)
7124 std::cerr << "protocol_module_sessionless::handle_sorry_enable() : exception : error = " << ex.what() << "." << std::endl;
7125 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7126 "handle_sorry_enable() : exception : error = %s. thread id : %d.");
7127 formatter % ex.what() % boost::this_thread::get_id();
7128 putLogError(100114, formatter.str(), __FILE__, __LINE__ );
7133 std::cerr << "protocol_module_sessionless::handle_sorry_enable() : Unknown exception." << std::endl;
7134 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7135 "handle_sorry_enable() : Unknown exception. thread id : %d.");
7136 formatter % boost::this_thread::get_id();
7137 putLogError(100115, formatter.str(), __FILE__, __LINE__ );
7141 /*-------- DEBUG LOG --------*/
7142 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7144 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7145 "handle_sorry_enable(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
7146 formatter % status % boost::this_thread::get_id();
7147 putLogDebug(100236, formatter.str(), __FILE__, __LINE__ );
7149 /*------DEBUG LOG END------*/
7154 //! call from sorry mode disable. use upstream thread and downstream thread.
7155 //! @param[in] upstream and downstream thread id( check! one thread one event )
7156 //! @return session use EVENT mode
7157 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorry_disable(
7158 const boost::thread::id thread_id)
7160 /*-------- DEBUG LOG --------*/
7161 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7163 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7164 "handle_sorry_disable(const boost::thread::id thread_id) : "
7166 formatter % thread_id;
7167 putLogDebug(100237, formatter.str(), __FILE__, __LINE__ );
7169 /*------DEBUG LOG END------*/
7170 EVENT_TAG status = FINALIZE;
7171 boost::asio::ip::tcp::endpoint endpoint;
7172 bool send_possible = false;
7173 bool send_disable = false;
7174 bool send_continue = false;
7175 thread_data_ptr session_data;
7180 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
7182 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
7183 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
7185 boost::format formatter("Invalid thread id. thread id : %d.");
7186 formatter % boost::this_thread::get_id();
7187 putLogError(100116, formatter.str(), __FILE__, __LINE__ );
7191 session_data = session_thread_it->second;
7194 endpoint = session_data->thread_division == THREAD_DIVISION_UP_STREAM ? session_data->client_endpoint_tcp
7195 : session_data->target_endpoint;
7196 recive_data_map_it recive_data_it = session_data->recive_data_map.find(endpoint);
7197 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
7199 //must be down thread
7200 if (unlikely(session_data->thread_division == THREAD_DIVISION_UP_STREAM))
7202 boost::format formatter("Invalid endpoint. thread id : %d.");
7203 formatter % boost::this_thread::get_id();
7204 putLogError(100117, formatter.str(), __FILE__, __LINE__ );
7208 session_data->sorry_flag = SORRY_FLAG_OFF;
7209 /*-------- DEBUG LOG --------*/
7210 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7212 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7213 "handle_sorry_disable() : SORRY_FLAG_OFF. thread id : %d.");
7214 formatter % boost::this_thread::get_id();
7215 putLogDebug(100238, formatter.str(), __FILE__, __LINE__ );
7217 /*------DEBUG LOG END------*/
7218 status = REALSERVER_RECV;
7222 recive_data& recv_data = recive_data_it->second;
7224 //get this thread sending possible data
7225 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
7226 data_send_possible());
7227 if (it != recv_data.send_status_list.end())
7229 send_possible = true;
7232 //sending ng data is exist or send_rest_size > 0
7233 it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_disable());
7234 if (it != recv_data.send_status_list.end())
7236 send_disable = true;
7239 //the data that can be sent continue is exist
7240 it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_continue());
7241 if (it != recv_data.send_status_list.end())
7243 send_continue = true;
7247 if (session_data->thread_division == THREAD_DIVISION_UP_STREAM)
7249 //accept_end_flag is off
7250 if (session_data->accept_end_flag == ACCEPT_END_FLAG_OFF)
7252 //set sorry flag off
7253 session_data->sorry_flag = SORRY_FLAG_OFF;
7254 /*-------- DEBUG LOG --------*/
7255 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7257 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7258 "handle_sorry_disable() : SORRY_FLAG_OFF. thread id : %d.");
7259 formatter % boost::this_thread::get_id();
7260 putLogDebug(100239, formatter.str(), __FILE__, __LINE__ );
7262 /*------DEBUG LOG END------*/
7266 //accept_end_flag is on
7270 if (session_data->sorry_flag == SORRY_FLAG_ON)
7272 //the data that can be sent continue is exist
7276 session_data->end_flag = END_FLAG_ON;
7277 /*-------- DEBUG LOG --------*/
7278 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7280 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7281 "handle_sorry_disable() : END_FLAG_ON. thread id : %d.");
7282 formatter % boost::this_thread::get_id();
7283 putLogDebug(100240, formatter.str(), __FILE__, __LINE__ );
7285 /*------DEBUG LOG END------*/
7286 status = SORRYSERVER_DISCONNECT;
7288 //the data that can be sent continue is not exist
7291 //set realserver_switch_flag on
7292 session_data->realserver_switch_flag = REALSERVER_SWITCH_FLAG_ON;
7293 /*-------- DEBUG LOG --------*/
7294 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7296 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7297 "handle_sorry_disable() : REALSERVER_SWITCH_FLAG_ON. thread id : %d.");
7298 formatter % boost::this_thread::get_id();
7299 putLogDebug(100241, formatter.str(), __FILE__, __LINE__ );
7301 /*------DEBUG LOG END------*/
7302 //set sorry_flag off
7303 session_data->sorry_flag = SORRY_FLAG_OFF;
7304 /*-------- DEBUG LOG --------*/
7305 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7307 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7308 "handle_sorry_disable() : SORRY_FLAG_OFF. thread id : %d.");
7309 formatter % boost::this_thread::get_id();
7310 putLogDebug(100242, formatter.str(), __FILE__, __LINE__ );
7312 /*------DEBUG LOG END------*/
7313 status = SORRYSERVER_DISCONNECT;
7321 status = REALSERVER_CONNECT;
7325 status = REALSERVER_SELECT;
7334 if (session_data->sorry_flag == SORRY_FLAG_ON)
7336 //set sorry_flag off
7337 session_data->sorry_flag = SORRY_FLAG_OFF;
7338 /*-------- DEBUG LOG --------*/
7339 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7341 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7342 "handle_sorry_disable() : SORRY_FLAG_OFF. thread id : %d.");
7343 formatter % boost::this_thread::get_id();
7344 putLogDebug(100243, formatter.str(), __FILE__, __LINE__ );
7346 /*------DEBUG LOG END------*/
7347 session_data->realserver_switch_flag = REALSERVER_SWITCH_FLAG_ON;
7348 /*-------- DEBUG LOG --------*/
7349 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7351 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7352 "handle_sorry_disable() : REALSERVER_SWITCH_FLAG_ON. thread id : %d.");
7353 formatter % boost::this_thread::get_id();
7354 putLogDebug(100244, formatter.str(), __FILE__, __LINE__ );
7356 /*------DEBUG LOG END------*/
7357 //sending ng data is exist or send_rest_size > 0
7361 session_data->end_flag = END_FLAG_ON;
7362 /*-------- DEBUG LOG --------*/
7363 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7365 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7366 "handle_sorry_disable() : END_FLAG_ON. thread id : %d.");
7367 formatter % boost::this_thread::get_id();
7368 putLogDebug(100245, formatter.str(), __FILE__, __LINE__ );
7370 /*------DEBUG LOG END------*/
7371 status = SORRYSERVER_DISCONNECT;
7376 //sending possible data is exist
7379 status = CLIENT_CONNECTION_CHECK;
7381 //sending possible data is not exist
7384 status = REALSERVER_RECV;
7391 //sending possible data is exist
7394 status = CLIENT_CONNECTION_CHECK;
7396 //sending possible data is not exist
7399 status = REALSERVER_RECV;
7409 /*-------- DEBUG LOG --------*/
7410 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7412 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7413 "handle_sorry_disable() : catch exception e = %d. thread id : %d.");
7414 formatter % e % boost::this_thread::get_id();
7415 putLogDebug(100246, formatter.str(), __FILE__, __LINE__ );
7417 /*------DEBUG LOG END------*/
7420 catch (std::exception& ex)
7422 std::cerr << "protocol_module_sessionless::handle_sorry_disable() : exception : error = " << ex.what() << "." << std::endl;
7423 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7424 "handle_sorry_disable() : exception : error = %s. thread id : %d.");
7425 formatter % ex.what() % boost::this_thread::get_id();
7426 putLogError(100118, formatter.str(), __FILE__, __LINE__ );
7431 std::cerr << "protocol_module_sessionless::handle_sorry_disable() : Unknown exception." << std::endl;
7432 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7433 "handle_sorry_disable() : Unknown exception. thread id : %d.");
7434 formatter % boost::this_thread::get_id();
7435 putLogError(100119, formatter.str(), __FILE__, __LINE__ );
7439 /*-------- DEBUG LOG --------*/
7440 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7442 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7443 "handle_sorry_disable(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
7444 formatter % status % boost::this_thread::get_id();
7445 putLogDebug(100247, formatter.str(), __FILE__, __LINE__ );
7447 /*------DEBUG LOG END------*/
7452 //! call from realserver disconnect. use upstream thread and downstream thread
7453 //! @param[in] upstream and downstream thread id( check! one thread one event )
7454 //! @param[in] disconnected realserver endpoint.
7455 //! @return session use EVENT mode
7456 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_disconnect(
7457 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint)
7459 /*-------- DEBUG LOG --------*/
7460 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7462 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7463 "handle_realserver_disconnect(const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint) : "
7464 "thread_id = %d, rs_endpoint = [%s]:%d.");
7465 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
7466 putLogDebug(100248, formatter.str(), __FILE__, __LINE__ );
7468 /*------DEBUG LOG END------*/
7469 EVENT_TAG status = FINALIZE;
7470 bool possible_flag = false;
7471 thread_data_ptr session_data;
7472 boost::asio::ip::tcp::endpoint endpoint;
7477 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
7479 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
7480 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
7482 boost::format formatter("Invalid thread id. thread id : %d.");
7483 formatter % boost::this_thread::get_id();
7484 putLogError(100120, formatter.str(), __FILE__, __LINE__ );
7488 session_data = session_thread_it->second;
7491 endpoint = session_data->thread_division == THREAD_DIVISION_UP_STREAM ? session_data->client_endpoint_tcp
7492 : session_data->target_endpoint;
7493 recive_data_map_it recive_data_it = session_data->recive_data_map.find(endpoint);
7494 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
7496 boost::format formatter("Invalid endpoint. thread id : %d.");
7497 formatter % boost::this_thread::get_id();
7498 putLogError(100121, formatter.str(), __FILE__, __LINE__ );
7502 recive_data& recv_data = recive_data_it->second;
7504 //the data that can be sent possible is exist
7505 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
7506 data_send_possible());
7507 if (it != recv_data.send_status_list.end())
7509 possible_flag = true;
7513 if (session_data->thread_division == THREAD_DIVISION_UP_STREAM)
7516 if (session_data->end_flag == END_FLAG_ON)
7518 status = CLIENT_RECV;
7523 //sorryserver_switch_flag is on
7524 if (session_data->sorryserver_switch_flag == SORRYSERVER_SWITCH_FLAG_ON)
7526 session_data->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_OFF;
7527 /*-------- DEBUG LOG --------*/
7528 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7530 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7531 "handle_realserver_disconnect() : SORRYSERVER_SWITCH_FLAG_OFF. thread id : %d.");
7532 formatter % boost::this_thread::get_id();
7533 putLogDebug(100249, formatter.str(), __FILE__, __LINE__ );
7535 /*------DEBUG LOG END------*/
7537 status = SORRYSERVER_SELECT;
7540 //sorryserver_switch_flag is off
7544 session_data->end_flag = END_FLAG_ON;
7545 /*-------- DEBUG LOG --------*/
7546 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7548 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7549 "handle_realserver_disconnect() : END_FLAG_ON. thread id : %d.");
7550 formatter % boost::this_thread::get_id();
7551 putLogDebug(100250, formatter.str(), __FILE__, __LINE__ );
7553 /*------DEBUG LOG END------*/
7554 status = CLIENT_RECV;
7561 if (session_data->end_flag == END_FLAG_ON)
7563 status = CLIENT_DISCONNECT;
7567 if (session_data->sorryserver_switch_flag == SORRYSERVER_SWITCH_FLAG_ON)
7569 session_data->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_OFF;
7570 /*-------- DEBUG LOG --------*/
7571 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7573 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7574 "handle_realserver_disconnect() : SORRYSERVER_SWITCH_FLAG_OFF. thread id : %d.");
7575 formatter % boost::this_thread::get_id();
7576 putLogDebug(100251, formatter.str(), __FILE__, __LINE__ );
7578 /*------DEBUG LOG END------*/
7579 status = SORRYSERVER_RECV;
7584 session_data->end_flag = END_FLAG_ON;
7585 /*-------- DEBUG LOG --------*/
7586 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7588 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7589 "handle_realserver_disconnect() : END_FLAG_ON. thread id : %d.");
7590 formatter % boost::this_thread::get_id();
7591 putLogDebug(100252, formatter.str(), __FILE__, __LINE__ );
7593 /*------DEBUG LOG END------*/
7594 status = CLIENT_DISCONNECT;
7598 //the data that can be sent possible is exist
7601 status = CLIENT_CONNECTION_CHECK;
7607 /*-------- DEBUG LOG --------*/
7608 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7610 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7611 "handle_realserver_disconnect() : catch exception e = %d. thread id : %d.");
7612 formatter % e % boost::this_thread::get_id();
7613 putLogDebug(100253, formatter.str(), __FILE__, __LINE__ );
7615 /*------DEBUG LOG END------*/
7618 catch (std::exception& ex)
7620 std::cerr << "protocol_module_sessionless::handle_realserver_disconnect() : exception: error = " << ex.what() << "." << std::endl;
7621 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7622 "handle_realserver_disconnect() : exception : error = %s. thread id : %d.");
7623 formatter % ex.what() % boost::this_thread::get_id();
7624 putLogError(100122, formatter.str(), __FILE__, __LINE__ );
7629 std::cerr << "protocol_module_sessionless::handle_realserver_disconnect() : Unknown exception." << std::endl;
7630 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7631 "handle_realserver_disconnect() : Unknown exception. thread id : %d.");
7632 formatter % boost::this_thread::get_id();
7633 putLogError(100123, formatter.str(), __FILE__, __LINE__ );
7637 /*-------- DEBUG LOG --------*/
7638 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7640 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7641 "handle_realserver_disconnect(const boost::thread::id thread_id, "
7642 "const boost::asio::ip::tcp::endpoint & rs_endpoint) : return_value = %d. thread id : %d.");
7643 formatter % status % boost::this_thread::get_id();
7644 putLogDebug(100254, formatter.str(), __FILE__, __LINE__ );
7646 /*------DEBUG LOG END------*/
7651 //! call from sorry server disconnect. use upstraem thread and downstream thread
7652 //! @param[in] upstream and downstream thread id( check! one thread one event )
7653 //! @param[in] disconnect sorryserver endpoint
7654 //! @return session use EVENT mode
7655 //! @return session use EVENT mode
7656 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_disconnect(
7657 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint)
7659 /*-------- DEBUG LOG --------*/
7660 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7664 "in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7665 "handle_sorryserver_disconnect(const boost::thread::id thread_id, "
7666 "const boost::asio::ip::tcp::endpoint & sorry_endpoint) : "
7667 "thread_id = %d, sorry_endpoint = [%s]:%d.");
7668 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port() ;
7669 putLogDebug(100255, formatter.str(), __FILE__, __LINE__ );
7671 /*------DEBUG LOG END------*/
7672 EVENT_TAG status = FINALIZE;
7673 bool possible_flag = false;
7674 thread_data_ptr session_data;
7675 boost::asio::ip::tcp::endpoint endpoint;
7680 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
7682 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
7683 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
7685 boost::format formatter("Invalid thread id. thread id : %d.");
7686 formatter % boost::this_thread::get_id();
7687 putLogError(100124, formatter.str(), __FILE__, __LINE__ );
7691 session_data = session_thread_it->second;
7694 endpoint = session_data->thread_division == THREAD_DIVISION_UP_STREAM ? session_data->client_endpoint_tcp
7695 : session_data->target_endpoint;
7696 recive_data_map_it recive_data_it = session_data->recive_data_map.find(endpoint);
7697 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
7699 boost::format formatter("Invalid endpoint. thread id : %d.");
7700 formatter % boost::this_thread::get_id();
7701 putLogError(100125, formatter.str(), __FILE__, __LINE__ );
7705 recive_data& recv_data = recive_data_it->second;
7707 //the data that can be sent possible is exist
7708 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
7709 data_send_possible());
7710 if (it != recv_data.send_status_list.end())
7712 possible_flag = true;
7716 if (session_data->thread_division == THREAD_DIVISION_UP_STREAM)
7719 if (session_data->end_flag == END_FLAG_ON)
7721 status = CLIENT_RECV;
7726 //realserver_switch_flag is on
7727 if (session_data->realserver_switch_flag == REALSERVER_SWITCH_FLAG_ON)
7729 session_data->realserver_switch_flag = REALSERVER_SWITCH_FLAG_OFF;
7730 /*-------- DEBUG LOG --------*/
7731 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7733 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7734 "handle_sorryserver_disconnect() : REALSERVER_SWITCH_FLAG_OFF. thread id : %d.");
7735 formatter % boost::this_thread::get_id();
7736 putLogDebug(100256, formatter.str(), __FILE__, __LINE__ );
7738 /*------DEBUG LOG END------*/
7739 status = REALSERVER_SELECT;
7741 //realserver_switch_flag is off
7745 session_data->end_flag = END_FLAG_ON;
7746 /*-------- DEBUG LOG --------*/
7747 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7749 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7750 "handle_sorryserver_disconnect() : END_FLAG_ON. thread id : %d.");
7751 formatter % boost::this_thread::get_id();
7752 putLogDebug(100257, formatter.str(), __FILE__, __LINE__ );
7754 /*------DEBUG LOG END------*/
7755 status = CLIENT_RECV;
7762 if (session_data->end_flag == END_FLAG_ON)
7764 status = CLIENT_DISCONNECT;
7768 if (session_data->realserver_switch_flag == REALSERVER_SWITCH_FLAG_ON)
7770 session_data->realserver_switch_flag = REALSERVER_SWITCH_FLAG_OFF;
7771 /*-------- DEBUG LOG --------*/
7772 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7774 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7775 "handle_sorryserver_disconnect() : REALSERVER_SWITCH_FLAG_OFF. thread id : %d.");
7776 formatter % boost::this_thread::get_id();
7777 putLogDebug(100258, formatter.str(), __FILE__, __LINE__ );
7779 /*------DEBUG LOG END------*/
7780 status = REALSERVER_RECV;
7784 session_data->end_flag = END_FLAG_ON;
7785 /*-------- DEBUG LOG --------*/
7786 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7788 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7789 "handle_sorryserver_disconnect() : END_FLAG_ON. thread id : %d.");
7790 formatter % boost::this_thread::get_id();
7791 putLogDebug(100259, formatter.str(), __FILE__, __LINE__ );
7793 /*------DEBUG LOG END------*/
7794 status = CLIENT_DISCONNECT;
7798 //the data that can be sent possible is exist
7801 status = CLIENT_CONNECTION_CHECK;
7807 /*-------- DEBUG LOG --------*/
7808 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7810 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7811 "handle_sorryserver_disconnect() : catch exception e = %d. thread id : %d.");
7812 formatter % e % boost::this_thread::get_id();
7813 putLogDebug(100260, formatter.str(), __FILE__, __LINE__ );
7815 /*------DEBUG LOG END------*/
7818 catch (const std::exception& ex)
7820 std::cerr << "protocol_module_sessionless::handle_sorryserver_disconnect() : exception : error = " << ex.what() << "." << std::endl;
7821 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7822 "handle_sorryserver_disconnect() : exception : error = %s. thread id : %d.");
7823 formatter % ex.what() % boost::this_thread::get_id();
7824 putLogError(100126, formatter.str(), __FILE__, __LINE__ );
7829 std::cerr << "protocol_module_sessionless::handle_sorryserver_disconnect() : Unknown exception." << std::endl;
7830 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7831 "handle_sorryserver_disconnect() : Unknown exception. thread id : %d.");
7832 formatter % boost::this_thread::get_id();
7833 putLogError(100127, formatter.str(), __FILE__, __LINE__ );
7837 /*-------- DEBUG LOG --------*/
7838 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7842 "out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7843 "handle_sorryserver_disconnect(const boost::thread::id thread_id, "
7844 "const boost::asio::ip::tcp::endpoint& sorry_endpoint) : return_value = %d. thread id : %d.");
7845 formatter % status % boost::this_thread::get_id();
7846 putLogDebug(100261, formatter.str(), __FILE__, __LINE__ );
7848 /*------DEBUG LOG END------*/
7853 //! call from realserver disconnect. use upstream thread and downstream thread.
7854 //! @param[in] upstream and downstream thread id( check! one thread one event )
7855 //! @param[in] disconnect realserver endpoint
7856 //! @return session use EVENT mode.
7857 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_close(
7858 const boost::thread::id thread_id, const boost::asio::ip::udp::endpoint & rs_endpoint)
7860 /*-------- DEBUG LOG --------*/
7861 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7863 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7864 "handle_realserver_close(const boost::thread::id thread_id, "
7865 "const boost::asio::ip::udp::endpoint & rs_endpoint) : "
7866 "return_value = %d. thread id : %d.");
7867 formatter % STOP % boost::this_thread::get_id();
7868 putLogDebug(100262, formatter.str(), __FILE__, __LINE__ );
7870 /*------DEBUG LOG END------*/
7876 extern "C" l7vs::protocol_module_base*
7879 return dynamic_cast<l7vs::protocol_module_base*>(new l7vs::protocol_module_sessionless());
7883 destroy_module( l7vs::protocol_module_base* in )