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');
69 protocol_module_sessionless::~protocol_module_sessionless()
72 //! tcp protocol support check
73 //! @return tcp support is true
74 //! @return tcp not-support is false
75 bool protocol_module_sessionless::is_tcp()
77 /*-------- DEBUG LOG --------*/
78 if (unlikely(LOG_LV_DEBUG == getloglevel()))
80 putLogDebug(100000, "in/out_function : bool protocol_module_sessionless::is_tcp() : "
81 "return_value = true.", __FILE__, __LINE__ );
83 /*------DEBUG LOG END------*/
87 //! udp protocol support check
88 //! @return udp support is true
89 //! @return udp not-support is false
90 bool protocol_module_sessionless::is_udp()
92 /*-------- DEBUG LOG --------*/
93 if (unlikely(LOG_LV_DEBUG == getloglevel()))
95 putLogDebug(100001, "in/out_function : bool protocol_module_sessionless::is_udp() : "
96 "return_value = false.", __FILE__, __LINE__ );
98 /*------DEBUG LOG END------*/
102 //! replication interval interrrupt
103 //! timer thread call this function. from virtualservice.
104 void protocol_module_sessionless::replication_interrupt()
106 /*-------- DEBUG LOG --------*/
107 if (unlikely(LOG_LV_DEBUG == getloglevel()))
109 putLogDebug(100002, "in/out_function : void protocol_module_sessionless::"
110 "replication_interrupt().", __FILE__, __LINE__ );
112 /*------DEBUG LOG END------*/
114 //! initialize function. called from module control. module loaded call
115 //! @param[in] realserver list iterator begin function object type
116 //! @param[in] realserver list iterator end function object type
117 //! @param[in] realserver list iterator next function object type
118 //! @param[in] realserver list mutex lock function object type.
119 //! @param[in] realserver list mutex unlock function object type
120 void protocol_module_sessionless::initialize(rs_list_itr_func_type inlist_begin,
121 rs_list_itr_func_type inlist_end,
122 rs_list_itr_next_func_type inlist_next,
123 boost::function< void( void ) > inlist_lock,
124 boost::function< void( void ) > inlist_unlock)
126 /*-------- DEBUG LOG --------*/
127 if (unlikely(LOG_LV_DEBUG == getloglevel()))
129 putLogDebug(100003, "in_function : void protocol_module_sessionless::initialize("
130 "rs_list_itr_func_type inlist_begin, rs_list_itr_func_type inlist_end, "
131 "rs_list_itr_next_func_type inlist_next, boost::function< void( void ) > "
132 "inlist_lock, boost::function< void( void ) > inlist_unlock).", __FILE__, __LINE__ );
134 /*------DEBUG LOG END------*/
136 //RealServer list begin function
137 rs_list_begin = inlist_begin;
138 //RealServer list end function
139 rs_list_end = inlist_end;
140 //RealServer list next function
141 rs_list_next = inlist_next;
142 //RealServer list lock funtion
143 rs_list_lock = inlist_lock;
144 //RealServer list unlock funtion
145 rs_list_unlock = inlist_unlock;
147 /*-------- DEBUG LOG --------*/
148 if (unlikely(LOG_LV_DEBUG == getloglevel()))
150 putLogDebug(100004, "out_function : void protocol_module_sessionless::initialize("
151 "rs_list_itr_func_type inlist_begin, rs_list_itr_func_type inlist_end, "
152 "rs_list_itr_next_func_type inlist_next, boost::function< void( void ) > "
153 "inlist_lock, boost::function< void( void ) > inlist_unlock).", __FILE__, __LINE__ );
155 /*-------- DEBUG LOG --------*/
158 //! finalize called from module control. module unloaded call.
159 void protocol_module_sessionless::finalize()
161 /*-------- DEBUG LOG --------*/
162 if (unlikely(LOG_LV_DEBUG == getloglevel()))
164 putLogDebug(100005, "in_function : void protocol_module_sessionless::finalize().", __FILE__,
167 /*------DEBUG LOG END------*/
169 //RealServer list functions initializtion
170 //RealServer list begin function
171 rs_list_begin.clear();
172 //RealServer list end function
174 //RealServer list next function
175 rs_list_next.clear();
176 //RealServer list lock function
177 rs_list_lock.clear();
178 //RealServer list unlock function
179 rs_list_unlock.clear();
181 /*-------- DEBUG LOG --------*/
182 if (unlikely(LOG_LV_DEBUG == getloglevel()))
184 putLogDebug(100006, "function : void protocol_module_sessionless::finalize() : "
185 "rs_list_begin.clear(), rs_list_end.clear(), rs_list_next.clear(), rs_list_lock.clear(), rs_list_unlock.clear() end.", __FILE__,
188 /*------DEBUG LOG END------*/
190 //Replication functions initializtion
191 //component memory allcate function
192 replication_pay_memory.clear();
193 //component memory lock function
194 replication_area_lock.clear();
195 //component memory unlock function
196 replication_area_unlock.clear();
198 /*-------- DEBUG LOG --------*/
199 if (unlikely(LOG_LV_DEBUG == getloglevel()))
201 putLogDebug(100007, "function : void protocol_module_sessionless::finalize() : "
202 "replication_pay_memory.clear(), replication_area_lock.clear(), replication_area_unlock.clear() end.", __FILE__,
205 /*------DEBUG LOG END------*/
207 //ScheduleModule's functions initializtion
208 schedule_tcp.clear();
210 /*-------- DEBUG LOG --------*/
211 if (unlikely(LOG_LV_DEBUG == getloglevel()))
213 putLogDebug(100008, "function : void protocol_module_sessionless::finalize() : "
214 "schedule_tcp.clear(), schedule_udp.clear() end.", __FILE__,
217 /*------DEBUG LOG END------*/
219 //Module's option initializtion
221 forwarded_for = FORWARDED_FOR_OFF;
223 sorry_uri.assign('\0');
224 /*-------- DEBUG LOG --------*/
225 if (unlikely(LOG_LV_DEBUG == getloglevel()))
227 putLogDebug(100009, "function : void protocol_module_sessionless::finalize() : "
228 "forwarded_for = 0, sorry_uri.assign('\\0') end.", __FILE__,
231 /*------DEBUG LOG END------*/
232 /*-------- DEBUG LOG --------*/
233 if (unlikely(LOG_LV_DEBUG == getloglevel()))
235 putLogDebug(100010, "out_function : void protocol_module_sessionless::finalize().", __FILE__,
238 /*------DEBUG LOG END------*/
241 //logger functions initializtion
242 //log level getting function
256 //! sorry support check
257 //! @return true sorry mode is supported.
258 //! @return false sorry mode is unsupported.
259 bool protocol_module_sessionless::is_use_sorry()
261 /*-------- DEBUG LOG --------*/
262 if (unlikely(LOG_LV_DEBUG == getloglevel()))
264 putLogDebug(100011, "in/out_function : bool protocol_module_sessionless::is_use_sorry() : "
265 "return_value = true.", __FILE__, __LINE__ );
267 /*------DEBUG LOG END------*/
271 //! realserver list update event
272 void protocol_module_sessionless::handle_rslist_update()
274 /*-------- DEBUG LOG --------*/
275 if (unlikely(LOG_LV_DEBUG == getloglevel()))
277 putLogDebug(100012, "in/out_function : void protocol_module_sessionless::handle_rslist_update().", __FILE__,
280 /*------DEBUG LOG END------*/
283 //! module parameter check.used by l7vsadm
284 //! @param[in] module paramter string list
285 //! @return result.flag true is parameter is noproblem.
286 //! @return result.flag false is paramter is problem.
287 protocol_module_base::check_message_result protocol_module_sessionless::check_parameter(const std::vector<
290 /*-------- DEBUG LOG --------*/
291 if (unlikely(LOG_LV_DEBUG == getloglevel()))
293 boost::format formatter("in_function : protocol_module_base::check_message_result "
294 "protocol_module_sessionless::check_parameter("
295 "const std::vector<std::string>& args) : args = %s.");
296 std::string argsdump;
297 for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
302 formatter % argsdump;
303 putLogDebug(100013, formatter.str(), __FILE__, __LINE__ );
305 /*------DEBUG LOG END------*/
306 using namespace boost::xpressive;
307 //set check result true
308 check_message_result check_result;
309 check_result.flag = true;
310 bool forward_checked = false;
311 bool sorryuri_checked = false;
312 sregex sorry_uri_regex
316 ( set = ';', ':', '@', '&', '=' ) |
317 ( set = '$', '-', '_', '.', '+' ) |
318 ( set = '!', '*', '\'', '\(', ')', ',' ) |
319 '%' >> repeat<2>(xdigit)));
320 typedef std::vector<std::string>::const_iterator vec_str_it;
324 vec_str_it it = args.begin();
325 vec_str_it it_end = args.end();
326 //loop option strings
327 for (; it != it_end; ++it)
329 //option string = "-F"
330 if (*it == "-F" || *it == "--forwarded-for")
332 //set forward flag ON
333 forward_checked = true;
335 //option string = "-S"
336 else if (*it == "-S" || *it == "--sorry-uri")
338 //set sorryURI flag OFF
339 if (!sorryuri_checked)
344 if (!it->empty() && (it->substr(0, 1) == "-" || it->substr(0, 2) == "--"))
346 //set check result flag false
347 check_result.flag = false;
348 //set check result message
349 check_result.message = "You have to set option value '-S/--sorry-uri'.";
350 putLogError(100000, check_result.message, __FILE__, __LINE__ );
354 //next option string's length > 127
355 if (it->size() > MAX_OPTION_SIZE - 1)
357 std::ostringstream ostr;
358 ostr << "'-S/--sorry-uri' option value '" << *it << "' is too long.";
360 //set check result flag false
361 check_result.flag = false;
362 //set check result message
363 check_result.message = ostr.str();
365 putLogError(100001, check_result.message, __FILE__, __LINE__ );
369 //next option string's length <= 127
373 if (regex_match(*it, sorry_uri_regex ))
376 //set sorryURI flag ON
377 sorryuri_checked = true;
382 std::ostringstream ostr;
383 ostr << "'-S/--sorry-uri' option value '" << *it << "' is not a valid URI.";
385 //set check result flag false
386 check_result.flag = false;
387 //set check result message
388 check_result.message = ostr.str();
389 putLogError(100002, check_result.message, __FILE__, __LINE__ );
395 //next item is not exist
398 //set check flag false
399 check_result.flag = false;
400 //set check result message
401 check_result.message = "You have to set option value '-S/--sorry-uri'.";
402 putLogError(100003, check_result.message, __FILE__,
411 //set check result flag false
412 check_result.flag = false;
413 //set check result message
414 check_result.message = "Cannot set multiple option '-S/--sorry-uri'.";
415 putLogError(100004, check_result.message, __FILE__,
421 //other option string
424 //set check result flag false
425 check_result.flag = false;
426 //set check result message
427 check_result.message = "Option error.";
428 putLogError(100005, check_result.message, __FILE__, __LINE__ );
434 catch (const std::exception& ex)
436 check_result.flag = false;
437 std::cerr << "protocol_module_sessionless::check_parameter() : exception : error = " << ex.what() << "." << std::endl;
438 boost::format formatter("function : protocol_module_base::check_message_result "
439 "protocol_module_sessionless::check_parameter() exception : "
441 formatter % ex.what();
442 putLogError(100006, formatter.str(), __FILE__, __LINE__ );
446 check_result.flag = false;
447 std::cerr << "protocol_module_sessionless::check_parameter() : Unknown exception." << std::endl;
448 putLogError(100007, "function : protocol_module_base::check_message_result "
449 "protocol_module_sessionless::check_parameter() : "
450 "Unknown exception.", __FILE__, __LINE__ );
453 /*-------- DEBUG LOG --------*/
454 if (unlikely(LOG_LV_DEBUG == getloglevel()))
456 boost::format formatter("out_function : protocol_module_base::check_message_result "
457 "protocol_module_sessionless::check_parameter("
458 "const std::vector<std::string>& args) : return_value = ("
459 "check_message_result.flag = %d, check_message_result.message = %s).");
460 formatter % check_result.flag % check_result.message;
461 putLogDebug(100014, formatter.str(), __FILE__, __LINE__ );
463 /*------DEBUG LOG END------*/
468 //! @param[in] module paramter string list
469 //! @return result.flag true is parameter is noproblem.
470 //! @return result.flag false is paramter is problem.
471 protocol_module_base::check_message_result protocol_module_sessionless::set_parameter(const std::vector<
474 /*-------- DEBUG LOG --------*/
475 if (unlikely(LOG_LV_DEBUG == getloglevel()))
477 boost::format formatter("in_function : protocol_module_base::check_message_result "
478 "protocol_module_sessionless::set_parameter("
479 "const std::vector<std::string>& args) : args = %s.");
480 std::string argsdump;
481 for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
486 formatter % argsdump;
487 putLogDebug(100015, formatter.str(), __FILE__, __LINE__ );
489 /*------DEBUG LOG END------*/
490 using namespace boost::xpressive;
491 //set check result flag true
492 check_message_result check_result;
493 check_result.flag = true;
494 bool forward_checked = false;
495 bool sorryuri_checked = false;
496 sregex sorry_uri_regex
500 ( set = ';', ':', '@', '&', '=' ) |
501 ( set = '$', '-', '_', '.', '+' ) |
502 ( set = '!', '*', '\'', '\(', ')', ',' ) |
503 '%' >> repeat<2>(xdigit)));
505 typedef std::vector<std::string>::const_iterator vec_str_it;
507 //set forwarded flag true
512 vec_str_it it = args.begin();
513 vec_str_it it_end = args.end();
514 for (; it != it_end; ++it)
516 //option string = "-F"
517 if (*it == "-F" || *it == "--forwarded-for")
519 //set forwarded flag ON
520 forward_checked = true;
522 //option string = "-S"
523 else if (*it == "-S" || *it == "--sorry-uri")
525 //sorryURI flag = OFF
526 if (!sorryuri_checked)
531 if (!it->empty() && (it->substr(0, 1) == "-" || it->substr(0, 2) == "--"))
533 //set check result flag false
534 check_result.flag = false;
535 //set check result message
536 check_result.message = "You have to set option value '-S/--sorry-uri'.";
537 putLogError(100008, check_result.message, __FILE__,
542 //next option string's length > 127
543 if (it->size() > MAX_OPTION_SIZE - 1)
545 std::ostringstream ostr;
546 ostr << "'-S/--sorry-uri' option value '" << *it << "' is too long.";
548 //set check result flag false
549 check_result.flag = false;
550 //set check result message
551 check_result.message = ostr.str();
552 putLogError(100009, check_result.message, __FILE__,
557 //next option string's length <= 127
562 if (regex_match(*it, sorry_uri_regex))
564 sorryuri_checked = true;
565 strcpy(sorry_uri.data(), it->c_str());
570 std::ostringstream ostr;
571 ostr << "'-S/--sorry-uri' option value '" << *it << "' is not a valid URI.";
573 //set check result flag false
574 check_result.flag = false;
575 //set check result message
576 check_result.message = ostr.str();
577 putLogError(100010, check_result.message, __FILE__,
584 //next item not exist
587 //set check result flag false
588 check_result.flag = false;
589 //set check result message
590 check_result.message = "You have to set option value '-S/--sorry-uri'.";
591 putLogError(100011, check_result.message, __FILE__,
600 //set check result flag false
601 check_result.flag = false;
602 //set check result message
603 check_result.message = "Cannot set multiple option '-S/--sorry-uri'.";
604 putLogError(100012, check_result.message, __FILE__,
613 //set check result flag false
614 check_result.flag = false;
615 //set check result message
616 check_result.message = "Option error.";
618 putLogError(100013, check_result.message, __FILE__,
625 if (check_result.flag == true)
628 if (!forward_checked)
635 catch (const std::exception& ex)
637 check_result.flag = false;
638 std::cerr << "protocol_module_sessionless::set_parameter() : exception : error = " << ex.what() << "." << std::endl;
639 boost::format formatter("function : protocol_module_base::check_message_result "
640 "protocol_module_sessionless::set_parameter() : exception : "
642 formatter % ex.what();
643 putLogError(100014, formatter.str(), __FILE__, __LINE__ );
647 check_result.flag = false;
648 std::cerr << "protocol_module_sessionless::set_parameter() : Unknown exception." << std::endl;
649 putLogError(100015, "function : protocol_module_base::check_message_result "
650 "protocol_module_sessionless::set_parameter() : "
651 "Unknown exception.", __FILE__, __LINE__ );
654 /*-------- DEBUG LOG --------*/
655 if (unlikely(LOG_LV_DEBUG == getloglevel()))
657 boost::format formatter("out_function : protocol_module_base::check_message_result "
658 "protocol_module_sessionless::set_parameter("
659 "const std::vector<std::string>& args) : return_value = ("
660 "check_message_result.flag = %d, check_message_result.message = %s).");
661 formatter % check_result.flag % check_result.message;
662 putLogDebug(100016, formatter.str(), __FILE__, __LINE__ );
664 /*-------- DEBUG LOG END--------*/
670 //! @param[in] module paramter string list
671 //! @return result.flag true is parameter is noproblem.
672 //! @return result.flag false is paramter is problem.
673 protocol_module_base::check_message_result protocol_module_sessionless::add_parameter(const std::vector<
676 /*-------- DEBUG LOG --------*/
677 if (unlikely(LOG_LV_DEBUG == getloglevel()))
679 boost::format formatter("in_function : protocol_module_base::check_message_result "
680 "protocol_module_sessionless::add_parameter("
681 "const std::vector<std::string>& args) : args = %s.");
682 std::string argsdump;
683 for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
688 formatter % argsdump;
689 putLogDebug(100017, formatter.str(), __FILE__, __LINE__ );
691 /*------DEBUG LOG END------*/
692 check_message_result check_result;
693 //set check result flag true
694 check_result.flag = true;
696 //param list is not empty
699 //set check result flag false
700 check_result.flag = false;
701 //set check result message
702 check_result.message = "Cannot add option.";
703 putLogError(100016, check_result.message, __FILE__, __LINE__ );
706 /*-------- DEBUG LOG --------*/
707 if (unlikely(LOG_LV_DEBUG == getloglevel()))
709 boost::format formatter("out_function : protocol_module_base::check_message_result "
710 "protocol_module_sessionless::add_parameter("
711 "const std::vector<std::string>& args) : return_value = ("
712 "check_message_result.flag = %d, check_message_result.message = %s).");
713 formatter % check_result.flag % check_result.message;
714 putLogDebug(100018, formatter.str(), __FILE__, __LINE__ );
716 /*-------- DEBUG LOG --------*/
722 //! @param[out] module paramter string
723 void protocol_module_sessionless::get_option_info(std::string& option)
725 /*-------- DEBUG LOG --------*/
726 if (unlikely(LOG_LV_DEBUG == getloglevel()))
728 putLogDebug(100019, "in_function : void protocol_module_sessionless::get_option_info("
729 "std::string& option).", __FILE__, __LINE__);
731 /*------DEBUG LOG END------*/
733 boost::format option_formatter("%s--sorry-uri '%s'");
734 option_formatter % (forwarded_for ? "--forwarded-for " : "") % sorry_uri.c_array();
735 option.assign(option_formatter.str());
737 /*-------- DEBUG LOG --------*/
738 if (unlikely(LOG_LV_DEBUG == getloglevel()))
740 boost::format formatter("out_function : void protocol_module_sessionless::get_option_info("
741 "std::string& option) : option = %s.");
743 putLogDebug(100020, formatter.str(), __FILE__, __LINE__);
745 /*------DEBUG LOG END------*/
748 //! TCP/IP scheduled function registation.
749 //! @param[in] schedule module TCP/IP scheduled function object type
750 void protocol_module_sessionless::register_schedule(tcp_schedule_func_type inschedule)
752 /*-------- DEBUG LOG --------*/
753 if (unlikely(LOG_LV_DEBUG == getloglevel()))
755 putLogDebug(100021, "in_function : void protocol_module_sessionless::register_schedule("
756 "tcp_schedule_func_type inschedule).", __FILE__, __LINE__ );
758 /*------DEBUG LOG END------*/
759 schedule_tcp = inschedule;
760 /*-------- DEBUG LOG --------*/
761 if (unlikely(LOG_LV_DEBUG == getloglevel()))
763 putLogDebug(100022, "out_function : void protocol_module_sessionless::register_schedule("
764 "tcp_schedule_func_type inschedule).", __FILE__, __LINE__ );
766 /*------DEBUG LOG END------*/
769 //! UDP scheduled function registation
770 //! @param[in] schedule module UDP scheduled funtion object type
771 void protocol_module_sessionless::register_schedule(udp_schedule_func_type inschedule)
773 /*-------- DEBUG LOG --------*/
774 if (unlikely(LOG_LV_DEBUG == getloglevel()))
777 "in/out_function : void protocol_module_sessionless::register_schedule(udp_schedule_func_type inschedule).",
778 __FILE__, __LINE__ );
780 /*------DEBUG LOG END------*/
783 //! called from session initialzie use in upstream_thread
784 //! @param[in] upstream thread id.
785 //! @param[in] downstream thread id
786 //! @return session use EVENT mode.
787 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_session_initialize(
788 const boost::thread::id up_thread_id, const boost::thread::id down_thread_id,
789 const boost::asio::ip::tcp::endpoint& client_endpoint_tcp,
790 const boost::asio::ip::udp::endpoint& client_endpoint_udp)
792 /*-------- DEBUG LOG --------*/
793 if (unlikely(LOG_LV_DEBUG == getloglevel()))
795 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
796 "handle_session_initialize(const boost::thread::id up_thread_id, "
797 "const boost::thread::id down_thread_id, const boost::asio::ip::tcp::endpoint& client_endpoint_tcp, "
798 "const boost::asio::ip::udp::endpoint& client_endpoint_udp) : "
799 "up_thread_id = %d, down_thread_id = %d, client_endpoint_tcp = [%s]:%d.");
800 formatter % up_thread_id % down_thread_id % client_endpoint_tcp.address().to_string() % client_endpoint_tcp.port() ;
801 putLogDebug(100024, formatter.str(), __FILE__, __LINE__ );
803 /*------DEBUG LOG END------*/
804 EVENT_TAG status = FINALIZE;
806 //session thread initialization
809 thread_data_ptr p_up(new session_thread_data_sessionless);
810 /*-------- DEBUG LOG --------*/
811 if (unlikely(LOG_LV_DEBUG == getloglevel()))
813 boost::format formatter("new : address = &(%d), size = %lu.");
814 formatter % static_cast<void*>(p_up.get()) % sizeof(session_thread_data_sessionless);
815 putLogDebug(100025, formatter.str(), __FILE__, __LINE__ );
817 /*------DEBUG LOG END------*/
818 p_up->thread_id = up_thread_id;
819 p_up->thread_division = THREAD_DIVISION_UP_STREAM;
820 p_up->pair_thread_id = down_thread_id;
821 p_up->accept_end_flag = ACCEPT_END_FLAG_OFF;
822 p_up->end_flag = END_FLAG_OFF;
823 p_up->sorry_flag = SORRY_FLAG_OFF;
824 p_up->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_OFF;
825 p_up->realserver_switch_flag = REALSERVER_SWITCH_FLAG_OFF;
826 p_up->last_status = INITIALIZE;
827 p_up->client_endpoint_tcp = client_endpoint_tcp;
829 recive_data recv_data;
830 p_up->recive_data_map[client_endpoint_tcp] = recv_data;
832 /*-------- DEBUG LOG --------*/
833 if (unlikely(LOG_LV_DEBUG == getloglevel()))
837 formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
838 "handle_session_initialize() : session_thread_data_sessionless(up_thread_id) : "
839 "thread_id = %d, thread_division = %d, "
840 "pair_thread_id = %d, accept_end_flag = %d, end_flag = %d, "
841 "sorry_flag = %d, sorryserver_switch_flag = %d, realserver_switch_flag = %d, last_status = %d, client_endpoint_tcp = [%s]:%d.");
842 formatter % p_up->thread_id % p_up->thread_division % p_up->pair_thread_id % p_up->accept_end_flag
843 % p_up->end_flag % p_up->sorry_flag % p_up->sorryserver_switch_flag % p_up->realserver_switch_flag
844 % p_up->last_status % client_endpoint_tcp.address().to_string() % client_endpoint_tcp.port();
845 putLogDebug(100026, formatter.str(), __FILE__, __LINE__ );
847 /*------DEBUG LOG END------*/
849 thread_data_ptr p_down(new session_thread_data_sessionless);
850 /*-------- DEBUG LOG --------*/
851 if (unlikely(LOG_LV_DEBUG == getloglevel()))
853 boost::format formatter("new : address = &(%d), size = %lu.");
854 formatter % static_cast<void*>(p_down.get()) % sizeof(session_thread_data_sessionless);
855 putLogDebug(100027, formatter.str(), __FILE__, __LINE__ );
857 /*------DEBUG LOG END------*/
858 p_down->thread_id = down_thread_id;
859 p_down->thread_division = THREAD_DIVISION_DOWN_STREAM;
860 p_down->pair_thread_id = up_thread_id;
861 p_down->accept_end_flag = ACCEPT_END_FLAG_OFF;
862 p_down->end_flag = END_FLAG_OFF;
863 p_down->sorry_flag = SORRY_FLAG_OFF;
864 p_down->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_OFF;
865 p_down->realserver_switch_flag = REALSERVER_SWITCH_FLAG_OFF;
866 p_down->last_status = INITIALIZE;
867 p_down->client_endpoint_tcp = client_endpoint_tcp;
868 /*-------- DEBUG LOG --------*/
869 if (unlikely(LOG_LV_DEBUG == getloglevel()))
872 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
873 "handle_session_initialize() : session_thread_data_sessionless(down_thread_id) : "
874 "thread_id = %d, thread_division = %d, pair_thread_id = %d, accept_end_flag = %d, end_flag = %d, "
875 "sorry_flag = %d, sorryserver_switch_flag = %d, realserver_switch_flag = %d, "
876 "last_status = %d, client_endpoint_tcp = [%s]:%d.");
877 formatter % p_down->thread_id % p_down->thread_division % p_down->pair_thread_id % p_down->accept_end_flag
878 % p_down->end_flag % p_down->sorry_flag % p_down->sorryserver_switch_flag
879 % p_down->realserver_switch_flag % p_down->last_status % client_endpoint_tcp.address().to_string() % client_endpoint_tcp.port();
880 putLogDebug(100028, formatter.str(), __FILE__, __LINE__ );
882 /*------DEBUG LOG END------*/
884 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
886 session_thread_data_map[up_thread_id] = p_up;
887 session_thread_data_map[down_thread_id] = p_down;
891 catch (const std::bad_alloc&)
893 std::cerr << "protocol_module_sessionless::handle_session_initialize() : exception : Could not allocate memory." << std::endl;
894 boost::format formatter("Could not allocate memory. thread id : %d.");
895 formatter % boost::this_thread::get_id();
896 putLogError(100017, formatter.str(), __FILE__, __LINE__ );
899 catch (const std::exception& ex)
901 std::cerr << "protocol_module_sessionless::handle_session_initialize() : exception : error = " << ex.what() << "." << std::endl;
902 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
903 "handle_session_initialize() : exception : error = %s. thread id : %d.");
904 formatter % ex.what() % boost::this_thread::get_id();
905 putLogError(100018, formatter.str(), __FILE__, __LINE__ );
910 std::cerr << "protocol_module_sessionless::handle_session_initialize() : Unknown exception." << std::endl;
911 boost::format formatter("function : protocol_module_base::check_message_result "
912 "protocol_module_sessionless::handle_session_initialize() : "
913 "Unknown exception. thread id : %d.");
914 formatter % boost::this_thread::get_id();
915 putLogError(100019, formatter.str(), __FILE__, __LINE__ );
920 /*-------- DEBUG LOG --------*/
921 if (unlikely(LOG_LV_DEBUG == getloglevel()))
923 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
924 "handle_session_initialize(const boost::thread::id up_thread_id, "
925 "const boost::thread::id down_thread_id, const boost::asio::ip::tcp::endpoint& client_endpoint_tcp, "
926 "const boost::asio::ip::udp::endpoint& client_endpoint_udp) : return_value = %d. thread id : %d.");
927 formatter % status % boost::this_thread::get_id();
928 putLogDebug(100029, formatter.str(), __FILE__, __LINE__ );
930 /*------DEBUG LOG END------*/
934 //! called from session finalize use in upstream thread.
935 //! @param[in] upstream thread id.
936 //! @param[in] downstream thread id
937 //! @return session use EVENT mode.
938 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_session_finalize(
939 const boost::thread::id up_thread_id, const boost::thread::id down_thread_id)
942 /*-------- DEBUG LOG --------*/
943 if (unlikely(LOG_LV_DEBUG == getloglevel()))
945 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
946 "handle_session_finalize(const boost::thread::id up_thread_id, "
947 "const boost::thread::id down_thread_id) : "
948 "up_thread_id = %d, down_thread_id = %d.");
949 formatter % up_thread_id % down_thread_id;
950 putLogDebug(100030, formatter.str(), __FILE__, __LINE__ );
952 /*------DEBUG LOG END------*/
953 EVENT_TAG status = STOP;
954 thread_data_ptr p_up;
955 thread_data_ptr p_down;
956 session_thread_data_map_it session_thread_data_it;
957 recive_data_map_it recive_data_it;
959 //session thread free
962 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
964 session_thread_data_it = session_thread_data_map.find(up_thread_id);
965 if (session_thread_data_it != session_thread_data_map.end())
967 p_up = session_thread_data_it->second;
968 /*-------- DEBUG LOG --------*/
969 if (unlikely(LOG_LV_DEBUG == getloglevel()))
971 boost::format formatter("delete : address = &(%d).");
972 formatter % static_cast<void*>(p_up.get());
973 putLogDebug(100031, formatter.str(), __FILE__, __LINE__ );
975 /*------DEBUG LOG END------*/
976 session_thread_data_map.erase(up_thread_id);
979 session_thread_data_it = session_thread_data_map.find(down_thread_id);
980 if (session_thread_data_it != session_thread_data_map.end())
982 /*-------- DEBUG LOG --------*/
983 if (unlikely(LOG_LV_DEBUG == getloglevel()))
985 boost::format formatter("delete : address = &(%d).");
986 formatter % static_cast<void*>(p_down.get());
987 putLogDebug(100032, formatter.str(), __FILE__,
990 /*------DEBUG LOG END------*/
991 session_thread_data_map.erase(down_thread_id);
996 catch (const std::exception& ex)
998 std::cerr << "protocol_module_sessionless::handle_session_finalize() : exception : error = " << ex.what() << "." << std::endl;
999 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1000 "handle_session_finalize() : exception : error = %s. thread id : %d.");
1001 formatter % ex.what() % boost::this_thread::get_id();
1002 putLogError(100020, formatter.str(), __FILE__, __LINE__ );
1007 std::cerr << "protocol_module_sessionless::handle_session_finalize() : Unknown exception." << std::endl;
1008 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1009 "handle_session_finalize() : "
1010 "Unknown exception. thread id : %d.");
1011 formatter % boost::this_thread::get_id();
1012 putLogError(100021, formatter.str(), __FILE__, __LINE__ );
1016 /*-------- DEBUG LOG --------*/
1017 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1019 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1020 "handle_session_finalize(const boost::thread::id up_thread_id, "
1021 "const boost::thread::id down_thread_id) : return_value = %d. thread id : %d.");
1022 formatter % status % boost::this_thread::get_id();
1023 putLogDebug(100033, formatter.str(), __FILE__, __LINE__ );
1025 /*------DEBUG LOG END------*/
1029 //! called from after session accept.in client socket use in upstream thread.
1030 //! @param[in] upstream thread id.
1031 //! @return session use EVENT mode.
1032 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_accept(const boost::thread::id thread_id)
1035 /*-------- DEBUG LOG --------*/
1036 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1038 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1039 "handle_accept(const boost::thread::id thread_id) : thread_id = %d.");
1040 formatter % thread_id;
1041 putLogDebug(100034, formatter.str(), __FILE__, __LINE__ );
1043 /*------DEBUG LOG END------*/
1045 EVENT_TAG status = FINALIZE;
1046 thread_data_ptr session_data;
1047 session_thread_data_map_it session_thread_it;
1051 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
1053 session_thread_it = session_thread_data_map.find(thread_id);
1054 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
1056 boost::format formatter("Invalid thread id. thread id : %d.");
1057 formatter % boost::this_thread::get_id();
1058 putLogError(100022, formatter.str(), __FILE__, __LINE__ );
1062 session_data = session_thread_it->second;
1064 //set accept end flag ON
1065 session_data->accept_end_flag = ACCEPT_END_FLAG_ON;
1066 /*-------- DEBUG LOG --------*/
1067 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1069 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1070 "handle_accept(const boost::thread::id thread_id) : ACCEPT_END_FLAG_ON. thread id : %d.");
1071 formatter % boost::this_thread::get_id();
1072 putLogDebug(100035, formatter.str(), __FILE__, __LINE__ );
1074 /*------DEBUG LOG END------*/
1077 if (session_data->sorry_flag == SORRY_FLAG_ON)
1080 status = SORRYSERVER_SELECT;
1086 status = REALSERVER_SELECT;
1091 /*-------- DEBUG LOG --------*/
1092 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1094 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1095 "handle_accept() : catch exception e = %d. thread id : %d.");
1096 formatter % e % boost::this_thread::get_id();
1097 putLogDebug(100036, formatter.str(), __FILE__, __LINE__ );
1100 /*------DEBUG LOG END------*/
1102 catch (const std::exception& ex)
1104 std::cerr << "protocol_module_sessionless::handle_accept() : exception : error = " << ex.what() << "." << std::endl;
1105 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1106 "handle_accept() : exception : error = %s. thread id : %d.");
1107 formatter % ex.what() % boost::this_thread::get_id();
1108 putLogError(100023, formatter.str(), __FILE__, __LINE__ );
1114 std::cerr << "protocol_module_sessionless::handle_accept() : Unknown exception." << std::endl;
1115 boost::format formatter("function : protocol_module_base::EVENT_TAG "
1116 "protocol_module_sessionless::handle_accept() : "
1117 "Unknown exception. thread id : %d.");
1118 formatter % boost::this_thread::get_id();
1119 putLogError(100024, formatter.str(), __FILE__, __LINE__ );
1123 /*-------- DEBUG LOG --------*/
1124 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1126 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1127 "handle_accept(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
1128 formatter % status % boost::this_thread::get_id();
1129 putLogDebug(100037, formatter.str(), __FILE__, __LINE__ );
1131 /*------DEBUG LOG END------*/
1135 //! called from after session recv in client socket. use in upstream thread.
1136 //! @param[in] upstream thread id
1137 //! @param[in] recive buffer refarence.
1138 //! @param[in] recive length
1139 //! @return session use EVENT mode.
1140 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_recv(const boost::thread::id thread_id,
1141 const boost::array<char, MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
1143 /*-------- DEBUG LOG --------*/
1144 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1146 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
1148 dump_memory(recvbuffer.data(), buffer_size, buffer);
1149 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1150 "handle_client_recv(const boost::thread::id thread_id, "
1151 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1152 "const size_t recvlen) : thread_id = %d, recvbuffer = %s, recvlen = %d.");
1153 formatter % thread_id % buffer % recvlen;
1154 putLogDebug(100038, formatter.str(), __FILE__, __LINE__ );
1156 /*------DEBUG LOG END------*/
1158 EVENT_TAG status = FINALIZE;
1159 size_t data_remain_start = 0;
1160 size_t data_remain_size = 0;
1161 size_t request_data_remain_size = 0;
1162 size_t header_offset = 0;
1163 size_t header_offset_len = 0;
1164 size_t content_length_header_offset = 0;
1165 size_t content_length_header_len = 0;
1166 size_t content_len_value = 0;
1168 size_t buffer_size = 0;
1169 const size_t cr_lf_len = strlen("\r\n\r\n");
1170 std::string str_value;
1171 const std::string http_header = "";
1172 const std::string content_header = "Content-Length";
1173 thread_data_ptr session_data;
1174 char* buffer1 = NULL;
1175 char* buffer2 = NULL;
1177 CHECK_RESULT_TAG check_result;
1178 session_thread_data_map_it session_thread_it;
1179 recive_data_map_it recive_data_it;
1182 if (recvlen > recvbuffer.size())
1184 std::cerr << "protocol_module_sessionless::handle_client_recv() : Data size bigger than buffer size." << std::endl;
1185 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
1186 formatter % boost::this_thread::get_id();
1187 putLogError(100025, formatter.str(), __FILE__, __LINE__ );
1188 /*-------- DEBUG LOG --------*/
1189 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1191 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1192 "handle_client_recv(const boost::thread::id thread_id, "
1193 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1194 "const size_t recvlen) : return_value = %d. thread id : %d.");
1195 formatter % FINALIZE % boost::this_thread::get_id();
1196 putLogDebug(100039, formatter.str(), __FILE__, __LINE__ );
1198 /*------DEBUG LOG END------*/
1205 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
1207 session_thread_it = session_thread_data_map.find(thread_id);
1208 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
1210 boost::format formatter("Invalid thread id. thread id : %d.");
1211 formatter % boost::this_thread::get_id();
1212 putLogError(100026, formatter.str(), __FILE__, __LINE__ );
1216 session_data = session_thread_it->second;
1220 if (session_data->end_flag == END_FLAG_ON)
1222 status = CLIENT_RECV;
1227 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
1228 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
1230 boost::format formatter("Invalid endpoint. thread id : %d.");
1231 formatter % boost::this_thread::get_id();
1232 putLogError(100027, formatter.str(), __FILE__, __LINE__ );
1236 recive_data& recv_data = recive_data_it->second;
1238 send_status_it it = recv_data.send_status_list.begin();
1239 send_status_it it_end = recv_data.send_status_list.end();
1242 it = std::find_if(it, it_end, data_send_ok());
1243 if (unlikely(it != it_end))
1245 boost::format formatter("Sending data is not correct. thread id : %d.");
1246 formatter % boost::this_thread::get_id();
1247 putLogError(100028, formatter.str(), __FILE__, __LINE__ );
1252 it = recv_data.send_status_list.begin();
1253 it = std::adjacent_find(it, it_end, data_send_repeated());
1254 if (unlikely(it != it_end))
1256 boost::format formatter("Sending data is not correct. thread id : %d.");
1257 formatter % boost::this_thread::get_id();
1258 putLogError(100029, formatter.str(), __FILE__, __LINE__ );
1262 /*-------- DEBUG LOG --------*/
1263 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1265 std::string datadump;
1266 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
1267 "send_rest_size = %d, send_possible_size = %d, "
1268 "send_offset = %d, unsend_size = %d, edit_division = %d.");
1270 for (it = recv_data.send_status_list.begin();
1271 it != recv_data.send_status_list.end();
1274 formatter % i % it->status % it->send_end_size
1275 % it->send_rest_size % it->send_possible_size
1276 % it->send_offset % it->unsend_size % it->edit_division;
1277 datadump += formatter.str();
1280 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1281 "handle_client_recv() : send status list dump : send status list size = %d.%s");
1283 formatter % recv_data.send_status_list.size() % datadump;
1284 putLogDebug(100040, formatter.str(), __FILE__, __LINE__ );
1286 /*------DEBUG LOG END------*/
1288 it = recv_data.send_status_list.begin();
1289 //get original status info
1290 while (it != it_end)
1292 //item status is SEND_END
1293 if (it->status == SEND_END)
1296 recv_data.send_status_list.erase(it++);
1299 //item status is SEND_CONTINUE
1300 else if (it->status == SEND_CONTINUE)
1302 it->send_offset += it->send_end_size;
1303 data_remain_start = it->send_offset;
1306 //item status is SEND_NG
1309 data_remain_start = it->send_offset;
1310 data_remain_size = it->unsend_size;
1316 /*-------- DEBUG LOG --------*/
1317 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1319 std::string datadump;
1320 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
1321 "send_rest_size = %d, send_possible_size = %d, "
1322 "send_offset = %d, unsend_size = %d, edit_division = %d.");
1324 for (it = recv_data.send_status_list.begin();
1325 it != recv_data.send_status_list.end();
1328 formatter % i % it->status % it->send_end_size
1329 % it->send_rest_size % it->send_possible_size
1330 % it->send_offset % it->unsend_size % it->edit_division;
1331 datadump += formatter.str();
1334 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1335 "handle_client_recv() : send status list dump : send status list size = %d.%s");
1337 formatter % recv_data.send_status_list.size() % datadump;
1338 putLogDebug(100041, formatter.str(), __FILE__, __LINE__ );
1340 /*------DEBUG LOG END------*/
1342 //recive buffer process
1343 //buffer rest size < request size
1344 if (recv_data.recive_buffer_rest_size < recvlen)
1346 //buffer max size < remain size + request size
1347 //buffer is need reallocate
1348 if (recv_data.recive_buffer_max_size < data_remain_size + recvlen)
1350 //the buffer's size that will be allocated is exceed the upper limit value
1351 if (MAX_SESSIONLESS_MODULE_BUFFER_SIZE < data_remain_size + recvlen)
1353 std::cerr << "protocol_module_sessionless::handle_client_recv() : the buffer's size that will be allacted is exceed the upper limit value." << std::endl;
1354 boost::format formatter("The buffer's size that will be allocated is exceed the upper limit value. thread id : %d.");
1355 formatter % boost::this_thread::get_id();
1356 putLogError(100030, formatter.str(), __FILE__, __LINE__ );
1357 /*-------- DEBUG LOG --------*/
1358 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1360 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1361 "handle_client_recv(const boost::thread::id thread_id, "
1362 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1363 "const size_t recvlen) : return_value = %d. thread id : %d.");
1364 formatter % FINALIZE % boost::this_thread::get_id();
1365 putLogDebug(100042, formatter.str(), __FILE__, __LINE__ );
1367 /*------DEBUG LOG END------*/
1371 buffer_size = (data_remain_size + recvlen) > MAX_BUFFER_SIZE ? (data_remain_size + recvlen) : MAX_BUFFER_SIZE;
1372 //recive_buffer1's memory allocate and initialization
1373 buffer1 = new char[buffer_size];
1374 /*-------- DEBUG LOG --------*/
1375 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1377 boost::format formatter("new : address = &(%d), size = %lu.");
1378 formatter % static_cast<void*>(buffer1) % buffer_size;
1379 putLogDebug(100043, formatter.str(), __FILE__, __LINE__ );
1381 /*------DEBUG LOG END------*/
1382 memset(buffer1, 0, buffer_size);
1383 //recive_buffer2's memory allocate and initialization
1384 buffer2 = new char[buffer_size];
1385 /*-------- DEBUG LOG --------*/
1386 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1388 boost::format formatter("new : address = &(%d), size = %lu.");
1389 formatter % static_cast<void*>(buffer2) % buffer_size;
1390 putLogDebug(100044, formatter.str(), __FILE__, __LINE__ );
1392 /*------DEBUG LOG END------*/
1393 memset(buffer2, 0, buffer_size);
1395 /*-------- DEBUG LOG --------*/
1396 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1398 std::string datadump;
1399 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
1400 boost::format formatter(
1401 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1402 "handle_client_recv() : before memcpy (data dump) : "
1403 "data begin = %d, data_size = %d, data = %s");
1404 formatter % data_remain_start % data_remain_size % datadump;
1405 putLogDebug(100045, formatter.str(), __FILE__, __LINE__ );
1407 /*------DEBUG LOG END------*/
1408 //copy data from old buffer to new buffer
1409 memcpy(buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
1410 /*-------- DEBUG LOG --------*/
1411 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1413 std::string datadump;
1414 dump_memory(buffer1, data_remain_size, datadump);
1415 boost::format formatter(
1416 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1417 "handle_client_recv() : after memcpy (data dump) : "
1418 "data begin = 0, data_size = %d, data = %s");
1419 formatter % data_remain_size % datadump;
1420 putLogDebug(100046, formatter.str(), __FILE__, __LINE__ );
1422 /*------DEBUG LOG END------*/
1424 /*-------- DEBUG LOG --------*/
1425 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1427 std::string datadump;
1428 dump_memory(recvbuffer.data(), recvlen, datadump);
1429 boost::format formatter(
1430 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1431 "handle_client_recv() : before memcpy (data dump) : "
1432 "data begin = 0, data_size = %d, data = %s");
1433 formatter % recvlen % datadump;
1434 putLogDebug(100047, formatter.str(), __FILE__, __LINE__ );
1436 /*------DEBUG LOG END------*/
1437 memcpy(buffer1 + data_remain_size, recvbuffer.data(), recvlen);
1438 /*-------- DEBUG LOG --------*/
1439 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1441 std::string datadump;
1442 dump_memory(buffer1 + data_remain_size, recvlen, datadump);
1443 boost::format formatter(
1444 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1445 "handle_client_recv() : after memcpy (data dump) : "
1446 "data begin = %d, data_size = %d, data = %s");
1447 formatter % data_remain_size % recvlen % datadump;
1448 putLogDebug(100048, formatter.str(), __FILE__, __LINE__ );
1450 /*------DEBUG LOG END------*/
1451 //free old buffer1 and old buffer2
1452 if (recv_data.recive_buffer1 != NULL)
1454 /*-------- DEBUG LOG --------*/
1455 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1457 boost::format formatter("delete : address = &(%d).");
1458 formatter % static_cast<void*>(recv_data.recive_buffer1);
1459 putLogDebug(100049, formatter.str(), __FILE__,
1462 /*------DEBUG LOG END------*/
1463 delete[] recv_data.recive_buffer1;
1464 recv_data.recive_buffer1 = NULL;
1467 if (recv_data.recive_buffer2 != NULL)
1469 /*-------- DEBUG LOG --------*/
1470 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1472 boost::format formatter("delete : address = &(%d).");
1473 formatter % static_cast<void*>(recv_data.recive_buffer2);
1474 putLogDebug(100050, formatter.str(), __FILE__,
1477 /*------DEBUG LOG END------*/
1478 delete[] recv_data.recive_buffer2;
1479 recv_data.recive_buffer2 = NULL;
1482 //set new buffer pointer
1483 recv_data.recive_buffer1 = buffer1;
1484 recv_data.recive_buffer2 = buffer2;
1485 recv_data.recive_buffer = recv_data.recive_buffer1;
1486 //set new buffer's max size
1487 recv_data.recive_buffer_max_size = buffer_size;
1489 //buffer's max size >= remain data size + requst size
1490 //buffer isn't need reallocate, but switch
1493 //pointer valid check
1494 if (unlikely(recv_data.recive_buffer1 == NULL || recv_data.recive_buffer2 == NULL))
1496 boost::format formatter("Invalid pointer. thread id : %d.");
1497 formatter % boost::this_thread::get_id();
1498 putLogError(100031, formatter.str(), __FILE__, __LINE__ );
1501 //using buffer is buffer1
1502 if (recv_data.recive_buffer == recv_data.recive_buffer1)
1504 //buffer2 initialization
1505 memset(recv_data.recive_buffer2, 0, recv_data.recive_buffer_max_size);
1506 /*-------- DEBUG LOG --------*/
1507 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1509 std::string datadump;
1510 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
1511 boost::format formatter(
1512 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1513 "handle_client_recv() : before memcpy (data dump) : "
1514 "data begin = %d, data_size = %d, data = %s");
1515 formatter % data_remain_start % data_remain_size % datadump;
1516 putLogDebug(100051, formatter.str(), __FILE__, __LINE__ );
1518 /*------DEBUG LOG END------*/
1519 //copy data from buffer1 to buffer2
1520 memcpy(recv_data.recive_buffer2, recv_data.recive_buffer + data_remain_start, data_remain_size);
1521 /*-------- DEBUG LOG --------*/
1522 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1524 std::string datadump;
1525 dump_memory(recv_data.recive_buffer2, recvlen, datadump);
1526 boost::format formatter(
1527 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1528 "handle_client_recv() : after memcpy (data dump) : "
1529 "data begin = 0, data_size = %d, data = %s");
1530 formatter % recvlen % datadump;
1531 putLogDebug(100052, formatter.str(), __FILE__, __LINE__ );
1533 /*------DEBUG LOG END------*/
1534 /*-------- DEBUG LOG --------*/
1535 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1537 std::string datadump;
1538 dump_memory(recvbuffer.data(), recvlen, datadump);
1539 boost::format formatter(
1540 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1541 "handle_client_recv() : before memcpy (data dump) : "
1542 "data begin = 0, data_size = %d, data = %s");
1543 formatter % recvlen % datadump;
1544 putLogDebug(100053, formatter.str(), __FILE__, __LINE__ );
1546 /*------DEBUG LOG END------*/
1547 memcpy(recv_data.recive_buffer2 + data_remain_size, recvbuffer.data(), recvlen);
1548 /*-------- DEBUG LOG --------*/
1549 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1551 std::string datadump;
1552 dump_memory(recv_data.recive_buffer2 + data_remain_size, recvlen, datadump);
1553 boost::format formatter(
1554 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1555 "handle_client_recv() : after memcpy (data dump) : "
1556 "data begin = %d, data_size = %d, data = %s");
1557 formatter % data_remain_size % recvlen % datadump;
1558 putLogDebug(100054, formatter.str(), __FILE__, __LINE__ );
1560 /*------DEBUG LOG END------*/
1561 //set buffer2 as using buffer
1562 recv_data.recive_buffer = recv_data.recive_buffer2;
1564 //using buffer is buffer2
1567 //buffer1 initializtion
1568 memset(recv_data.recive_buffer1, 0, recv_data.recive_buffer_max_size);
1569 /*-------- DEBUG LOG --------*/
1570 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1572 std::string datadump;
1573 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
1574 boost::format formatter(
1575 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1576 "handle_client_recv() : before memcpy (data dump) : "
1577 "data begin = %d, data_size = %d, data = %s");
1578 formatter % data_remain_start % data_remain_size % datadump;
1579 putLogDebug(100055, formatter.str(), __FILE__, __LINE__ );
1581 /*------DEBUG LOG END------*/
1582 //copy data from buffer2 to buffer1
1583 memcpy(recv_data.recive_buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
1584 /*-------- DEBUG LOG --------*/
1585 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1587 std::string datadump;
1588 dump_memory(recv_data.recive_buffer1, data_remain_size, datadump);
1589 boost::format formatter(
1590 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1591 "handle_client_recv() : after memcpy (data dump) : "
1592 "data begin = 0, data_size = %d, data = %s");
1593 formatter % data_remain_size % datadump;
1594 putLogDebug(100056, formatter.str(), __FILE__, __LINE__ );
1596 /*------DEBUG LOG END------*/
1597 /*-------- DEBUG LOG --------*/
1598 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1600 std::string datadump;
1601 dump_memory(recvbuffer.data(), recvlen, datadump);
1602 boost::format formatter(
1603 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1604 "handle_client_recv() : before memcpy (data dump) : "
1605 "data begin = 0, data_size = %d, data = %s");
1606 formatter % recvlen % datadump;
1607 putLogDebug(100057, formatter.str(), __FILE__, __LINE__ );
1609 /*------DEBUG LOG END------*/
1610 memcpy(recv_data.recive_buffer1 + data_remain_size, recvbuffer.data(), recvlen);
1611 /*-------- DEBUG LOG --------*/
1612 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1614 std::string datadump;
1615 dump_memory(recv_data.recive_buffer1 + data_remain_size, recvlen, datadump);
1616 boost::format formatter(
1617 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1618 "handle_client_recv() : after memcpy (data dump) : "
1619 "data begin = %d, data_size = %d, data = %s");
1620 formatter % data_remain_size % recvlen % datadump;
1621 putLogDebug(100058, formatter.str(), __FILE__, __LINE__ );
1623 /*------DEBUG LOG END------*/
1624 //set buffer1 as using buffer
1625 recv_data.recive_buffer = recv_data.recive_buffer1;
1629 //set buffer's rest size
1630 recv_data.recive_buffer_rest_size = recv_data.recive_buffer_max_size - data_remain_size - recvlen;
1632 //remain_size recalc
1633 data_remain_size += recvlen;
1635 send_status_it it_begin = recv_data.send_status_list.begin();
1636 send_status_it it_end = recv_data.send_status_list.end();
1639 for (; it_begin != it_end; ++it_begin)
1641 it_begin->send_offset -= data_remain_start;
1644 //buffer's rest size >= request size
1647 //pointer valid check
1648 if (unlikely(recv_data.recive_buffer == NULL))
1650 boost::format formatter("Invalid pointer. thread id : %d.");
1651 formatter % boost::this_thread::get_id();
1652 putLogError(100032, formatter.str(), __FILE__, __LINE__ );
1655 /*-------- DEBUG LOG --------*/
1656 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1658 std::string datadump;
1659 dump_memory(recvbuffer.data(), recvlen, datadump);
1660 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1661 "handle_client_recv() : before memcpy (data dump) : "
1662 "data begin = 0, data_size = %d, data = %s");
1663 formatter % recvlen % datadump;
1664 putLogDebug(100059, formatter.str(), __FILE__, __LINE__ );
1666 /*------DEBUG LOG END------*/
1667 //copy data from parameter to using buffer
1668 memcpy(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
1669 recvbuffer.data(), recvlen);
1670 /*-------- DEBUG LOG --------*/
1671 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1673 std::string datadump;
1674 dump_memory(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
1676 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1677 "handle_client_recv() : after memcpy (data dump) : "
1678 "data begin = %d, data_size = %d, data = %s");
1679 formatter % (recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size )
1680 % recvlen % datadump;
1681 putLogDebug(100060, formatter.str(), __FILE__, __LINE__ );
1683 /*------DEBUG LOG END------*/
1684 //buffer's rest size recalc
1685 recv_data.recive_buffer_rest_size -= recvlen;
1686 //remain data size recalc
1687 data_remain_size += recvlen;
1690 it = recv_data.send_status_list.begin();
1691 it_end = recv_data.send_status_list.end();
1693 //set request rest size
1694 request_data_remain_size = recvlen;
1696 //original status process
1697 for (; it != it_end; ++it)
1699 //status is SEND_CONTINUE
1700 if (it->status == SEND_CONTINUE)
1702 //send rest size > request size
1703 if (it->send_rest_size > request_data_remain_size)
1705 //send possible size recalc
1706 it->send_possible_size = request_data_remain_size;
1707 //send rest size recalc
1708 it->send_rest_size -= request_data_remain_size;
1709 //send end size recalc
1710 it->send_end_size = 0;
1711 //request size recalc
1712 request_data_remain_size = 0;
1714 //send rest size <= request size
1717 //send possible size recalc
1718 it->send_possible_size = it->send_rest_size;
1719 //send rest size recalc
1720 request_data_remain_size -= it->send_rest_size;
1721 //send end size recalc
1722 it->send_end_size = 0;
1723 //request size recalc
1724 it->send_rest_size = 0;
1726 //set edit_division flag off
1727 it->edit_division = EDIT_DIVISION_NO_EDIT;
1728 //set status SEND_OK
1729 it->status = SEND_OK;
1732 else if (it->status == SEND_NG)
1735 check_result = check_http_method(recv_data.recive_buffer + it->send_offset, data_remain_size);
1736 /*-------- DEBUG LOG --------*/
1737 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1739 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1740 "handle_client_recv() : call check_http_method : "
1741 "return_value = %d. thread id : %d.");
1742 formatter % check_result % boost::this_thread::get_id();
1743 putLogDebug(100061, formatter.str(), __FILE__, __LINE__ );
1745 /*------DEBUG LOG END------*/
1746 //check http method result is OK
1747 if (check_result == CHECK_OK)
1749 //check http version
1750 check_result = check_http_version(recv_data.recive_buffer + it->send_offset, data_remain_size);
1751 /*-------- DEBUG LOG --------*/
1752 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1754 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1755 "handle_client_recv() : call check_http_version : "
1756 "return_value = %d. thread id : %d.");
1757 formatter % check_result % boost::this_thread::get_id();
1758 putLogDebug(100062, formatter.str(), __FILE__, __LINE__ );
1760 /*------DEBUG LOG END------*/
1762 //check method and version result is OK
1763 if (check_result == CHECK_OK)
1765 //search http header
1766 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size, http_header,
1767 header_offset, header_offset_len);
1768 /*-------- DEBUG LOG --------*/
1769 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1771 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1772 "handle_client_recv() : call find_http_header : "
1773 "return_value = %d. thread id : %d.");
1774 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
1775 putLogDebug(100063, formatter.str(), __FILE__, __LINE__ );
1777 /*------DEBUG LOG END------*/
1778 //search http header result is OK
1781 //search Content_Length header
1782 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size,
1783 content_header, content_length_header_offset, content_length_header_len);
1784 /*-------- DEBUG LOG --------*/
1785 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1787 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1788 "handle_client_recv() : call find_http_header : "
1789 "return_value = %d. thread id : %d.");
1790 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
1791 putLogDebug(100064, formatter.str(), __FILE__, __LINE__ );
1793 /*------DEBUG LOG END------*/
1794 //search Content_Length result is OK
1797 //Get Content_Length header's numeric value
1798 for (pos = 0; recv_data.recive_buffer[it->send_offset + content_length_header_offset + pos] != ':' && pos
1799 < content_length_header_len; ++pos)
1801 if (pos == content_length_header_len)
1803 throw std::string("Content_Length field's value is invalid.");
1808 str_value.assign(recv_data.recive_buffer + it->send_offset + content_length_header_offset + pos,
1809 content_length_header_len - pos);
1811 size_t pos_end = str_value.find_last_of('\r');
1812 if (pos_end != std::string::npos)
1814 str_value = str_value.erase(pos_end);
1817 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos);
1819 str_value = str_value.substr(pos);
1823 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
1825 catch (const boost::bad_lexical_cast& ex)
1827 throw std::string("Content_Length field's value is invalid.");
1830 //send_rest_size recalc
1831 //set whole http header's length + Content_Length's value
1832 it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
1834 //search Content_Length result is NG
1837 //send_rest_size recalc
1838 //set whole http header's length
1839 it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
1841 //set edit_division flag on
1842 it->edit_division = EDIT_DIVISION_EDIT;
1844 //search http header result is NG
1847 //unsend_size recalc
1848 it->unsend_size += request_data_remain_size;
1849 //request data rest size recalc
1850 request_data_remain_size = 0;
1854 //check method and version result is NG
1855 else if (check_result == CHECK_NG)
1857 //set edit_division flag off
1858 it->edit_division = EDIT_DIVISION_NO_EDIT;
1859 //send_rest_size recalc
1860 it->send_rest_size = it->unsend_size + request_data_remain_size;
1862 //check method and version result is CHECK_INPOSSIBLE
1865 //unsend_size recalc
1866 it->unsend_size += request_data_remain_size;
1867 //request data rest size recalc
1868 request_data_remain_size = 0;
1872 //recalc fields value according to send_rest_size and request rest size
1873 if (it->send_rest_size > it->unsend_size + request_data_remain_size)
1875 it->send_possible_size = it->unsend_size + request_data_remain_size;
1876 it->send_rest_size -= (it->unsend_size + request_data_remain_size);
1877 it->send_end_size = 0;
1878 it->unsend_size = 0;
1879 request_data_remain_size = 0;
1883 it->send_possible_size = it->send_rest_size;
1884 request_data_remain_size = it->unsend_size + request_data_remain_size - it->send_rest_size;
1885 it->send_end_size = 0;
1886 it->unsend_size = 0;
1887 it->send_rest_size = 0;
1890 //change status from SEND_NG to SEND_OK
1891 it->status = SEND_OK;
1893 //no request rest data to process
1894 if (request_data_remain_size <= 0)
1899 /*-------- DEBUG LOG --------*/
1900 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1902 std::string datadump;
1903 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
1904 "send_rest_size = %d, send_possible_size = %d, "
1905 "send_offset = %d, unsend_size = %d, edit_division = %d.");
1907 for (it = recv_data.send_status_list.begin();
1908 it != recv_data.send_status_list.end();
1911 formatter % i % it->status % it->send_end_size
1912 % it->send_rest_size % it->send_possible_size
1913 % it->send_offset % it->unsend_size % it->edit_division;
1914 datadump += formatter.str();
1917 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1918 "handle_client_recv() : send status list dump : send status list size = %d.%s");
1920 formatter % recv_data.send_status_list.size() % datadump;
1921 putLogDebug(100065, formatter.str(), __FILE__, __LINE__ );
1923 /*------DEBUG LOG END------*/
1924 //there are still rest data need to process
1925 //new status created and add to status list
1926 while (request_data_remain_size > 0)
1928 //new status created
1929 send_status new_send_state;
1931 new_send_state.edit_division = EDIT_DIVISION_NO_EDIT;
1932 new_send_state.send_end_size = 0;
1933 new_send_state.send_offset = 0;
1934 new_send_state.send_possible_size = 0;
1935 new_send_state.unsend_size = 0;
1936 new_send_state.send_rest_size = 0;
1937 //status initialize to SEND_NG
1938 new_send_state.status = SEND_NG;
1939 //add new status to status_list
1940 recv_data.send_status_list.push_back(new_send_state);
1941 std::list<send_status>::reverse_iterator new_send_it = recv_data.send_status_list.rbegin();
1943 new_send_it->send_offset = recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size
1944 - request_data_remain_size;
1947 check_result = check_http_method(recv_data.recive_buffer + new_send_it->send_offset,
1948 request_data_remain_size);
1949 /*-------- DEBUG LOG --------*/
1950 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1952 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1953 "handle_client_recv() : call check_http_method : "
1954 "return_value = %d. thread id : %d.");
1955 formatter % check_result % boost::this_thread::get_id();
1956 putLogDebug(100066, formatter.str(), __FILE__, __LINE__ );
1958 /*------DEBUG LOG END------*/
1959 //check http method result is OK
1960 if (check_result == CHECK_OK)
1962 //check http version
1963 check_result = check_http_version(recv_data.recive_buffer + new_send_it->send_offset,
1964 request_data_remain_size);
1965 /*-------- DEBUG LOG --------*/
1966 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1968 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1969 "handle_client_recv() : call check_http_version : "
1970 "return_value = %d. thread id : %d.");
1971 formatter % check_result % boost::this_thread::get_id();
1972 putLogDebug(100067, formatter.str(), __FILE__, __LINE__ );
1974 /*------DEBUG LOG END------*/
1976 //check http method and version result is OK
1977 if (check_result == CHECK_OK)
1979 //search whole http header, get whole http header's offset and length
1980 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset, request_data_remain_size,
1981 http_header, header_offset, header_offset_len);
1982 /*-------- DEBUG LOG --------*/
1983 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1985 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1986 "handle_client_recv() : call find_http_header : "
1987 "return_value = %d. thread id : %d.");
1988 formatter % check_result % boost::this_thread::get_id();
1989 putLogDebug(100068, formatter.str(), __FILE__, __LINE__ );
1991 /*------DEBUG LOG END------*/
1992 //searched whole http header
1995 //search ContentLength http header, get ContentLength header's offset and length
1996 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset,
1997 request_data_remain_size, content_header, content_length_header_offset, content_length_header_len);
1998 /*-------- DEBUG LOG --------*/
1999 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2001 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2002 "handle_client_recv() : call find_http_header : "
2003 "return_value = %d. thread id : %d.");
2004 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
2005 putLogDebug(100069, formatter.str(), __FILE__, __LINE__ );
2007 /*------DEBUG LOG END------*/
2009 //searched ContentLength http header
2012 //Get Content_Length header's numeric value
2014 recv_data.recive_buffer[new_send_it->send_offset + content_length_header_offset + pos] != ':'
2015 && pos < content_length_header_len;
2017 if (pos == content_length_header_len)
2019 throw std::string("Content_Length field's value is invalid.");
2024 str_value.assign(recv_data.recive_buffer + new_send_it->send_offset + content_length_header_offset + pos,
2025 content_length_header_len - pos);
2027 size_t pos_end = str_value.find_last_of('\r');
2028 if (pos_end != std::string::npos)
2030 str_value = str_value.erase(pos_end);
2033 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos);
2035 str_value = str_value.substr(pos);
2038 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
2040 catch (const boost::bad_lexical_cast& ex)
2042 throw std::string("Content_Length field's value is invalid.");
2044 //send_rest_size recalc
2045 //set whole http header's + whole http header's length + Content_Length's value
2046 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
2048 //not searched ContentLength http header
2051 //send_rest_size recalc
2052 //set whole http header's + whole http header's length
2053 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
2056 //set edit_division flag on
2057 new_send_it->edit_division = EDIT_DIVISION_EDIT;
2059 //not searched whole http header
2062 new_send_it->unsend_size = request_data_remain_size;
2063 request_data_remain_size = 0;
2067 //check http method or version result is NG
2068 else if (check_result == CHECK_NG)
2070 new_send_it->edit_division = EDIT_DIVISION_NO_EDIT;
2071 new_send_it->send_rest_size = request_data_remain_size;
2074 //check http method or version result is impossible
2077 new_send_it->unsend_size = request_data_remain_size;
2078 request_data_remain_size = 0;
2082 //recalc fields value according to send_rest_size and request rest size
2083 if (new_send_it->send_rest_size > request_data_remain_size)
2085 new_send_it->send_possible_size = request_data_remain_size;
2086 new_send_it->send_rest_size -= request_data_remain_size;
2087 new_send_it->send_end_size = 0;
2088 request_data_remain_size = 0;
2092 new_send_it->send_possible_size = new_send_it->send_rest_size;
2093 request_data_remain_size -= new_send_it->send_rest_size;
2094 new_send_it->send_end_size = 0;
2095 new_send_it->send_rest_size = 0;
2098 //change status from SEND_NG to SEND_OK
2099 new_send_it->status = SEND_OK;
2102 /*-------- DEBUG LOG --------*/
2103 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2105 std::string datadump;
2106 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
2107 "send_rest_size = %d, send_possible_size = %d, "
2108 "send_offset = %d, unsend_size = %d, edit_division = %d.");
2110 for (it = recv_data.send_status_list.begin();
2111 it != recv_data.send_status_list.end();
2114 formatter % i % it->status % it->send_end_size
2115 % it->send_rest_size % it->send_possible_size
2116 % it->send_offset % it->unsend_size % it->edit_division;
2117 datadump += formatter.str();
2120 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2121 "handle_client_recv() : send status list dump : send status list size = %d.%s");
2123 formatter % recv_data.send_status_list.size() % datadump;
2124 putLogDebug(100070, formatter.str(), __FILE__, __LINE__ );
2126 /*------DEBUG LOG END------*/
2127 //search for send_possible item in status list
2128 send_status_it it_find = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
2129 data_send_possible());
2130 //the data that can be sent possible is exist
2131 if (it_find != recv_data.send_status_list.end())
2134 if (session_data->sorry_flag == SORRY_FLAG_ON)
2136 status = SORRYSERVER_CONNECT;
2141 status = REALSERVER_CONNECT;
2144 //the data that can be sent possible is not exist
2147 status = CLIENT_RECV;
2153 /*-------- DEBUG LOG --------*/
2154 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2156 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2157 "handle_client_recv() : catch exception e = %d. thread id : %d.");
2158 formatter % e % boost::this_thread::get_id();
2159 putLogDebug(100071, formatter.str(), __FILE__, __LINE__ );
2161 /*------DEBUG LOG END------*/
2164 catch (const std::string& ex)
2166 std::cerr << "protocol_module_sessionless::handle_client_recv() : exception : " << ex << std::endl;
2167 boost::format formatter("protocol_module_sessionless::handle_client_recv() : exception : %s. thread id : %d.");
2168 formatter % ex.c_str() % boost::this_thread::get_id();
2169 putLogError(100033, formatter.str(), __FILE__, __LINE__ );
2172 catch (const std::bad_alloc&)
2174 std::cerr << "protocol_module_sessionless::handle_client_recv() : exception : Could not allocate memory." << std::endl;
2175 boost::format formatter("Could not allocate memory. thread id : %d.");
2176 formatter % boost::this_thread::get_id();
2177 putLogError(100034, formatter.str(), __FILE__, __LINE__ );
2180 catch (const std::exception& ex)
2182 std::cerr << "protocol_module_sessionless::handle_client_recv() : exception : error = " << ex.what() << "." << std::endl;
2183 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2184 "handle_client_recv() : exception : error = %s. thread id : %d.");
2185 formatter % ex.what() % boost::this_thread::get_id();
2186 putLogError(100035, formatter.str(), __FILE__, __LINE__ );
2192 std::cerr << "protocol_module_sessionless::handle_client_recv() : Unknown exception." << std::endl;
2193 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2194 "protocol_module_sessionless::handle_client_recv() : "
2195 "Unknown exception. thread id : %d.");
2196 formatter % boost::this_thread::get_id();
2197 putLogError(100036, formatter.str(), __FILE__, __LINE__ );
2201 /*-------- DEBUG LOG --------*/
2202 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2204 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2205 "handle_client_recv(const boost::thread::id thread_id, "
2206 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
2207 "const size_t recvlen) : return_value = %d. thread id : %d.");
2208 formatter % status % boost::this_thread::get_id();
2209 putLogDebug(100072, formatter.str(), __FILE__, __LINE__ );
2211 /*------DEBUG LOG END------*/
2216 //! called from after realserver select.use in upstream thread.
2217 //! @param[in] upstream thread id
2218 //! @param[out] realserver TCP endpoint
2219 //! @return session use EVENT mode.
2220 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_select(
2221 const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint & rs_endpoint)
2223 /*-------- DEBUG LOG --------*/
2224 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2226 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2227 "handle_realserver_select(const boost::thread::id thread_id, "
2228 "boost::asio::ip::tcp::endpoint & rs_endpoint) : "
2229 "thread_id = %d, rs_endpoint = [%s]:%d.");
2230 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
2231 putLogDebug(100073, formatter.str(), __FILE__, __LINE__ );
2233 /*------DEBUG LOG END------*/
2234 EVENT_TAG status = FINALIZE;
2235 boost::asio::ip::tcp::endpoint tmp_endpoint;
2236 thread_data_ptr session_data;
2237 session_thread_data_map_it session_thread_it;
2238 session_thread_data_map_it session_thread_it_end;
2239 recive_data_map_it recive_data_it;
2241 if (schedule_tcp.empty())
2243 std::cerr << "protocol_module_sessionless::handle_realserver_select() : Schedule_tcp function is empty." << std::endl;
2244 boost::format formatter("Schedule_tcp function is empty. thread id : %d.");
2245 formatter % boost::this_thread::get_id();
2246 putLogError(100037, formatter.str(), __FILE__, __LINE__ );
2247 /*-------- DEBUG LOG --------*/
2248 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2250 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2251 "handle_realserver_select(const boost::thread::id thread_id, "
2252 "boost::asio::ip::tcp::endpoint & rs_endpoint)"
2253 " : return_value = %d. thread id : %d.");
2254 formatter % FINALIZE % boost::this_thread::get_id();
2255 putLogDebug(100074, formatter.str(), __FILE__, __LINE__ );
2257 /*------DEBUG LOG END------*/
2264 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
2266 session_thread_it = session_thread_data_map.find(thread_id);
2267 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2269 boost::format formatter("Invalid thread id. thread id : %d.");
2270 formatter % boost::this_thread::get_id();
2271 putLogError(100038, formatter.str(), __FILE__, __LINE__ );
2275 session_data = session_thread_it->second;
2278 //call schedule_module's schedule function, get realserver endpoint
2279 schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, rs_endpoint);
2280 /*-------- DEBUG LOG --------*/
2281 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2283 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2284 "handle_realserver_select() : call schedule_tcp : "
2285 "rs_endpoint = [%s]:%d. thread id : %d.");
2286 formatter % rs_endpoint.address().to_string() % rs_endpoint.port() % boost::this_thread::get_id();
2287 putLogDebug(100075, formatter.str(), __FILE__, __LINE__ );
2289 /*------DEBUG LOG END------*/
2292 if (rs_endpoint != tmp_endpoint)
2295 session_data->target_endpoint = rs_endpoint;
2297 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
2298 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
2300 boost::format formatter("Invalid endpoint. thread id : %d.");
2301 formatter % boost::this_thread::get_id();
2302 putLogError(100039, formatter.str(), __FILE__, __LINE__ );
2305 recive_data& recv_data = recive_data_it->second;
2307 send_status_it it = recv_data.send_status_list.begin();
2308 send_status_it it_end = recv_data.send_status_list.end();
2310 it = find_if(it, it_end, data_send_possible());
2313 status = REALSERVER_CONNECT;
2317 status = CLIENT_RECV;
2323 session_data->end_flag = END_FLAG_ON;
2324 /*-------- DEBUG LOG --------*/
2325 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2327 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2328 "handle_realserver_select() : END_FLAG_ON. thread id : %d.");
2329 formatter % boost::this_thread::get_id();
2330 putLogDebug(100076, formatter.str(), __FILE__, __LINE__ );
2332 /*------DEBUG LOG END------*/
2333 status = CLIENT_DISCONNECT;
2338 /*-------- DEBUG LOG --------*/
2339 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2341 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2342 "handle_realserver_select() : catch exception e = %d. thread id : %d.");
2343 formatter % e % boost::this_thread::get_id();
2344 putLogDebug(100077, formatter.str(), __FILE__, __LINE__ );
2347 /*------DEBUG LOG END------*/
2349 catch (const std::exception& ex)
2351 std::cerr << "protocol_module_sessionless::handle_realserver_select() : exception : error = " << ex.what() << "." << std::endl;
2352 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2353 "handle_realserver_select() : exception : error = %s. thread id : %d.");
2354 formatter % ex.what() % boost::this_thread::get_id();
2355 putLogError(100040, formatter.str(), __FILE__, __LINE__ );
2360 std::cerr << "protocol_module_sessionless::handle_realserver_select() : Unknown exception." << std::endl;
2361 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2362 "protocol_module_sessionless::handle_realserver_select() : "
2363 "Unknown exception. thread id : %d.");
2364 formatter % boost::this_thread::get_id();
2365 putLogError(100041, formatter.str(), __FILE__, __LINE__ );
2369 /*-------- DEBUG LOG --------*/
2370 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2372 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2373 "handle_realserver_select(const boost::thread::id thread_id, "
2374 "boost::asio::ip::tcp::endpoint & rs_endpoint)"
2375 " : return_value = %d. thread id : %d.");
2376 formatter % status % boost::this_thread::get_id();
2377 putLogDebug(100078, formatter.str(), __FILE__, __LINE__ );
2379 /*------DEBUG LOG END------*/
2384 //! called from after realserver select
2385 //! @param[in] upstream thread id
2386 //! @param[out] realserver UDP endpoint
2387 //! @param[out] sendbuffer reference
2388 //! @param[out] send data length
2389 //! @return session use EVENT mode.
2390 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_select(
2391 const boost::thread::id thread_id, boost::asio::ip::udp::endpoint& rs_endpoint, boost::array<char,
2392 MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
2394 /*-------- DEBUG LOG --------*/
2395 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2397 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2398 "handle_realserver_select(const boost::thread::id thread_id, "
2399 "boost::asio::ip::udp::endpoint& rs_endpoint, boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
2400 "size_t& datalen) : "
2401 "return_value = %d. thread id : %d.");
2402 formatter % STOP % boost::this_thread::get_id();
2403 putLogDebug(100079, formatter.str(), __FILE__, __LINE__ );
2405 /*------DEBUG LOG END------*/
2408 //! called from after realserver connect
2409 //! @param[in] upstream thread id
2410 //! @param[out] sendbuffer reference
2411 //! @param[out] send data length
2412 //! @return session use EVENT mode.
2413 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_connect(
2414 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
2416 /*-------- DEBUG LOG --------*/
2417 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2419 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2420 "handle_realserver_connect(const boost::thread::id thread_id, "
2421 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
2423 formatter % thread_id;
2424 putLogDebug(100080, formatter.str(), __FILE__, __LINE__ );
2426 /*------DEBUG LOG END------*/
2428 EVENT_TAG status = FINALIZE;
2430 size_t header_offset = 0;
2431 size_t header_offset_len = 0;
2432 size_t send_buffer_remian_size = 0;
2433 size_t copy_size = 0;
2434 const int send_buffer_end_size = sendbuffer.max_size();
2435 const std::string http_header = "";
2436 const std::string str_forword_for = "X-Forwarded-For";
2437 thread_data_ptr session_data;
2438 session_thread_data_map_it session_thread_it;
2439 recive_data_map_it recive_data_it;
2444 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
2447 session_thread_it = session_thread_data_map.find(thread_id);
2448 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2450 boost::format formatter("Invalid thread id. thread id : %d.");
2451 formatter % boost::this_thread::get_id();
2452 putLogError(100042, formatter.str(), __FILE__, __LINE__ );
2456 session_data = session_thread_it->second;
2460 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
2461 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
2463 boost::format formatter("Invalid endpoint. thread id : %d.");
2464 formatter % boost::this_thread::get_id();
2465 putLogError(100043, formatter.str(), __FILE__, __LINE__ );
2469 //recive_buffer pointer check
2470 recive_data& recv_data = recive_data_it->second;
2471 if (unlikely(recv_data.recive_buffer == NULL))
2473 boost::format formatter("Invalid pointer. thread id : %d.");
2474 formatter % boost::this_thread::get_id();
2475 putLogError(100044, formatter.str(), __FILE__, __LINE__ );
2480 send_status_it it = recv_data.send_status_list.begin();
2481 send_status_it it_end = recv_data.send_status_list.end();
2482 it = find_if(it, it_end, data_send_possible());
2483 if (unlikely(it == it_end))
2485 boost::format formatter("Sending possible data is not existed. thread id : %d.");
2486 formatter % boost::this_thread::get_id();
2487 putLogError(100045, formatter.str(), __FILE__, __LINE__ );
2491 //send buffer rest size initialization
2492 send_buffer_remian_size = send_buffer_end_size;
2494 //edit_division flag on
2495 if (it->edit_division == EDIT_DIVISION_EDIT && forwarded_for == FORWARDED_FOR_ON)
2497 //edit list is empty
2498 if (it->edit_data_list.empty())
2502 edata.data_size = 0;
2503 edata.insert_posission = 0;
2504 edata.replace_size = 0;
2505 //search X-Forwarded-For header
2506 ret = find_http_header(recv_data.recive_buffer + it->send_offset, it->send_possible_size,
2507 str_forword_for, header_offset, header_offset_len);
2508 /*-------- DEBUG LOG --------*/
2509 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2511 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2512 "handle_realserver_connect() : call find_http_header : "
2513 "return_value = %d. thread id : %d.");
2514 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
2515 putLogDebug(100081, formatter.str(), __FILE__, __LINE__ );
2517 /*------DEBUG LOG END------*/
2518 //search http header result is OK
2521 //edit X-Forwarded-For header, set it to edata.data
2522 edata.data.assign(recv_data.recive_buffer + it->send_offset + header_offset, header_offset_len);
2524 edata.data += session_data->client_endpoint_tcp.address().to_string();
2525 //save new X-Forwarded-For header offset
2526 edata.insert_posission = header_offset;
2527 //save new X-Forwarded-For header length
2528 edata.data_size = edata.data.size();
2529 //save old X-Forwarded-For header length
2530 edata.replace_size = header_offset_len;
2532 //search http header result is NG
2535 //search whole http header, get whole http header's offset and length
2536 ret = find_http_header(recv_data.recive_buffer + it->send_offset, it->send_possible_size, "",
2537 header_offset, header_offset_len);
2538 /*-------- DEBUG LOG --------*/
2539 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2541 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2542 "handle_realserver_connect() : call find_http_header : "
2543 "return_value = %d. thread id : %d.");
2544 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
2545 putLogDebug(100082, formatter.str(), __FILE__, __LINE__ );
2547 /*------DEBUG LOG END------*/
2550 boost::format formatter("find_http_header() function failure. thread id : %d.");
2551 formatter % boost::this_thread::get_id();
2552 putLogError(100046, formatter.str(), __FILE__, __LINE__ );
2553 /*-------- DEBUG LOG --------*/
2554 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2556 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2557 "handle_realserver_connect(const boost::thread::id thread_id, "
2558 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
2559 "size_t& datalen) : return_value = %d. thread id : %d.");
2560 formatter % FINALIZE % boost::this_thread::get_id();
2561 putLogDebug(100083, formatter.str(), __FILE__, __LINE__ );
2563 /*------DEBUG LOG END------*/
2566 //create X-Forwarded-For header, put it to edata.data
2567 edata.data = str_forword_for;
2569 edata.data += session_data->client_endpoint_tcp.address().to_string();
2570 edata.data += "\r\n";
2571 //save new X-Forwarded-For header offset
2572 edata.insert_posission = header_offset;
2573 //save new X-Forwarded-For header length
2574 edata.data_size = edata.data.size();
2575 //save old X-Forwarded-For header length
2576 edata.replace_size = 0;
2579 //add to edit_data_list
2580 it->edit_data_list.push_back(edata);
2583 /*-------- DEBUG LOG --------*/
2584 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2586 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2587 "handle_realserver_connect() : Copy data loop start. thread id : %d.");
2588 formatter % boost::this_thread::get_id();
2589 putLogDebug(100084, formatter.str(), __FILE__, __LINE__ );
2591 /*------DEBUG LOG END------*/
2594 //edit_data_list is empty
2595 if (it->edit_data_list.empty())
2597 //set edit_division flag on
2598 it->edit_division = EDIT_DIVISION_NO_EDIT;
2600 if (send_buffer_remian_size > 0 && it->send_possible_size > 0)
2602 //send_buffer_remian_size is larger
2603 if (send_buffer_remian_size >= it->send_possible_size)
2605 copy_size = it->send_possible_size;
2606 /*-------- DEBUG LOG --------*/
2607 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2609 std::string datadump;
2610 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
2611 it->send_possible_size, datadump);
2612 boost::format formatter(
2613 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2614 "handle_realserver_connect() : before memcpy (data dump) : "
2615 "data begin = %d, data_size = %d, data = %s");
2616 formatter % (it->send_offset + it->send_end_size)
2617 % copy_size % datadump;
2618 putLogDebug(100085, formatter.str(), __FILE__, __LINE__ );
2620 /*------DEBUG LOG END------*/
2621 //copy data from recive_buffer to sendbuffer by sending_possible size
2622 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2623 recv_data.recive_buffer + it->send_offset + it->send_end_size,
2624 it->send_possible_size);
2625 /*-------- DEBUG LOG --------*/
2626 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2628 std::string datadump;
2629 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2630 it->send_possible_size, datadump);
2632 boost::format formatter(
2633 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2634 "handle_realserver_connect() : after memcpy (data dump) : "
2635 "data begin = %d, data_size = %d, data = %s");
2636 formatter % (send_buffer_end_size - send_buffer_remian_size)
2637 % copy_size % datadump;
2638 putLogDebug(100086, formatter.str(), __FILE__, __LINE__ );
2640 /*------DEBUG LOG END------*/
2642 it->send_end_size += copy_size;
2643 it->send_possible_size = 0;
2644 send_buffer_remian_size -= copy_size;
2646 //send_possible_size is larger
2649 copy_size = send_buffer_remian_size;
2650 /*-------- DEBUG LOG --------*/
2651 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2653 std::string datadump;
2654 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
2655 copy_size, datadump);
2657 boost::format formatter(
2658 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2659 "handle_realserver_connect() : before memcpy (data dump) : "
2660 "data begin = %d, data_size = %d, data = %s");
2661 formatter % (it->send_offset + it->send_end_size)
2662 % copy_size % datadump;
2663 putLogDebug(100087, formatter.str(), __FILE__, __LINE__ );
2665 /*------DEBUG LOG END------*/
2666 //copy data from recive_buffer to sendbuffer by send buffer rest size
2667 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2668 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
2669 /*-------- DEBUG LOG --------*/
2670 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2672 std::string datadump;
2673 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2674 copy_size, datadump);
2676 boost::format formatter(
2677 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2678 "handle_realserver_connect() : after memcpy (data dump) : "
2679 "data begin = %d, data_size = %d, data = %s");
2680 formatter % (send_buffer_end_size - send_buffer_remian_size)
2681 % copy_size % datadump;
2682 putLogDebug(100088, formatter.str(), __FILE__, __LINE__ );
2684 /*------DEBUG LOG END------*/
2685 it->send_end_size += copy_size;
2686 it->send_possible_size -= copy_size;
2687 send_buffer_remian_size = 0;
2692 //edit_data_list is not empty
2695 //find the item in the list which has mininum insert_posission
2696 std::list<edit_data>::iterator edit_min = std::min_element(it->edit_data_list.begin(),
2697 it->edit_data_list.end());
2698 //send_buffer_remian_size is larger than data that before X-Forwarded-For
2699 if (send_buffer_remian_size >= edit_min->insert_posission - it->send_end_size)
2701 //copy data before X-Forwarded-For
2702 copy_size = edit_min->insert_posission - it->send_end_size;
2703 /*-------- DEBUG LOG --------*/
2704 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2706 std::string datadump;
2707 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
2708 copy_size, datadump);
2710 boost::format formatter(
2711 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2712 "handle_realserver_connect() : before memcpy (data dump) : "
2713 "data begin = %d, data_size = %d, data = %s");
2714 formatter % (it->send_offset + it->send_end_size)
2715 % copy_size % datadump;
2716 putLogDebug(100089, formatter.str(), __FILE__, __LINE__ );
2718 /*------DEBUG LOG END------*/
2719 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2720 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
2721 /*-------- DEBUG LOG --------*/
2722 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2724 std::string datadump;
2725 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2726 copy_size, datadump);
2727 boost::format formatter(
2728 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2729 "handle_realserver_connect() : after memcpy (data dump) : "
2730 "data begin = %d, data_size = %d, data = %s");
2731 formatter % (send_buffer_end_size - send_buffer_remian_size)
2732 % copy_size % datadump;
2733 putLogDebug(100090, formatter.str(), __FILE__, __LINE__ );
2735 /*------DEBUG LOG END------*/
2736 it->send_end_size += copy_size;
2737 it->send_possible_size -= copy_size;
2738 send_buffer_remian_size -= copy_size;
2740 //there is remain buffer for copy X-Forwarded-For
2741 if (send_buffer_remian_size >= edit_min->data_size)
2743 /*-------- DEBUG LOG --------*/
2744 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2746 std::string datadump;
2747 dump_memory(edit_min->data.c_str(),
2748 edit_min->data_size, datadump);
2750 boost::format formatter(
2751 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2752 "handle_realserver_connect() : before memcpy (data dump) : "
2753 "data begin = 0, data_size = %d, data = %s");
2754 formatter % edit_min->data_size % datadump;
2755 putLogDebug(100091, formatter.str(), __FILE__, __LINE__ );
2757 /*------DEBUG LOG END------*/
2758 //copy X-Forwarded-For
2759 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2760 edit_min->data.c_str(), edit_min->data_size);
2761 /*-------- DEBUG LOG --------*/
2762 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2764 std::string datadump;
2765 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2766 edit_min->data_size, datadump);
2767 boost::format formatter(
2768 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2769 "handle_realserver_connect() : after memcpy (data dump) : "
2770 "data begin = %d, data_size = %d, data = %s");
2771 formatter % (send_buffer_end_size - send_buffer_remian_size)
2772 % edit_min->data_size % datadump;
2773 putLogDebug(100092, formatter.str(), __FILE__, __LINE__ );
2775 /*------DEBUG LOG END------*/
2776 it->send_end_size += edit_min->replace_size;
2777 it->send_possible_size -= edit_min->replace_size;
2778 send_buffer_remian_size -= edit_min->data_size;
2779 it->edit_data_list.erase(edit_min);
2787 //data that before X-Forwarded-For is larger than send_buffer_remian_size
2790 copy_size = send_buffer_remian_size;
2791 /*-------- DEBUG LOG --------*/
2792 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2794 std::string datadump;
2795 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
2796 copy_size, datadump);
2798 boost::format formatter(
2799 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2800 "handle_realserver_connect() : before memcpy (data dump) : "
2801 "data begin = %d, data_size = %d, data = %s");
2802 formatter % (it->send_offset + it->send_end_size)
2803 % copy_size % datadump;
2804 putLogDebug(100093, formatter.str(), __FILE__, __LINE__ );
2806 /*------DEBUG LOG END------*/
2807 //copy data as large as possible
2808 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2809 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
2810 /*-------- DEBUG LOG --------*/
2811 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2813 std::string datadump;
2814 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2815 copy_size, datadump);
2817 boost::format formatter(
2818 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2819 "handle_realserver_connect() : after memcpy (data dump) : "
2820 "data begin = %d, data_size = %d, data = %s");
2821 formatter % (send_buffer_end_size - send_buffer_remian_size)
2822 % copy_size % datadump;
2823 putLogDebug(100094, formatter.str(), __FILE__, __LINE__ );
2825 /*------DEBUG LOG END------*/
2827 it->send_end_size += copy_size;
2828 it->send_possible_size -= copy_size;
2829 send_buffer_remian_size -= copy_size;
2834 /*-------- DEBUG LOG --------*/
2835 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2837 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2838 "handle_realserver_connect() : Copy data loop end. thread id : %d.");
2839 formatter % boost::this_thread::get_id();
2840 putLogDebug(100095, formatter.str(), __FILE__, __LINE__ );
2842 /*------DEBUG LOG END------*/
2844 //edit_division flag is off
2847 //copy data as large as possible
2848 //send_possible_size is larger
2849 if (send_buffer_remian_size >= it->send_possible_size)
2851 copy_size = it->send_possible_size;
2852 /*-------- DEBUG LOG --------*/
2853 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2855 std::string datadump;
2856 dump_memory(recv_data.recive_buffer + it->send_offset,
2857 copy_size, datadump);
2858 boost::format formatter(
2859 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2860 "handle_realserver_connect() : before memcpy (data dump) : "
2861 "data begin = %d, data_size = %d, data = %s");
2862 formatter % it->send_offset
2863 % copy_size % datadump;
2864 putLogDebug(100096, formatter.str(), __FILE__, __LINE__ );
2866 /*------DEBUG LOG END------*/
2867 //copy data by send_possible size
2868 memcpy(sendbuffer.data(), recv_data.recive_buffer + it->send_offset, copy_size);
2869 /*-------- DEBUG LOG --------*/
2870 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2872 std::string datadump;
2873 dump_memory(sendbuffer.data(), copy_size, datadump);
2874 boost::format formatter(
2875 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2876 "handle_realserver_connect() : after memcpy (data dump) : "
2877 "data begin = 0, data_size = %d, data = %s");
2878 formatter % copy_size % datadump;
2879 putLogDebug(100097, formatter.str(), __FILE__, __LINE__ );
2881 /*------DEBUG LOG END------*/
2882 it->send_end_size = copy_size;
2883 it->send_possible_size = 0;
2884 send_buffer_remian_size -= copy_size;
2886 //buffer rest size is larger
2889 /*-------- DEBUG LOG --------*/
2890 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2892 std::string datadump;
2893 dump_memory(recv_data.recive_buffer + it->send_offset, send_buffer_remian_size, datadump);
2895 boost::format formatter(
2896 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2897 "handle_realserver_connect() : before memcpy (data dump) : "
2898 "data begin = %d, data_size = %d, data = %s");
2899 formatter % it->send_offset
2900 % send_buffer_remian_size % datadump;
2901 putLogDebug(100098, formatter.str(), __FILE__, __LINE__ );
2903 /*------DEBUG LOG END------*/
2904 //copy data by buffer rest size
2905 memcpy(sendbuffer.data(), recv_data.recive_buffer + it->send_offset, send_buffer_remian_size);
2906 /*-------- DEBUG LOG --------*/
2907 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2909 std::string datadump;
2910 dump_memory(sendbuffer.data(), send_buffer_remian_size, datadump);
2911 boost::format formatter(
2912 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2913 "handle_realserver_connect() : after memcpy (data dump) : "
2914 "data begin = 0, data_size = %d, data = %s");
2915 formatter % send_buffer_remian_size % datadump;
2916 putLogDebug(100099, formatter.str(), __FILE__, __LINE__ );
2918 /*------DEBUG LOG END------*/
2919 it->send_end_size = send_buffer_remian_size;
2920 it->send_possible_size -= send_buffer_remian_size;
2921 send_buffer_remian_size = 0;
2925 //set copyed data length
2926 datalen = send_buffer_end_size - send_buffer_remian_size;
2927 status = REALSERVER_SEND;
2931 /*-------- DEBUG LOG --------*/
2932 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2934 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2935 "handle_realserver_connect() : catch exception e = %d. thread id : %d.");
2936 formatter % e % boost::this_thread::get_id();
2937 putLogDebug(100100, formatter.str(), __FILE__, __LINE__ );
2940 /*------DEBUG LOG END------*/
2942 catch (const std::exception& ex)
2944 std::cerr << "protocol_module_sessionless::handle_realserver_connect() : exception : error = " << ex.what() << "." << std::endl;
2945 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2946 "handle_realserver_connect() : exception : error = %s. thread id : %d.");
2947 formatter % ex.what() % boost::this_thread::get_id();
2948 putLogError(100047, formatter.str(), __FILE__, __LINE__ );
2953 std::cerr << "protocol_module_sessionless::handle_realserver_connect() : Unknown exception." << std::endl;
2954 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2955 "handle_realserver_connect() : Unknown exception. thread id : %d.");
2956 formatter % boost::this_thread::get_id();
2957 putLogError(100048, formatter.str(), __FILE__, __LINE__ );
2961 /*-------- DEBUG LOG --------*/
2962 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2964 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2965 "handle_realserver_connect(const boost::thread::id thread_id, "
2966 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
2967 "size_t& datalen) : return_value = %d. thread id : %d.");
2968 formatter % status % boost::this_thread::get_id();
2969 putLogDebug(100101, formatter.str(), __FILE__, __LINE__ );
2971 /*------DEBUG LOG END------*/
2976 //! called from after realserver connection fail
2977 //! @param[in] upstream thread id
2978 //! @param[in] fail realserver endpoint reference
2979 //! @return session use EVENT mode.
2980 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_connection_fail(
2981 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint)
2983 /*-------- DEBUG LOG --------*/
2984 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2986 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2987 "handle_realserver_connection_fail(const boost::thread::id thread_id, "
2988 "const boost::asio::ip::tcp::endpoint & rs_endpoint) : "
2989 "thread_id = %d, rs_endpoint = [%s]:%d.");
2990 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
2991 putLogDebug(100102, formatter.str(), __FILE__, __LINE__ );
2993 /*------DEBUG LOG END------*/
2995 EVENT_TAG status = FINALIZE;
2996 thread_data_ptr session_data;
2997 session_thread_data_map_it session_thread_it;
3001 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
3003 session_thread_it = session_thread_data_map.find(thread_id);
3004 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3006 boost::format formatter("Invalid thread id. thread id : %d.");
3007 formatter % boost::this_thread::get_id();
3008 putLogError(100049, formatter.str(), __FILE__, __LINE__ );
3012 session_data = session_thread_it->second;
3015 session_data->end_flag = END_FLAG_ON;
3016 /*-------- DEBUG LOG --------*/
3017 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3019 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3020 "handle_realserver_connection_fail() : END_FLAG_ON. thread id : %d.");
3021 formatter % boost::this_thread::get_id();
3022 putLogDebug(100103, formatter.str(), __FILE__, __LINE__ );
3024 /*------DEBUG LOG END------*/
3025 status = CLIENT_DISCONNECT;
3029 /*-------- DEBUG LOG --------*/
3030 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3032 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3033 "handle_realserver_connection_fail() : catch exception e = %d. thread id : %d.");
3034 formatter % e % boost::this_thread::get_id();
3035 putLogDebug(100104, formatter.str(), __FILE__, __LINE__ );
3038 /*------DEBUG LOG END------*/
3040 catch (std::exception& ex)
3042 std::cerr << "protocol_module_sessionless::handle_realserver_connection_fail() : exception : error = " << ex.what() << "." << std::endl;
3043 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3044 "handle_realserver_connection_fail() : exception : error = %s. thread id : %d.");
3045 formatter % ex.what() % boost::this_thread::get_id();
3046 putLogError(100050, formatter.str(), __FILE__, __LINE__ );
3051 std::cerr << "protocol_module_sessionless::handle_realserver_connection_fail() : Unknown exception." << std::endl;
3052 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3053 "handle_realserver_connection_fail() : Unknown exception. thread id : %d.");
3054 formatter % boost::this_thread::get_id();
3055 putLogError(100051, formatter.str(), __FILE__, __LINE__ );
3059 /*-------- DEBUG LOG --------*/
3060 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3062 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3063 "handle_realserver_connection_fail(const boost::thread::id thread_id, "
3064 "const boost::asio::ip::tcp::endpoint & rs_endpoint) : return_value = %d. thread id : %d.");
3065 formatter % status % boost::this_thread::get_id();
3066 putLogDebug(100105, formatter.str(), __FILE__, __LINE__ );
3068 /*------DEBUG LOG END------*/
3071 //! called from after realserver send.
3072 //! @param[in] upstream thread id
3073 //! @return session use EVENT mode.
3074 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_send(
3075 const boost::thread::id thread_id)
3077 /*-------- DEBUG LOG --------*/
3078 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3080 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3081 "handle_realserver_send(const boost::thread::id thread_id) : "
3083 formatter % thread_id;
3084 putLogDebug(100106, formatter.str(), __FILE__, __LINE__ );
3086 /*------DEBUG LOG END------*/
3087 EVENT_TAG status = FINALIZE;
3088 thread_data_ptr session_data;
3089 session_thread_data_map_it session_thread_it;
3090 recive_data_map_it recive_data_it;
3095 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
3098 session_thread_it = session_thread_data_map.find(thread_id);
3099 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3101 boost::format formatter("Invalid thread id. thread id : %d.");
3102 formatter % boost::this_thread::get_id();
3103 putLogError(100052, formatter.str(), __FILE__, __LINE__ );
3107 session_data = session_thread_it->second;
3111 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
3112 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
3114 boost::format formatter("Invalid endpoint. thread id : %d.");
3115 formatter % boost::this_thread::get_id();
3116 putLogError(100053, formatter.str(), __FILE__, __LINE__ );
3120 recive_data& recv_data = recive_data_it->second;
3122 send_status_it it = recv_data.send_status_list.begin();
3123 send_status_it it_end = recv_data.send_status_list.end();
3126 it = std::adjacent_find(it, it_end, data_send_list_incorrect());
3127 if (unlikely(it != it_end))
3129 boost::format formatter("Sending possible data is invalid. thread id : %d.");
3130 formatter % boost::this_thread::get_id();
3131 putLogError(100054, formatter.str(), __FILE__, __LINE__ );
3136 it = recv_data.send_status_list.begin();
3137 it = std::find_if(it, it_end, data_send_ok());
3138 if (unlikely(it == it_end))
3140 boost::format formatter("Sending possible data is not existed. thread id : %d.");
3141 formatter % boost::this_thread::get_id();
3142 putLogError(100055, formatter.str(), __FILE__, __LINE__ );
3146 //sending possible data is exist
3147 if (it->send_possible_size > 0)
3149 //status remain SEND_OK
3150 it->status = SEND_OK;
3152 it->send_offset += it->send_end_size;
3154 //insert_posission recalc
3155 for (std::list<edit_data>::iterator list_it = it->edit_data_list.begin(); list_it
3156 != it->edit_data_list.end(); ++list_it)
3158 list_it->insert_posission -= it->send_end_size;
3161 //send_end_size recalc
3162 it->send_end_size = 0;
3164 //sending possible data is not exist
3167 //can recive from client continue
3168 if (it->send_rest_size > 0)
3170 //change status from SEND_OK to SEND_CONTINUE
3171 it->status = SEND_CONTINUE;
3173 //can not recive from client continue
3176 //change status from SEND_OK to SEND_END
3177 it->status = SEND_END;
3181 it = recv_data.send_status_list.begin();
3182 it = find_if(it, it_end, data_send_ok());
3183 //send_ok item is exist
3186 status = REALSERVER_CONNECT;
3188 //send_ok item is exist
3191 status = CLIENT_RECV;
3197 /*-------- DEBUG LOG --------*/
3198 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3200 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3201 "handle_realserver_send() : catch exception e = %d. thread id : %d.");
3202 formatter % e % boost::this_thread::get_id();
3203 putLogDebug(100107, formatter.str(), __FILE__, __LINE__ );
3206 /*------DEBUG LOG END------*/
3208 catch (const std::exception& ex)
3210 std::cerr << "protocol_module_sessionless::handle_realserver_send() : exception : error = " << ex.what() << "." << std::endl;
3211 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3212 "handle_realserver_send() : exception : error = %s. thread id : %d.");
3213 formatter % ex.what() % boost::this_thread::get_id();
3214 putLogError(100056, formatter.str(), __FILE__, __LINE__ );
3220 std::cerr << "protocol_module_sessionless::handle_realserver_send() : Unknown exception." << std::endl;
3221 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3222 "handle_realserver_send() : Unknown exception. thread id : %d.");
3223 formatter % boost::this_thread::get_id();
3224 putLogError(100057, formatter.str(), __FILE__, __LINE__ );
3228 /*-------- DEBUG LOG --------*/
3229 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3231 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3232 "handle_realserver_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
3233 formatter % status % boost::this_thread::get_id();
3234 putLogDebug(100108, formatter.str(), __FILE__, __LINE__ );
3236 /*------DEBUG LOG END------*/
3241 //! called from after sorryserver select
3242 //! @param[in] upstream thread id
3243 //! @param[in] sorryserver endpiont reference
3244 //! @return session use EVENT mode.
3245 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_select(
3246 const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint& sorry_endpoint)
3248 /*-------- DEBUG LOG --------*/
3249 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3251 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3252 "handle_sorryserver_select(const boost::thread::id thread_id, "
3253 "boost::asio::ip::tcp::endpoint& sorry_endpoint) : "
3254 "thread_id = %d, sorry_endpoint = [%s]:%d.");
3255 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port();
3256 putLogDebug(100109, formatter.str(), __FILE__, __LINE__ );
3258 /*------DEBUG LOG END------*/
3259 EVENT_TAG status = FINALIZE;
3260 boost::asio::ip::tcp::endpoint client_endpoint;
3262 thread_data_ptr session_data;
3263 session_thread_data_map_it session_thread_it;
3264 recive_data_map_it recive_data_it;
3268 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
3270 session_thread_it = session_thread_data_map.find(thread_id);
3271 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second== NULL))
3273 boost::format formatter("Invalid thread id. thread id : %d.");
3274 formatter % boost::this_thread::get_id();
3275 putLogError(100058, formatter.str(), __FILE__, __LINE__ );
3279 session_data = session_thread_it->second;
3280 //set sorry_endpoint
3281 session_data->target_endpoint = sorry_endpoint;
3284 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
3285 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
3287 boost::format formatter("Invalid endpoint. thread id : %d.");
3288 formatter % boost::this_thread::get_id();
3289 putLogError(100059, formatter.str(), __FILE__, __LINE__ );
3293 recive_data& recv_data = recive_data_it->second;
3295 send_status_it it = recv_data.send_status_list.begin();
3296 send_status_it it_end = recv_data.send_status_list.end();
3298 it = find_if(it, it_end, data_send_possible());
3301 status = SORRYSERVER_CONNECT;
3305 status = CLIENT_RECV;
3311 /*-------- DEBUG LOG --------*/
3312 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3314 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3315 "handle_sorryserver_select() : catch exception e = %d. thread id : %d.");
3316 formatter % e % boost::this_thread::get_id();
3317 putLogDebug(100110, formatter.str(), __FILE__, __LINE__ );
3320 /*------DEBUG LOG END------*/
3322 catch (const std::bad_alloc& ex)
3324 std::cerr << "protocol_module_sessionless::handle_sorryserver_select() : exception : Could not allocate memory." << std::endl;
3325 boost::format formatter("Could not allocate memory. thread id : %d.");
3326 formatter % boost::this_thread::get_id();
3327 putLogError(100060, formatter.str(), __FILE__, __LINE__ );
3330 catch (const std::exception& ex)
3332 std::cerr << "protocol_module_sessionless::handle_sorryserver_select() : exception : error = " << ex.what() << "." << std::endl;
3333 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3334 "handle_sorryserver_select() : exception : error = %s. thread id : %d.");
3335 formatter % ex.what() % boost::this_thread::get_id();
3336 putLogError(100061, formatter.str(), __FILE__, __LINE__ );
3341 std::cerr << "protocol_module_sessionless::handle_sorryserver_select() : Unknown exception." << std::endl;
3342 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3343 "handle_sorryserver_select() : Unknown exception. thread id : %d.");
3344 formatter % boost::this_thread::get_id();
3345 putLogError(100062, formatter.str(), __FILE__, __LINE__ );
3349 /*-------- DEBUG LOG --------*/
3350 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3354 "out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3355 "handle_sorryserver_select(const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint& sorry_endpoint) : return_value = %d."
3356 " thread id : %d.");
3357 formatter % status % boost::this_thread::get_id();
3358 putLogDebug(100111, formatter.str(), __FILE__, __LINE__ );
3360 /*------DEBUG LOG END------*/
3364 //! called from after sorryserver connect
3365 //! @param[in] upstream thread id
3366 //! @param[out] send buffer reference.
3367 //! @param[out] send length
3368 //! @return session use EVENT mode.
3369 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_connect(
3370 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
3372 /*-------- DEBUG LOG --------*/
3373 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3375 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3376 "handle_sorryserver_connect(const boost::thread::id thread_id, "
3377 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
3379 formatter % thread_id;
3380 putLogDebug(100112, formatter.str(), __FILE__, __LINE__ );
3382 /*------DEBUG LOG END------*/
3383 EVENT_TAG status = FINALIZE;
3385 size_t header_offset = 0;
3386 size_t header_offset_len = 0;
3387 size_t url_offset = 0;
3388 size_t url_offset_len = 0;
3389 size_t send_buffer_remian_size = 0;
3390 size_t copy_size = 0;
3391 const int send_buffer_end_size = sendbuffer.max_size();
3392 const std::string http_header = "";
3393 const std::string str_forword_for = "X-Forwarded-For";
3394 thread_data_ptr session_data;
3395 session_thread_data_map_it session_thread_it;
3396 recive_data_map_it recive_data_it;
3401 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
3404 session_thread_it = session_thread_data_map.find(thread_id);
3405 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3407 boost::format formatter("Invalid thread id. thread id : %d.");
3408 formatter % boost::this_thread::get_id();
3409 putLogError(100063, formatter.str(), __FILE__, __LINE__ );
3413 session_data = session_thread_it->second;
3417 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
3418 if (unlikely(recive_data_it
3419 == session_data->recive_data_map.end()))
3421 boost::format formatter("Invalid endpoint. thread id : %d.");
3422 formatter % boost::this_thread::get_id();
3423 putLogError(100064, formatter.str(), __FILE__, __LINE__ );
3427 //recive_buffer pointer check
3428 recive_data& recv_data = recive_data_it->second;
3429 if (unlikely(recv_data.recive_buffer == NULL))
3431 boost::format formatter("Invalid pointer. thread id : %d.");
3432 formatter % boost::this_thread::get_id();
3433 putLogError(100065, formatter.str(), __FILE__, __LINE__ );
3438 send_status_it it = recv_data.send_status_list.begin();
3439 send_status_it it_end = recv_data.send_status_list.end();
3441 it = find_if(it, it_end, data_send_possible());
3442 if (unlikely(it == it_end))
3444 boost::format formatter("Sending possible data is not existed. thread id : %d.");
3445 formatter % boost::this_thread::get_id();
3446 putLogError(100066, formatter.str(), __FILE__, __LINE__ );
3450 //send buffer rest size initialization
3451 send_buffer_remian_size = send_buffer_end_size;
3453 //edit_division flag on
3454 if (it->edit_division == EDIT_DIVISION_EDIT)
3456 //edit list is empty
3457 if (it->edit_data_list.empty())
3461 edata.data_size = 0;
3462 edata.insert_posission = 0;
3463 edata.replace_size = 0;
3465 if (strlen(sorry_uri.data()) > 0)
3467 ret = find_uri(recv_data.recive_buffer + it->send_offset, it->send_possible_size, url_offset,
3469 /*-------- DEBUG LOG --------*/
3470 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3472 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3473 "handle_sorryserver_connect() : call find_uri : "
3474 "return_value = %d. thread id : %d.");
3475 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
3476 putLogDebug(100113, formatter.str(), __FILE__, __LINE__ );
3478 /*------DEBUG LOG END------*/
3479 //search http header result is OK
3482 //edit sorry_uri, put it to edata.data
3483 edata.data = sorry_uri.data();
3484 //save new uri offset
3485 edata.insert_posission = url_offset;
3486 //save new uri length
3487 edata.data_size = edata.data.size();
3488 //save old uri length
3489 edata.replace_size = url_offset_len;
3490 //add to edit_data_list
3491 it->edit_data_list.push_back(edata);
3495 if (forwarded_for == FORWARDED_FOR_ON)
3497 //search X-Forwarded-For header
3498 ret = find_http_header(recv_data.recive_buffer + it->send_offset, it->send_possible_size,
3499 str_forword_for.c_str(), header_offset, header_offset_len);
3500 /*-------- DEBUG LOG --------*/
3501 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3503 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3504 "handle_sorryserver_connect() : call find_http_header : "
3505 "return_value = %d. thread id : %d.");
3506 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
3507 putLogDebug(100114, formatter.str(), __FILE__, __LINE__ );
3509 /*------DEBUG LOG END------*/
3511 //search http header result is OK
3514 //edit X-Forwarded-For header, put it to edata.data
3515 edata.data.assign(recv_data.recive_buffer + it->send_offset + header_offset, header_offset_len);
3517 edata.data += session_data->client_endpoint_tcp.address().to_string();
3518 //save new X-Forwarded-For header offset
3519 edata.insert_posission = header_offset;
3520 //save new X-Forwarded-For header length
3521 edata.data_size = edata.data.size();
3522 //save old X-Forwarded-For header length
3523 edata.replace_size = header_offset_len;
3525 //search http header result is NG
3528 //search whole http header, get whole http header's offset and length
3529 ret = find_http_header(recv_data.recive_buffer + it->send_offset, it->send_possible_size, "",
3530 header_offset, header_offset_len);
3531 /*-------- DEBUG LOG --------*/
3532 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3534 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3535 "handle_sorryserver_connect() : call find_http_header : "
3536 "return_value = %d. thread id : %d.");
3537 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
3538 putLogDebug(100115, formatter.str(), __FILE__, __LINE__ );
3540 /*------DEBUG LOG END------*/
3543 boost::format formatter("find_http_header() function failure. thread id : %d.");
3544 formatter % boost::this_thread::get_id();
3545 putLogError(100067, formatter.str(), __FILE__, __LINE__ );
3546 /*-------- DEBUG LOG --------*/
3547 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3549 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3550 "handle_sorryserver_connect(const boost::thread::id thread_id, "
3551 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
3552 "size_t& datalen) : return_value = %d. thread id : %d.");
3553 formatter % FINALIZE % boost::this_thread::get_id();
3554 putLogDebug(100116, formatter.str(), __FILE__, __LINE__ );
3556 /*------DEBUG LOG END------*/
3559 //create X-Forwarded-For header, set it to edata.data
3560 edata.data = str_forword_for;
3562 edata.data += session_data->client_endpoint_tcp.address().to_string();
3563 edata.data += "\r\n";
3564 //save new X-Forwarded-For header offset
3565 edata.insert_posission = header_offset;
3566 //save new X-Forwarded-For header length
3567 edata.data_size = edata.data.size();
3568 //save old X-Forwarded-For header length
3569 edata.replace_size = 0;
3572 //add to edit_data_list
3573 it->edit_data_list.push_back(edata);
3577 /*-------- DEBUG LOG --------*/
3578 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3580 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3581 "handle_sorryserver_connect() : Copy data loop start. thread id : %d.");
3582 formatter % boost::this_thread::get_id();
3583 putLogDebug(100117, formatter.str(), __FILE__, __LINE__ );
3585 /*------DEBUG LOG END------*/
3588 //edit_data_list is empty
3589 if (it->edit_data_list.empty())
3591 //set edit_division flag off
3592 it->edit_division = EDIT_DIVISION_NO_EDIT;
3594 if (send_buffer_remian_size > 0 && it->send_possible_size > 0)
3596 //send_buffer_remian_size is larger
3597 if (send_buffer_remian_size > it->send_possible_size)
3599 //copy data from recive_buffer to sendbuffer by sending_possible size
3600 copy_size = it->send_possible_size;
3601 /*-------- DEBUG LOG --------*/
3602 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3604 std::string datadump;
3605 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
3606 copy_size, datadump);
3607 boost::format formatter(
3608 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3609 "handle_sorryserver_connect() : before memcpy (data dump) : "
3610 "data begin = %d, data_size = %d, data = %s");
3611 formatter % (it->send_offset + it->send_end_size)
3612 % copy_size % datadump;
3613 putLogDebug(100118, formatter.str(), __FILE__, __LINE__ );
3615 /*------DEBUG LOG END------*/
3616 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3617 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
3618 /*-------- DEBUG LOG --------*/
3619 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3621 std::string datadump;
3622 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3623 copy_size, datadump);
3624 boost::format formatter(
3625 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3626 "handle_sorryserver_connect() : after memcpy (data dump) : "
3627 "data begin = %d, data_size = %d, data = %s");
3628 formatter % (send_buffer_end_size - send_buffer_remian_size)
3629 % copy_size % datadump;
3630 putLogDebug(100119, formatter.str(), __FILE__, __LINE__ );
3632 /*------DEBUG LOG END------*/
3633 it->send_end_size += copy_size;
3634 it->send_possible_size = 0;
3635 send_buffer_remian_size -= copy_size;
3637 //send_possible_size is larger
3640 copy_size = send_buffer_remian_size;
3641 /*-------- DEBUG LOG --------*/
3642 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3644 std::string datadump;
3645 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
3646 copy_size, datadump);
3647 boost::format formatter(
3648 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3649 "handle_sorryserver_connect() : before memcpy (data dump) : "
3650 "data begin = %d, data_size = %d, data = %s");
3651 formatter % (it->send_offset + it->send_end_size)
3652 % copy_size % datadump;
3653 putLogDebug(100120, formatter.str(), __FILE__, __LINE__ );
3655 /*------DEBUG LOG END------*/
3656 //copy data from recive_buffer to sendbuffer by send buffer rest size
3657 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3658 recv_data.recive_buffer + it->send_offset + it->send_end_size,
3660 /*-------- DEBUG LOG --------*/
3661 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3663 std::string datadump;
3664 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3665 copy_size, datadump);
3666 boost::format formatter(
3667 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3668 "handle_sorryserver_connect() : after memcpy (data dump) : "
3669 "data begin = %d, data_size = %d, data = %s");
3670 formatter % (send_buffer_end_size - send_buffer_remian_size)
3671 % copy_size % datadump;
3672 putLogDebug(100121, formatter.str(), __FILE__, __LINE__ );
3674 /*------DEBUG LOG END------*/
3675 it->send_end_size += copy_size;
3676 it->send_possible_size -= copy_size;
3677 send_buffer_remian_size = 0;
3683 //edit_data_list is not empty
3686 //search item which insert_posission is mininum
3687 std::list<edit_data>::iterator edit_min = std::min_element(it->edit_data_list.begin(),
3688 it->edit_data_list.end());
3689 //send_buffer_remian_size is larger than data that before X-Forwarded-For/uri
3690 if (send_buffer_remian_size >= edit_min->insert_posission - it->send_end_size)
3692 //copy data before X-Forwarded-For/url
3693 copy_size = edit_min->insert_posission - it->send_end_size;
3694 /*-------- DEBUG LOG --------*/
3695 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3697 std::string datadump;
3698 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
3699 copy_size, datadump);
3701 boost::format formatter(
3702 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3703 "handle_sorryserver_connect() : before memcpy (data dump) : "
3704 "data begin = %d, data_size = %d, data = %s");
3705 formatter % (it->send_offset + it->send_end_size)
3706 % copy_size % datadump;
3707 putLogDebug(100122, formatter.str(), __FILE__, __LINE__ );
3709 /*------DEBUG LOG END------*/
3710 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3711 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
3712 /*-------- DEBUG LOG --------*/
3713 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3715 std::string datadump;
3716 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3717 copy_size, datadump);
3718 boost::format formatter(
3719 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3720 "handle_sorryserver_connect() : after memcpy (data dump) : "
3721 "data begin = %d, data_size = %d, data = %s");
3722 formatter % (send_buffer_end_size - send_buffer_remian_size)
3723 % copy_size % datadump;
3724 putLogDebug(100123, formatter.str(), __FILE__, __LINE__ );
3726 /*------DEBUG LOG END------*/
3727 it->send_end_size += copy_size;
3728 it->send_possible_size -= copy_size;
3729 send_buffer_remian_size -= copy_size;
3731 //there is remain buffer for copy X-Forwarded-For/url
3732 if (send_buffer_remian_size >= edit_min->data_size)
3734 /*-------- DEBUG LOG --------*/
3735 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3737 std::string datadump;
3738 dump_memory(edit_min->data.c_str(),
3739 edit_min->data_size, datadump);
3740 boost::format formatter(
3741 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3742 "handle_sorryserver_connect() : before memcpy (data dump) : "
3743 "data begin = 0, data_size = %d, data = %s");
3744 formatter % edit_min->data_size % datadump;
3745 putLogDebug(100124, formatter.str(), __FILE__, __LINE__ );
3747 /*------DEBUG LOG END------*/
3748 //copy X-Forwarded-For/uri
3749 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3750 edit_min->data.c_str(), edit_min->data_size);
3751 /*-------- DEBUG LOG --------*/
3752 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3754 std::string datadump;
3755 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3756 edit_min->data_size, datadump);
3758 boost::format formatter(
3759 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3760 "handle_sorryserver_connect() : after memcpy (data dump) : "
3761 "data begin = %d, data_size = %d, data = %s");
3762 formatter % (send_buffer_end_size - send_buffer_remian_size)
3763 % edit_min->data_size % datadump;
3764 putLogDebug(100125, formatter.str(), __FILE__, __LINE__ );
3766 /*------DEBUG LOG END------*/
3767 it->send_end_size += edit_min->replace_size;
3768 it->send_possible_size -= edit_min->replace_size;
3769 send_buffer_remian_size -= edit_min->data_size;
3770 it->edit_data_list.erase(edit_min);
3778 //data that before X-Forwarded-For/uri is larger than send_buffer_remian_size
3781 copy_size = send_buffer_remian_size;
3782 /*-------- DEBUG LOG --------*/
3783 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3785 std::string datadump;
3786 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3787 copy_size, datadump);
3789 boost::format formatter(
3790 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3791 "handle_sorryserver_connect() : before memcpy (data dump) : "
3792 "data begin = %d, data_size = %d, data = %s");
3793 formatter % (it->send_offset + it->send_end_size)
3794 % copy_size % datadump;
3795 putLogDebug(100126, formatter.str(), __FILE__, __LINE__ );
3797 /*------DEBUG LOG END------*/
3798 //copy data as large as possible
3799 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3800 recv_data.recive_buffer + it->send_offset + it->send_end_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() : after memcpy (data dump) : "
3811 "data begin = %d, data_size = %d, data = %s");
3812 formatter % (send_buffer_end_size - send_buffer_remian_size)
3813 % copy_size % datadump;
3814 putLogDebug(100127, formatter.str(), __FILE__, __LINE__ );
3816 /*------DEBUG LOG END------*/
3817 it->send_end_size += copy_size;
3818 it->send_possible_size -= copy_size;
3819 send_buffer_remian_size -= copy_size;
3824 /*-------- DEBUG LOG --------*/
3825 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3827 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3828 "handle_sorryserver_connect() : Copy data loop end. thread id : %d.");
3829 formatter % boost::this_thread::get_id();
3830 putLogDebug(100128, formatter.str(), __FILE__, __LINE__ );
3832 /*------DEBUG LOG END------*/
3834 //edit_division flag is off
3837 //copy data as large as possible
3838 //send_possible_size is larger
3839 if (send_buffer_remian_size >= it->send_possible_size)
3841 copy_size = it->send_possible_size;
3842 /*-------- DEBUG LOG --------*/
3843 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3845 std::string datadump;
3846 dump_memory(recv_data.recive_buffer+ it->send_offset, copy_size, datadump);
3848 boost::format formatter(
3849 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3850 "handle_sorryserver_connect() : before memcpy (data dump) : "
3851 "data begin = %d, data_size = %d, data = %s");
3852 formatter % it->send_offset
3853 % copy_size % datadump;
3854 putLogDebug(100129, formatter.str(), __FILE__, __LINE__ );
3856 /*------DEBUG LOG END------*/
3857 //copy data by send_possible size
3858 memcpy(sendbuffer.data(), recv_data.recive_buffer
3859 + it->send_offset, copy_size);
3860 /*-------- DEBUG LOG --------*/
3861 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3863 std::string datadump;
3864 dump_memory(sendbuffer.data(), copy_size, datadump);
3866 boost::format formatter(
3867 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3868 "handle_sorryserver_connect() : after memcpy (data dump) : "
3869 "data begin = 0, data_size = %d, data = %s");
3870 formatter % copy_size % datadump;
3871 putLogDebug(100130, formatter.str(), __FILE__, __LINE__ );
3873 /*------DEBUG LOG END------*/
3874 it->send_end_size = it->send_possible_size;
3875 it->send_possible_size = 0;
3876 send_buffer_remian_size -= copy_size;
3878 //buffer rest size is larger
3881 /*-------- DEBUG LOG --------*/
3882 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3884 std::string datadump;
3885 dump_memory(recv_data.recive_buffer+ it->send_offset, send_buffer_remian_size, datadump);
3887 boost::format formatter(
3888 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3889 "handle_sorryserver_connect() : before memcpy (data dump) : "
3890 "data begin = %d, data_size = %d, data = %s");
3891 formatter % it->send_offset
3892 % send_buffer_remian_size % datadump;
3893 putLogDebug(100131, formatter.str(), __FILE__, __LINE__ );
3895 /*------DEBUG LOG END------*/
3896 //copy data by buffer rest size
3897 memcpy(sendbuffer.data(), recv_data.recive_buffer
3898 + it->send_offset, send_buffer_remian_size);
3899 /*-------- DEBUG LOG --------*/
3900 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3902 std::string datadump;
3903 dump_memory(sendbuffer.data(), send_buffer_remian_size, datadump);
3905 boost::format formatter(
3906 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3907 "handle_sorryserver_connect() : after memcpy (data dump) : "
3908 "data begin = 0, data_size = %d, data = %s");
3909 formatter % send_buffer_remian_size % datadump;
3910 putLogDebug(100132, formatter.str(), __FILE__, __LINE__ );
3912 /*------DEBUG LOG END------*/
3913 it->send_end_size = send_buffer_remian_size;
3914 it->send_possible_size -= send_buffer_remian_size;
3915 send_buffer_remian_size = 0;
3919 //set copyed data length
3920 datalen = send_buffer_end_size - send_buffer_remian_size;
3922 status = SORRYSERVER_SEND;
3927 /*-------- DEBUG LOG --------*/
3928 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3930 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3931 "handle_sorryserver_connect() : catch exception e = %d. thread id : %d.");
3932 formatter % e % boost::this_thread::get_id();
3933 putLogDebug(100133, formatter.str(), __FILE__, __LINE__ );
3936 /*------DEBUG LOG END------*/
3938 catch (const std::exception& ex)
3940 std::cerr << "protocol_module_sessionless::handle_sorryserver_connect() : exception : error = " << ex.what() << "." << std::endl;
3941 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3942 "handle_sorryserver_connect() : exception : error = %s. thread id : %d.");
3943 formatter % ex.what() % boost::this_thread::get_id();
3944 putLogError(100068, formatter.str(), __FILE__, __LINE__ );
3949 std::cerr << "protocol_module_sessionless::handle_sorryserver_connect() : Unknown exception." << std::endl;
3950 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3951 "handle_sorryserver_connect() : Unknown exception. thread id : %d.");
3952 formatter % boost::this_thread::get_id();
3953 putLogError(100069, formatter.str(), __FILE__, __LINE__ );
3957 /*-------- DEBUG LOG --------*/
3958 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3960 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3961 "handle_sorryserver_connect(const boost::thread::id thread_id, "
3962 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
3963 "size_t& datalen) : return_value = %d. thread id : %d.");
3964 formatter % status % boost::this_thread::get_id();
3965 putLogDebug(100134, formatter.str(), __FILE__, __LINE__ );
3967 /*------DEBUG LOG END------*/
3972 //! called from after sorryserver connection fail
3973 //! @param[in] upstream thread id
3974 //! @param[in] sorryserver endpoint reference.
3975 //! @return session use EVENT mode.
3976 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_connection_fail(
3977 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint)
3979 /*-------- DEBUG LOG --------*/
3980 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3982 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3983 "handle_sorryserver_connection_fail(const boost::thread::id thread_id, "
3984 "const boost::asio::ip::tcp::endpoint & sorry_endpoint) : "
3985 "thread_id = %d, sorry_endpoint = [%s]:%d.");
3986 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port();
3987 putLogDebug(100135, formatter.str(), __FILE__, __LINE__ );
3989 /*------DEBUG LOG END------*/
3991 EVENT_TAG status = FINALIZE;
3992 thread_data_ptr session_data;
3993 session_thread_data_map_it session_thread_it;
3997 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
3999 session_thread_it = session_thread_data_map.find(thread_id);
4000 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
4002 boost::format formatter("Invalid thread id. thread id : %d.");
4003 formatter % boost::this_thread::get_id();
4004 putLogError(100070, formatter.str(), __FILE__, __LINE__ );
4008 session_data = session_thread_it->second;
4011 session_data->end_flag = END_FLAG_ON;
4012 /*-------- DEBUG LOG --------*/
4013 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4015 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4016 "handle_sorryserver_connection_fail() : END_FLAG_ON. thread id : %d.");
4017 formatter % boost::this_thread::get_id();
4018 putLogDebug(100136, formatter.str(), __FILE__, __LINE__ );
4020 /*------DEBUG LOG END------*/
4022 status = CLIENT_DISCONNECT;
4026 /*-------- DEBUG LOG --------*/
4027 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4029 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4030 "handle_sorryserver_connection_fail() : catch exception e = %d. thread id : %d.");
4031 formatter % e % boost::this_thread::get_id();
4032 putLogDebug(100137, formatter.str(), __FILE__, __LINE__ );
4035 /*------DEBUG LOG END------*/
4037 catch (const std::exception& ex)
4039 std::cerr << "protocol_module_sessionless::handle_sorryserver_connection_fail() : exception : error=" << ex.what() << "." << std::endl;
4040 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4041 "handle_sorryserver_connection_fail() : exception : error = %s. thread id : %d.");
4042 formatter % ex.what() % boost::this_thread::get_id();
4043 putLogError(100071, formatter.str(), __FILE__, __LINE__ );
4048 std::cerr << "protocol_module_sessionless::handle_sorryserver_connection_fail() : Unknown exception." << std::endl;
4049 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4050 "handle_sorryserver_connection_fail() : Unknown exception. thread id : %d.");
4051 formatter % boost::this_thread::get_id();
4052 putLogError(100072, formatter.str(), __FILE__, __LINE__ );
4056 /*-------- DEBUG LOG --------*/
4057 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4061 "out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4062 "handle_sorryserver_connection_fail( const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint) : return_value = %d."
4063 " thread id : %d.");
4064 formatter % status % boost::this_thread::get_id();
4065 putLogDebug(100138, formatter.str(), __FILE__, __LINE__ );
4067 /*------DEBUG LOG END------*/
4071 //! called from after sorryserver send
4072 //! @param[in] upstream thread id
4073 //! @return session use EVENT mode.
4074 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_send(
4075 const boost::thread::id thread_id)
4077 /*-------- DEBUG LOG --------*/
4078 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4080 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4081 "handle_sorryserver_send(const boost::thread::id thread_id) : "
4083 formatter % thread_id;
4084 putLogDebug(100139, formatter.str(), __FILE__, __LINE__ );
4086 /*------DEBUG LOG END------*/
4087 EVENT_TAG status = FINALIZE;
4088 thread_data_ptr session_data;
4089 session_thread_data_map_it session_thread_it;
4090 recive_data_map_it recive_data_it;
4095 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
4098 session_thread_it = session_thread_data_map.find(thread_id);
4099 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
4101 boost::format formatter("Invalid thread id. thread id : %d.");
4102 formatter % boost::this_thread::get_id();
4103 putLogError(100073, formatter.str(), __FILE__, __LINE__ );
4107 session_data = session_thread_it->second;
4111 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
4112 if (unlikely(recive_data_it
4113 == session_data->recive_data_map.end()))
4115 boost::format formatter("Invalid endpoint. thread id : %d.");
4116 formatter % boost::this_thread::get_id();
4117 putLogError(100074, formatter.str(), __FILE__, __LINE__ );
4121 recive_data& recv_data = recive_data_it->second;
4123 send_status_it it = recv_data.send_status_list.begin();
4124 send_status_it it_end = recv_data.send_status_list.end();
4126 it = std::adjacent_find(it, it_end, data_send_list_incorrect());
4127 if (unlikely(it != it_end))
4129 boost::format formatter("Sending possible data is invalid. thread id : %d.");
4130 formatter % boost::this_thread::get_id();
4131 putLogError(100075, formatter.str(), __FILE__, __LINE__ );
4136 it = recv_data.send_status_list.begin();
4137 it = find_if(it, it_end, data_send_ok());
4138 if (unlikely(it == it_end))
4140 boost::format formatter("Sending possible data is not existed. thread id : %d.");
4141 formatter % boost::this_thread::get_id();
4142 putLogError(100076, formatter.str(), __FILE__, __LINE__ );
4146 //sending possible data is exist
4147 if (it->send_possible_size > 0)
4149 //status remain SEND_OK
4150 it->status = SEND_OK;
4152 it->send_offset += it->send_end_size;
4154 //insert_posission recalc
4155 for (std::list<edit_data>::iterator list_it = it->edit_data_list.begin(); list_it
4156 != it->edit_data_list.end(); ++list_it)
4158 list_it->insert_posission -= it->send_end_size;
4161 //send_end_size recalc
4162 it->send_end_size = 0;
4164 //sending possible data is not exist
4167 //can recive from clent continue
4168 if (it->send_rest_size > 0)
4170 //change status from SEND_OK to SEND_CONTINUE
4171 it->status = SEND_CONTINUE;
4173 //can not recive from clent continue
4176 //change status from SEND_OK to SEND_END
4177 it->status = SEND_END;
4181 it = recv_data.send_status_list.begin();
4182 it = find_if(it, it_end, data_send_ok());
4183 //send_ok item is exist
4186 status = SORRYSERVER_CONNECT;
4188 //send_ok item is exist
4191 status = CLIENT_RECV;
4197 /*-------- DEBUG LOG --------*/
4198 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4200 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4201 "handle_sorryserver_send() : catch exception e = %d. thread id : %d.");
4202 formatter % e % boost::this_thread::get_id();
4203 putLogDebug(100140, formatter.str(), __FILE__, __LINE__ );
4206 /*------DEBUG LOG END------*/
4208 catch (const std::exception& ex)
4210 std::cerr << "protocol_module_sessionless::handle_sorryserver_send() : exception : error = " << ex.what() << "." << std::endl;
4211 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4212 "handle_sorryserver_send() : exception : error = %s. thread id : %d.");
4213 formatter % ex.what() % boost::this_thread::get_id();
4214 putLogError(100077, formatter.str(), __FILE__, __LINE__ );
4220 std::cerr << "protocol_module_sessionless::handle_sorryserver_send() : Unknown exception." << std::endl;
4221 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4222 "handle_sorryserver_send() : Unknown exception. thread id : %d.");
4223 formatter % boost::this_thread::get_id();
4224 putLogError(100078, formatter.str(), __FILE__, __LINE__ );
4228 /*-------- DEBUG LOG --------*/
4229 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4231 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4232 "handle_sorryserver_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
4233 formatter % status % boost::this_thread::get_id();
4234 putLogDebug(100141, formatter.str(), __FILE__, __LINE__ );
4236 /*------DEBUG LOG END------*/
4241 //! called from after realserver recive.for UDP
4242 //! @param[in] downstream thread id
4243 //! @param[in] realserver UDP endpoint reference
4244 //! @param[in] recive from realserver buffer reference
4245 //! @param[in] recv data length
4246 //! @return session use EVENT mode.
4247 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_recv(
4248 const boost::thread::id thread_id, const boost::asio::ip::udp::endpoint& rs_endpoint, const boost::array<char,
4249 MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
4251 /*-------- DEBUG LOG --------*/
4252 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4254 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4255 "handle_realserver_recv(const boost::thread::id thread_id, "
4256 "const boost::asio::ip::udp::endpoint& rs_endpoint, "
4257 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4258 "const size_t recvlen) : "
4259 "return_value = %d. thread id : %d.");
4260 formatter % STOP % boost::this_thread::get_id();
4261 putLogDebug(100142, formatter.str(), __FILE__, __LINE__ );
4263 /*------DEBUG LOG END------*/
4267 //! called from after realserver recvive for TCP/IP
4268 //! @param[in] downstream thread id
4269 //! @param[in] realserver TCP/IP endpoint reference
4270 //! @param[in] realserver recive buffer reference.
4271 //! @param[in] recv data length
4272 //! @return session use EVENT mode.
4273 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_recv(
4274 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint& rs_endpoint, const boost::array<char,
4275 MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
4277 /*-------- DEBUG LOG --------*/
4278 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4280 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
4282 dump_memory(recvbuffer.data(), buffer_size, buffer);
4283 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4284 "handle_realserver_recv(const boost::thread::id thread_id, "
4285 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
4286 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4287 "const size_t recvlen) : thread_id = %d, rs_endpoint = [%s]:%d, recvbuffer = %s, recvlen = %d.");
4288 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port()
4290 putLogDebug(100143, formatter.str(), __FILE__, __LINE__ );
4292 /*------DEBUG LOG END------*/
4294 EVENT_TAG status = FINALIZE;
4295 size_t data_remain_start = 0;
4296 size_t data_remain_size = 0;
4297 size_t request_data_remain_size = 0;
4298 size_t header_offset = 0;
4299 size_t header_offset_len = 0;
4300 size_t content_length_header_offset = 0;
4301 size_t content_length_header_len = 0;
4302 size_t content_len_value = 0;
4304 size_t buffer_size = 0;
4305 const size_t cr_lf_len = strlen("\r\n\r\n");
4306 thread_data_ptr session_data;
4307 char* buffer1 = NULL;
4308 char* buffer2 = NULL;
4309 std::string str_value;
4310 const std::string http_header = "";
4311 const std::string content_header = "Content-Length";
4313 CHECK_RESULT_TAG check_result;
4314 session_thread_data_map_it session_thread_it;
4315 recive_data_map_it recive_data_it;
4318 if (recvlen > recvbuffer.size())
4320 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : Data size bigger than buffer size." << std::endl;
4321 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
4322 formatter % boost::this_thread::get_id();
4323 putLogError(100079, formatter.str(), __FILE__, __LINE__ );
4324 /*-------- DEBUG LOG --------*/
4325 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4327 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4328 "handle_realserver_recv(const boost::thread::id thread_id, "
4329 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
4330 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4331 "const size_t recvlen) : return_value = %d. thread id : %d.");
4332 formatter % FINALIZE % boost::this_thread::get_id();
4333 putLogDebug(100144, formatter.str(), __FILE__, __LINE__ );
4335 /*------DEBUG LOG END------*/
4342 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
4344 session_thread_it = session_thread_data_map.find(thread_id);
4345 if (unlikely(session_thread_it == session_thread_data_map.end()
4346 ||session_thread_it->second == NULL))
4348 boost::format formatter("Invalid thread id. thread id : %d.");
4349 formatter % boost::this_thread::get_id();
4350 putLogError(100080, formatter.str(), __FILE__, __LINE__ );
4354 session_data = session_thread_it->second;
4357 recive_data_it = session_data->recive_data_map.find(rs_endpoint);
4358 if (recive_data_it == session_data->recive_data_map.end())
4360 recive_data recv_data;
4361 session_data->recive_data_map[rs_endpoint] = recv_data;
4364 session_data->target_endpoint = rs_endpoint;
4366 recive_data& recv_data = session_data->recive_data_map[rs_endpoint];
4368 send_status_it it = recv_data.send_status_list.begin();
4369 send_status_it it_end = recv_data.send_status_list.end();
4372 it = std::find_if(it, it_end, data_send_ok());
4373 if (unlikely(it != it_end))
4375 boost::format formatter("Sending data is not correct. thread id : %d.");
4376 formatter % boost::this_thread::get_id();
4377 putLogError(100081, formatter.str(), __FILE__, __LINE__ );
4382 it = recv_data.send_status_list.begin();
4383 it = std::adjacent_find(it, it_end, data_send_repeated());
4384 if (unlikely(it != it_end))
4386 boost::format formatter("Sending data is not correct. thread id : %d.");
4387 formatter % boost::this_thread::get_id();
4388 putLogError(100082, formatter.str(), __FILE__, __LINE__ );
4392 /*-------- DEBUG LOG --------*/
4393 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4395 std::string datadump;
4396 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
4397 "send_rest_size = %d, send_possible_size = %d, "
4398 "send_offset = %d, unsend_size = %d, edit_division = %d.");
4400 for (it = recv_data.send_status_list.begin();
4401 it != recv_data.send_status_list.end();
4404 formatter % i % it->status % it->send_end_size
4405 % it->send_rest_size % it->send_possible_size
4406 % it->send_offset % it->unsend_size % it->edit_division;
4407 datadump += formatter.str();
4410 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4411 "handle_realserver_recv() : send status list dump : send status list size = %d.%s");
4413 formatter % recv_data.send_status_list.size() % datadump;
4414 putLogDebug(100145, formatter.str(), __FILE__, __LINE__ );
4416 /*------DEBUG LOG END------*/
4417 it = recv_data.send_status_list.begin();
4418 //get original status info
4419 while (it != it_end)
4421 //item status is SEND_END
4422 if (it->status == SEND_END)
4425 recv_data.send_status_list.erase(it++);
4428 //item status is SEND_CONTINUE
4429 else if (it->status == SEND_CONTINUE)
4431 it->send_offset += it->send_end_size;
4432 data_remain_start = it->send_offset;
4435 //item status is SEND_NG
4438 data_remain_start = it->send_offset;
4439 data_remain_size = it->unsend_size;
4445 /*-------- DEBUG LOG --------*/
4446 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4448 std::string datadump;
4449 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
4450 "send_rest_size = %d, send_possible_size = %d, "
4451 "send_offset = %d, unsend_size = %d, edit_division = %d.");
4453 for (it = recv_data.send_status_list.begin();
4454 it != recv_data.send_status_list.end();
4457 formatter % i % it->status % it->send_end_size
4458 % it->send_rest_size % it->send_possible_size
4459 % it->send_offset % it->unsend_size % it->edit_division;
4460 datadump += formatter.str();
4463 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4464 "handle_realserver_recv() : send status list dump : send status list size = %d.%s");
4466 formatter % recv_data.send_status_list.size() % datadump;
4467 putLogDebug(100146, formatter.str(), __FILE__, __LINE__ );
4469 /*------DEBUG LOG END------*/
4470 //recive buffer process
4471 //buffer rest size < request size
4472 if (recv_data.recive_buffer_rest_size < recvlen)
4474 //buffer max size < remain size + request size
4475 //buffer is need reallocate
4476 if (recv_data.recive_buffer_max_size < data_remain_size + recvlen)
4478 //the buffer's size that will be allocated is exceed the upper limit value
4479 if (MAX_SESSIONLESS_MODULE_BUFFER_SIZE < data_remain_size + recvlen)
4481 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : the buffer's size that will be allacted is exceed the upper limit value." << std::endl;
4482 boost::format formatter("The buffer's size that will be allocated is exceed the upper limit value. thread id : %d.");
4483 formatter % boost::this_thread::get_id();
4484 putLogError(100083, formatter.str(), __FILE__, __LINE__ );
4486 /*-------- DEBUG LOG --------*/
4487 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4489 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4490 "handle_realserver_recv(const boost::thread::id thread_id, "
4491 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
4492 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4493 "const size_t recvlen) : return_value = %d. thread id : %d.");
4494 formatter % FINALIZE % boost::this_thread::get_id();
4495 putLogDebug(100147, formatter.str(), __FILE__, __LINE__ );
4497 /*------DEBUG LOG END------*/
4501 //recive_buffer1's memory allocate and initialization
4502 buffer_size = (data_remain_size + recvlen) > MAX_BUFFER_SIZE ? (data_remain_size + recvlen) : MAX_BUFFER_SIZE;
4503 buffer1 = new char[buffer_size];
4504 /*-------- DEBUG LOG --------*/
4505 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4507 boost::format formatter("new : address = &(%d), size = %lu.");
4508 formatter % static_cast<void*>(buffer1) % buffer_size;
4509 putLogDebug(100148, formatter.str(), __FILE__, __LINE__ );
4511 /*-------- DEBUG LOG --------*/
4512 memset(buffer1, 0, buffer_size);
4513 //recive_buffer2's memory allocate and initialization
4514 buffer2 = new char[buffer_size];
4515 /*-------- DEBUG LOG --------*/
4516 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4518 boost::format formatter("new : address = &(%d), size = %lu.");
4519 formatter % static_cast<void*>(buffer2) % buffer_size;
4520 putLogDebug(100149, formatter.str(), __FILE__, __LINE__ );
4522 /*-------- DEBUG LOG END--------*/
4523 memset(buffer2, 0, buffer_size);
4525 /*-------- DEBUG LOG --------*/
4526 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4528 std::string datadump;
4529 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
4531 boost::format formatter(
4532 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4533 "handle_realserver_recv() : before memcpy (data dump) : "
4534 "data begin = %d, data_size = %d, data = %s");
4535 formatter % data_remain_start % data_remain_size % datadump;
4536 putLogDebug(100150, formatter.str(), __FILE__, __LINE__ );
4538 /*------DEBUG LOG END------*/
4539 //copy data from old buffer to new buffer
4540 memcpy(buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
4541 /*-------- DEBUG LOG --------*/
4542 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4544 std::string datadump;
4545 dump_memory(buffer1, data_remain_size, datadump);
4547 boost::format formatter(
4548 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4549 "handle_realserver_recv() : after memcpy (data dump) : "
4550 "data begin = 0, data_size = %d, data = %s");
4551 formatter % data_remain_size % datadump;
4552 putLogDebug(100151, formatter.str(), __FILE__, __LINE__ );
4554 /*------DEBUG LOG END------*/
4556 /*-------- DEBUG LOG --------*/
4557 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4559 std::string datadump;
4560 dump_memory(recvbuffer.data(), recvlen, datadump);
4561 boost::format formatter(
4562 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4563 "handle_realserver_recv() : before memcpy (data dump) : "
4564 "data begin = 0, data_size = %d, data = %s");
4565 formatter % recvlen % datadump;
4566 putLogDebug(100152, formatter.str(), __FILE__, __LINE__ );
4568 /*------DEBUG LOG END------*/
4569 memcpy(buffer1 + data_remain_size, recvbuffer.data(), recvlen);
4570 /*-------- DEBUG LOG --------*/
4571 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4573 std::string datadump;
4574 dump_memory(buffer1 + data_remain_size, recvlen, datadump);
4575 boost::format formatter(
4576 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4577 "handle_realserver_recv() : after memcpy (data dump) : "
4578 "data begin = %d, data_size = %d, data = %s");
4579 formatter % data_remain_size % recvlen % datadump;
4580 putLogDebug(100153, formatter.str(), __FILE__, __LINE__ );
4582 /*------DEBUG LOG END------*/
4583 //free old buffer1 and old buffer2
4584 if (recv_data.recive_buffer1 != NULL)
4586 /*-------- DEBUG LOG --------*/
4587 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4589 boost::format formatter("delete : address = &(%d).");
4590 formatter % static_cast<void*>(recv_data.recive_buffer1);
4591 putLogDebug(100154, formatter.str(), __FILE__,
4594 /*------DEBUG LOG END------*/
4595 delete[] recv_data.recive_buffer1;
4596 recv_data.recive_buffer1 = NULL;
4599 if (recv_data.recive_buffer2 != NULL)
4601 /*-------- DEBUG LOG --------*/
4602 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4604 boost::format formatter("delete : address = &(%d).");
4605 formatter % static_cast<void*>(recv_data.recive_buffer2);
4606 putLogDebug(100155, formatter.str(), __FILE__,
4609 /*------DEBUG LOG END------*/
4610 delete[] recv_data.recive_buffer2;
4611 recv_data.recive_buffer2 = NULL;
4614 //set new buffer pointer
4615 recv_data.recive_buffer1 = buffer1;
4616 recv_data.recive_buffer2 = buffer2;
4617 recv_data.recive_buffer = recv_data.recive_buffer1;
4618 //set new buffer's max size
4619 recv_data.recive_buffer_max_size = buffer_size;
4621 //buffer's max size >= remain data size + requst size
4622 //buffer isn't need reallocate, but switch
4625 //pointer valid check
4626 if (unlikely(recv_data.recive_buffer1 == NULL || recv_data.recive_buffer2 == NULL))
4628 boost::format formatter("Invalid pointer. thread id : %d.");
4629 formatter % boost::this_thread::get_id();
4630 putLogError(100084, formatter.str(), __FILE__, __LINE__ );
4633 //using buffer is buffer1
4634 if (recv_data.recive_buffer == recv_data.recive_buffer1)
4636 //buffer2 initialization
4637 memset(recv_data.recive_buffer2, 0, recv_data.recive_buffer_max_size);
4638 /*-------- DEBUG LOG --------*/
4639 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4641 std::string datadump;
4642 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
4643 boost::format formatter(
4644 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4645 "handle_realserver_recv() : before memcpy (data dump) : "
4646 "data begin = %d, data_size = %d, data = %s");
4647 formatter % data_remain_start % data_remain_size % datadump;
4648 putLogDebug(100156, formatter.str(), __FILE__, __LINE__ );
4650 /*------DEBUG LOG END------*/
4651 //copy data from buffer1 to buffer2
4652 memcpy(recv_data.recive_buffer2, recv_data.recive_buffer + data_remain_start, data_remain_size);
4653 /*-------- DEBUG LOG --------*/
4654 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4656 std::string datadump;
4657 dump_memory(recv_data.recive_buffer2, data_remain_size, datadump);
4658 boost::format formatter(
4659 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4660 "handle_realserver_recv() : after memcpy (data dump) : "
4661 "data begin = 0, data_size = %d, data = %s");
4662 formatter % data_remain_size % datadump;
4663 putLogDebug(100157, formatter.str(), __FILE__, __LINE__ );
4665 /*------DEBUG LOG END------*/
4666 /*-------- DEBUG LOG --------*/
4667 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4669 std::string datadump;
4670 dump_memory(recvbuffer.data(), recvlen, datadump);
4671 boost::format formatter(
4672 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4673 "handle_realserver_recv() : before memcpy (data dump) : "
4674 "data begin = 0, data_size = %d, data = %s");
4675 formatter % data_remain_size % datadump;
4676 putLogDebug(100158, formatter.str(), __FILE__, __LINE__ );
4678 /*------DEBUG LOG END------*/
4679 memcpy(recv_data.recive_buffer2 + data_remain_size, recvbuffer.data(), recvlen);
4680 /*-------- DEBUG LOG --------*/
4681 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4683 std::string datadump;
4684 dump_memory(recv_data.recive_buffer2 + data_remain_size, recvlen, datadump);
4686 boost::format formatter(
4687 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4688 "handle_realserver_recv() : after memcpy (data dump) : "
4689 "data begin = %d, data_size = %d, data = %s");
4690 formatter % data_remain_size % recvlen % datadump;
4691 putLogDebug(100159, formatter.str(), __FILE__, __LINE__ );
4693 /*------DEBUG LOG END------*/
4694 //set buffer2 as using buffer
4695 recv_data.recive_buffer = recv_data.recive_buffer2;
4697 //using buffer is buffer2
4700 //buffer1 initialization
4701 memset(recv_data.recive_buffer1, 0, recv_data.recive_buffer_max_size);
4702 /*-------- DEBUG LOG --------*/
4703 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4705 std::string datadump;
4706 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
4708 boost::format formatter(
4709 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4710 "handle_realserver_recv() : before memcpy (data dump) : "
4711 "data begin = %d, data_size = %d, data = %s");
4712 formatter % data_remain_start % data_remain_size % datadump;
4713 putLogDebug(100160, formatter.str(), __FILE__, __LINE__ );
4715 /*------DEBUG LOG END------*/
4716 //copy data from buffer2 to buffer1
4717 memcpy(recv_data.recive_buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
4718 /*-------- DEBUG LOG --------*/
4719 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4721 std::string datadump;
4722 dump_memory(recv_data.recive_buffer1, data_remain_size, datadump);
4724 boost::format formatter(
4725 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4726 "handle_realserver_recv() : after memcpy (data dump) : "
4727 "data begin = 0, data_size = %d, data = %s");
4728 formatter % data_remain_size % datadump;
4729 putLogDebug(100161, formatter.str(), __FILE__, __LINE__ );
4731 /*------DEBUG LOG END------*/
4732 /*-------- DEBUG LOG --------*/
4733 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4735 std::string datadump;
4736 dump_memory(recvbuffer.data(), recvlen, datadump);
4738 boost::format formatter(
4739 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4740 "handle_realserver_recv() : before memcpy (data dump) : "
4741 "data begin = 0, data_size = %d, data = %s");
4742 formatter % recvlen % datadump;
4743 putLogDebug(100162, formatter.str(), __FILE__, __LINE__ );
4745 /*------DEBUG LOG END------*/
4746 memcpy(recv_data.recive_buffer1 + data_remain_size, recvbuffer.data(), recvlen);
4747 /*-------- DEBUG LOG --------*/
4748 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4750 std::string datadump;
4751 dump_memory(recv_data.recive_buffer1 + data_remain_size, recvlen, datadump);
4753 boost::format formatter(
4754 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4755 "handle_realserver_recv() : after memcpy (data dump) : "
4756 "data begin = %d, data_size = %d, data = %s");
4757 formatter % data_remain_size % recvlen % datadump;
4758 putLogDebug(100163, formatter.str(), __FILE__, __LINE__ );
4760 /*------DEBUG LOG END------*/
4761 //set buffer1 as using buffer
4762 recv_data.recive_buffer = recv_data.recive_buffer1;
4766 //set buffer's rest size
4767 recv_data.recive_buffer_rest_size = recv_data.recive_buffer_max_size - data_remain_size - recvlen;
4769 //remain_size recalc
4770 data_remain_size += recvlen;
4772 send_status_it it_begin = recv_data.send_status_list.begin();
4773 send_status_it it_end = recv_data.send_status_list.end();
4775 for (; it_begin != it_end; ++it_begin)
4777 it_begin->send_offset -= data_remain_start;
4780 //buffer's rest size >= request size
4784 //pointer valid check
4785 if (unlikely(recv_data.recive_buffer == NULL))
4787 boost::format formatter("Invalid pointer. thread id : %d.");
4788 formatter % boost::this_thread::get_id();
4789 putLogError(100085, formatter.str(), __FILE__, __LINE__ );
4792 /*-------- DEBUG LOG --------*/
4793 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4795 std::string datadump;
4796 dump_memory(recvbuffer.data(), recvlen, datadump);
4797 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4798 "handle_realserver_recv() : before memcpy (data dump) : "
4799 "data begin = 0, data_size = %d, data = %s");
4800 formatter % recvlen % datadump;
4801 putLogDebug(100164, formatter.str(), __FILE__, __LINE__ );
4803 /*------DEBUG LOG END------*/
4805 //copy data from parameter to using buffer
4806 memcpy(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
4807 recvbuffer.data(), recvlen);
4808 /*-------- DEBUG LOG --------*/
4809 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4811 std::string datadump;
4812 dump_memory(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
4814 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4815 "handle_realserver_recv() : before memcpy (data dump) : "
4816 "data begin = %d, data_size = %d, data = %s");
4817 formatter % (recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size )
4818 % recvlen % datadump;
4819 putLogDebug(100165, formatter.str(), __FILE__, __LINE__ );
4821 /*------DEBUG LOG END------*/
4822 //buffer's rest size recalc
4823 recv_data.recive_buffer_rest_size -= recvlen;
4824 //remain data size recalc
4825 data_remain_size += recvlen;
4828 it = recv_data.send_status_list.begin();
4829 it_end = recv_data.send_status_list.end();
4830 //request rest size initialization
4831 request_data_remain_size = recvlen;
4832 //original status process
4833 for (; it != it_end; ++it)
4835 //status is SEND_CONTINUE
4836 if (it->status == SEND_CONTINUE)
4838 //send rest size > request size
4839 if (it->send_rest_size > request_data_remain_size)
4841 //send possible size recalc
4842 it->send_possible_size = request_data_remain_size;
4843 //send rest size recalc
4844 it->send_rest_size -= request_data_remain_size;
4845 //send end size recalc
4846 it->send_end_size = 0;
4847 //request size recalc
4848 request_data_remain_size = 0;
4850 //send rest size <= request size
4853 //send possible size recalc
4854 it->send_possible_size = it->send_rest_size;
4855 //send rest size recalc
4856 request_data_remain_size -= it->send_rest_size;
4857 //send end size recalc
4858 it->send_end_size = 0;
4859 //request size recalc
4860 it->send_rest_size = 0;
4862 //change status from SEND_CONTINUE to SEND_OK
4863 it->status = SEND_OK;
4866 else if (it->status == SEND_NG)
4869 check_result = check_status_code(recv_data.recive_buffer + it->send_offset, data_remain_size);
4870 /*-------- DEBUG LOG --------*/
4871 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4873 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4874 "handle_realserver_recv() : call check_http_method : "
4875 "return_value = %d. thread id : %d.");
4876 formatter % check_result % boost::this_thread::get_id();
4877 putLogDebug(100166, formatter.str(), __FILE__, __LINE__ );
4879 /*------DEBUG LOG END------*/
4880 //check http method result is OK
4881 if (check_result == CHECK_OK)
4883 //check http version
4884 check_result = check_http_version(recv_data.recive_buffer + it->send_offset, data_remain_size);
4885 /*-------- DEBUG LOG --------*/
4886 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4888 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4889 "handle_realserver_recv() : call check_http_version : "
4890 "return_value = %d. thread id : %d.");
4891 formatter % check_result % boost::this_thread::get_id();
4892 putLogDebug(100167, formatter.str(), __FILE__, __LINE__ );
4894 /*------DEBUG LOG END------*/
4896 //check method and version result is OK
4897 if (check_result == CHECK_OK)
4899 //search http header
4900 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size, http_header,
4901 header_offset, header_offset_len);
4902 /*-------- DEBUG LOG --------*/
4903 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4905 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4906 "handle_realserver_recv() : call find_http_header : "
4907 "return_value = %d. thread id : %d.");
4908 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
4909 putLogDebug(100168, formatter.str(), __FILE__, __LINE__ );
4911 /*------DEBUG LOG END------*/
4912 //search http header result is OK
4915 //search Content_Length header
4916 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size,
4917 content_header, content_length_header_offset, content_length_header_len);
4918 /*-------- DEBUG LOG --------*/
4919 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4921 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4922 "handle_realserver_recv() : call find_http_header : "
4923 "return_value = %d. thread id : %d.");
4924 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
4925 putLogDebug(100169, formatter.str(), __FILE__, __LINE__ );
4927 /*------DEBUG LOG END------*/
4928 //search Content_Length result is OK
4931 //Get Content_Length header's numeric value
4932 for (pos = 0; recv_data.recive_buffer[it->send_offset + content_length_header_offset + pos] != ':' && pos
4933 < content_length_header_len; ++pos)
4935 if (pos == content_length_header_len)
4937 throw std::string("Content_Length field's value is invalid.");
4942 str_value.assign(recv_data.recive_buffer + it->send_offset + content_length_header_offset + pos,
4943 content_length_header_len - pos);
4945 size_t pos_end = str_value.find_last_of('\r');
4946 if (pos_end != std::string::npos)
4948 str_value = str_value.erase(pos_end);
4951 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos)
4954 str_value = str_value.substr(pos);
4958 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
4960 catch (const boost::bad_lexical_cast& ex)
4962 throw std::string("Content_Length field's value is invalid.");
4964 //send_rest_size recalc
4965 //set whole http header's length + Content_Length's value
4966 it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
4968 //search Content_Length result is NG
4971 //send_rest_size recalc
4972 //set whole http header's length
4973 it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
4976 //search http header result is NG
4979 it->unsend_size += request_data_remain_size;
4980 request_data_remain_size = 0;
4984 //check method and version result is NG
4985 else if (check_result == CHECK_NG)
4987 //send_rest_size recalc
4988 it->send_rest_size = it->unsend_size + request_data_remain_size;
4990 //check method and version result is CHECK_INPOSSIBLE
4993 it->unsend_size += request_data_remain_size;
4994 request_data_remain_size = 0;
4998 //recalc fields value according to send_rest_size and request rest size
4999 if (it->send_rest_size > it->unsend_size + request_data_remain_size)
5001 it->send_possible_size = it->unsend_size+ request_data_remain_size;
5002 it->send_rest_size -= (it->unsend_size + request_data_remain_size);
5003 it->send_end_size = 0;
5004 it->unsend_size = 0;
5005 request_data_remain_size = 0;
5009 it->send_possible_size = it->send_rest_size;
5010 request_data_remain_size = it->unsend_size + request_data_remain_size - it->send_rest_size;
5011 it->send_end_size = 0;
5012 it->unsend_size = 0;
5013 it->send_rest_size = 0;
5016 //change status from SEND_NG to SEND_OK
5017 it->status = SEND_OK;
5019 //no request rest data to process
5020 if (request_data_remain_size <= 0)
5026 /*-------- DEBUG LOG --------*/
5027 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5029 std::string datadump;
5030 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
5031 "send_rest_size = %d, send_possible_size = %d, "
5032 "send_offset = %d, unsend_size = %d, edit_division = %d.");
5034 for (it = recv_data.send_status_list.begin();
5035 it != recv_data.send_status_list.end();
5038 formatter % i % it->status % it->send_end_size
5039 % it->send_rest_size % it->send_possible_size
5040 % it->send_offset % it->unsend_size % it->edit_division;
5041 datadump += formatter.str();
5044 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5045 "handle_realserver_recv() : send status list dump : send status list size = %d.%s");
5047 formatter % recv_data.send_status_list.size() % datadump;
5048 putLogDebug(100170, formatter.str(), __FILE__, __LINE__ );
5050 /*------DEBUG LOG END------*/
5051 //there are still rest data need to process
5052 //new status created and add to status list
5053 while (request_data_remain_size > 0)
5055 //new status created
5056 send_status new_send_state;
5057 new_send_state.edit_division = EDIT_DIVISION_NO_EDIT;
5058 new_send_state.send_end_size = 0;
5059 new_send_state.send_offset = 0;
5060 new_send_state.send_possible_size = 0;
5061 new_send_state.unsend_size = 0;
5062 new_send_state.send_rest_size = 0;
5063 //status initialize to SEND_NG
5064 new_send_state.status = SEND_NG;
5065 //add new status to status_list
5066 recv_data.send_status_list.push_back(new_send_state);
5067 std::list<send_status>::reverse_iterator new_send_it = recv_data.send_status_list.rbegin();
5069 new_send_it->send_offset = recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size
5070 - request_data_remain_size;
5073 check_result = check_status_code(recv_data.recive_buffer + new_send_it->send_offset,
5074 request_data_remain_size);
5075 /*-------- DEBUG LOG --------*/
5076 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5078 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5079 "handle_realserver_recv() : call check_http_method : "
5080 "return_value = %d. thread id : %d.");
5081 formatter % check_result % boost::this_thread::get_id();
5082 putLogDebug(100171, formatter.str(), __FILE__, __LINE__ );
5084 /*------DEBUG LOG END------*/
5085 //check http method result is OK
5086 if (check_result == CHECK_OK)
5088 //check http version
5089 check_result = check_http_version(recv_data.recive_buffer + new_send_it->send_offset,
5090 request_data_remain_size);
5091 /*-------- DEBUG LOG --------*/
5092 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5094 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5095 "handle_realserver_recv() : call check_http_version : "
5096 "return_value = %d. thread id : %d.");
5097 formatter % check_result % boost::this_thread::get_id();
5098 putLogDebug(100172, formatter.str(), __FILE__, __LINE__ );
5100 /*------DEBUG LOG END------*/
5102 //check http method and version result is OK
5103 if (check_result == CHECK_OK)
5105 //search whole http header, get whole http header's offset and length
5106 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset, request_data_remain_size,
5107 http_header, header_offset, header_offset_len);
5108 /*-------- DEBUG LOG --------*/
5109 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5111 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5112 "handle_realserver_recv() : call find_http_header : "
5113 "return_value = %d. thread id : %d.");
5114 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
5115 putLogDebug(100173, formatter.str(), __FILE__, __LINE__ );
5117 /*------DEBUG LOG END------*/
5118 //searched whole http header
5121 //search ContentLength http header, get ContentLength header's offset and length
5122 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset,
5123 request_data_remain_size, content_header, content_length_header_offset, content_length_header_len);
5124 /*-------- DEBUG LOG --------*/
5125 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5127 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5128 "handle_realserver_recv() : call find_http_header : "
5129 "return_value = %d. thread id : %d.");
5130 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
5131 putLogDebug(100174, formatter.str(), __FILE__, __LINE__ );
5133 /*------DEBUG LOG END------*/
5135 //searched ContentLength http header
5138 //Get Content_Length header's numeric value
5139 for (pos = 0; recv_data.recive_buffer[new_send_it->send_offset + content_length_header_offset + pos] != ':'
5140 && pos < content_length_header_len; ++pos)
5142 if (pos == content_length_header_len)
5144 throw std::string("Content_Length field's value is invalid.");
5149 str_value.assign(recv_data.recive_buffer + new_send_it->send_offset + content_length_header_offset + pos,
5150 content_length_header_len - pos);
5152 size_t pos_end = str_value.find_last_of('\r');
5153 if (pos_end != std::string::npos)
5155 str_value = str_value.erase(pos_end);
5158 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos)
5161 str_value = str_value.substr(pos);
5164 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
5166 catch (const boost::bad_lexical_cast& ex)
5168 throw std::string("Content_Length field's value is invalid.");
5170 //send_rest_size recalc
5171 //set whole http header's + whole http header's length + Content_Length's value
5172 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
5174 //not searched ContentLength http header
5177 //send_rest_size recalc
5178 //set whole http header's + whole http header's length
5179 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
5182 //not searched whole http header
5185 new_send_it->unsend_size = request_data_remain_size;
5186 request_data_remain_size = 0;
5190 //check http method or version result is NG
5191 else if (check_result == CHECK_NG)
5193 new_send_it->send_rest_size = request_data_remain_size;
5195 //check http method or version result is impossible
5198 new_send_it->unsend_size = request_data_remain_size;
5199 request_data_remain_size = 0;
5203 //recalc fields value according to send_rest_size and request rest size
5204 if (new_send_it->send_rest_size > request_data_remain_size)
5206 new_send_it->send_possible_size = request_data_remain_size;
5207 new_send_it->send_rest_size -= request_data_remain_size;
5208 new_send_it->send_end_size = 0;
5209 new_send_it->send_end_size = 0;
5210 request_data_remain_size = 0;
5214 new_send_it->send_possible_size = new_send_it->send_rest_size;
5215 request_data_remain_size -= new_send_it->send_rest_size;
5216 new_send_it->send_end_size = 0;
5217 new_send_it->send_rest_size = 0;
5220 //change status from SEND_NG to SEND_OK
5221 new_send_it->status = SEND_OK;
5223 /*-------- DEBUG LOG --------*/
5224 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5226 std::string datadump;
5227 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
5228 "send_rest_size = %d, send_possible_size = %d, "
5229 "send_offset = %d, unsend_size = %d, edit_division = %d.");
5231 for (it = recv_data.send_status_list.begin();
5232 it != recv_data.send_status_list.end();
5235 formatter % i % it->status % it->send_end_size
5236 % it->send_rest_size % it->send_possible_size
5237 % it->send_offset % it->unsend_size % it->edit_division;
5238 datadump += formatter.str();
5241 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5242 "handle_realserver_recv() : send status list dump : send status list size = %d.%s");
5244 formatter % recv_data.send_status_list.size() % datadump;
5245 putLogDebug(100175, formatter.str(), __FILE__, __LINE__ );
5247 /*------DEBUG LOG END------*/
5249 //search for send_possible item in status list
5250 send_status_it it_find = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
5251 data_send_possible());
5252 //the data that can be sent possible is exist
5253 if (it_find != recv_data.send_status_list.end())
5255 status = CLIENT_CONNECTION_CHECK;
5257 //the data that can be sent possible is not exist
5260 status = REALSERVER_RECV;
5265 /*-------- DEBUG LOG --------*/
5266 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5268 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5269 "handle_realserver_recv() : catch exception e = %d. thread id : %d.");
5270 formatter % e % boost::this_thread::get_id();
5271 putLogDebug(100176, formatter.str(), __FILE__, __LINE__ );
5273 /*------DEBUG LOG END------*/
5276 catch (const std::string& ex)
5278 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : exception : " << ex << std::endl;
5279 boost::format formatter("protocol_module_sessionless::handle_realserver_recv() : exception : %s. thread id : %d.");
5280 formatter % ex.c_str() % boost::this_thread::get_id();
5281 putLogError(100086, formatter.str(), __FILE__, __LINE__ );
5284 catch (const std::bad_alloc&)
5286 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : exception : Could not allocate memory." << std::endl;
5287 boost::format formatter("Could not allocate memory. thread id : %d.");
5288 formatter % boost::this_thread::get_id();
5289 putLogError(100087, formatter.str(), __FILE__, __LINE__ );
5292 catch (const std::exception& ex)
5294 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : exception : error = " << ex.what() << "." << std::endl;
5295 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5296 "handle_realserver_recv() : exception : error = %s. thread id : %d.");
5297 formatter % ex.what() % boost::this_thread::get_id();
5298 putLogError(100088, formatter.str(), __FILE__, __LINE__ );
5304 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : Unknown exception." << std::endl;
5305 boost::format formatter("function : protocol_module_base::EVENT_TAG "
5306 "protocol_module_sessionless::handle_realserver_recv() : "
5307 "Unknown exception. thread id : %d.");
5308 formatter % boost::this_thread::get_id();
5309 putLogError(100089, formatter.str(), __FILE__, __LINE__ );
5313 /*-------- DEBUG LOG --------*/
5314 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5316 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5317 "handle_realserver_recv(const boost::thread::id thread_id, "
5318 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
5319 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5320 "const size_t recvlen) : return_value = %d. thread id : %d.");
5321 formatter % status % boost::this_thread::get_id();
5322 putLogDebug(100177, formatter.str(), __FILE__, __LINE__ );
5324 /*------DEBUG LOG END------*/
5331 //! called from after sorryserver recive
5332 //! @param[in] downstream thread id
5333 //! @param[in] sorryserver endpoint reference
5334 //! @param[in] recive from realserver buffer reference.
5335 //! @param[in] recv data length
5336 //! @return session use EVENT mode
5337 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_recv(
5338 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint& sorry_endpoint, const boost::array<
5339 char, MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
5341 /*-------- DEBUG LOG --------*/
5342 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5344 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
5346 dump_memory(recvbuffer.data(), buffer_size, buffer);
5347 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5348 "handle_sorryserver_recv(const boost::thread::id thread_id, "
5349 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
5350 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5351 "const size_t recvlen) : thread_id = %d, sorry_endpoint = [%s]:%d, recvbuffer = %s, recvlen = %d.");
5352 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port()
5354 putLogDebug(100178, formatter.str(), __FILE__, __LINE__ );
5356 /*------DEBUG LOG END------*/
5358 EVENT_TAG status = FINALIZE;
5359 size_t data_remain_start = 0;
5360 size_t data_remain_size = 0;
5361 size_t request_data_remain_size = 0;
5362 size_t header_offset = 0;
5363 size_t header_offset_len = 0;
5364 size_t content_length_header_offset = 0;
5365 size_t content_length_header_len = 0;
5366 size_t content_len_value = 0;
5368 size_t buffer_size = 0;
5369 const size_t cr_lf_len = strlen("\r\n\r\n");
5370 std::string str_value;
5371 const std::string http_header = "";
5372 const std::string content_header = "Content-Length";
5373 thread_data_ptr session_data;
5374 char* buffer1 = NULL;
5375 char* buffer2 = NULL;
5377 CHECK_RESULT_TAG check_result;
5378 session_thread_data_map_it session_thread_it;
5379 recive_data_map_it recive_data_it;
5382 if (recvlen > recvbuffer.size())
5384 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : Data size bigger than buffer size." << std::endl;
5385 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
5386 formatter % boost::this_thread::get_id();
5387 putLogError(100090, formatter.str(), __FILE__,
5389 /*-------- DEBUG LOG --------*/
5390 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5392 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5393 "handle_sorryserver_recv(const boost::thread::id thread_id, "
5394 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
5395 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5396 "const size_t recvlen) : return_value = %d. thread id : %d.");
5397 formatter % FINALIZE % boost::this_thread::get_id();
5398 putLogDebug(100179, formatter.str(), __FILE__, __LINE__ );
5400 /*------DEBUG LOG END------*/
5407 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
5409 session_thread_it = session_thread_data_map.find(thread_id);
5410 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
5412 boost::format formatter("Invalid thread id. thread id : %d.");
5413 formatter % boost::this_thread::get_id();
5414 putLogError(100091, formatter.str(), __FILE__, __LINE__ );
5418 session_data = session_thread_it->second;
5421 recive_data_it = session_data->recive_data_map.find(sorry_endpoint);
5422 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
5424 recive_data recv_data;
5425 session_data->recive_data_map[sorry_endpoint] = recv_data;
5428 session_data->target_endpoint = sorry_endpoint;
5430 recive_data& recv_data = session_data->recive_data_map[sorry_endpoint];
5433 send_status_it it = recv_data.send_status_list.begin();
5434 send_status_it it_end = recv_data.send_status_list.end();
5435 it = std::find_if(it, it_end, data_send_ok());
5436 if (unlikely(it != it_end))
5438 boost::format formatter("Sending data is invalid. thread id : %d.");
5439 formatter % boost::this_thread::get_id();
5440 putLogError(100092, formatter.str(), __FILE__, __LINE__ );
5445 it = recv_data.send_status_list.begin();
5446 it = std::adjacent_find(it, it_end, data_send_repeated());
5447 if (unlikely(it != it_end))
5449 boost::format formatter("Sending data is invalid. thread id : %d.");
5450 formatter % boost::this_thread::get_id();
5451 putLogError(100093, formatter.str(), __FILE__, __LINE__ );
5455 /*-------- DEBUG LOG --------*/
5456 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5458 std::string datadump;
5459 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
5460 "send_rest_size = %d, send_possible_size = %d, "
5461 "send_offset = %d, unsend_size = %d, edit_division = %d.");
5463 for (it = recv_data.send_status_list.begin();
5464 it != recv_data.send_status_list.end();
5467 formatter % i % it->status % it->send_end_size
5468 % it->send_rest_size % it->send_possible_size
5469 % it->send_offset % it->unsend_size % it->edit_division;
5470 datadump += formatter.str();
5473 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5474 "handle_sorryserver_recv() : send status list dump : send status list size = %d.%s");
5476 formatter % recv_data.send_status_list.size() % datadump;
5477 putLogDebug(100180, formatter.str(), __FILE__, __LINE__ );
5479 /*------DEBUG LOG END------*/
5481 it = recv_data.send_status_list.begin();
5482 //get original status info
5483 while (it != it_end)
5485 //item status is SEND_END
5486 if (it->status == SEND_END)
5489 recv_data.send_status_list.erase(it++);
5492 //item status is SEND_CONTINUE
5493 else if (it->status == SEND_CONTINUE)
5495 it->send_offset += it->send_end_size;
5496 data_remain_start = it->send_offset;
5499 //item status is SEND_NG
5502 data_remain_start = it->send_offset;
5503 data_remain_size = it->unsend_size;
5509 /*-------- DEBUG LOG --------*/
5510 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5512 std::string datadump;
5513 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
5514 "send_rest_size = %d, send_possible_size = %d, "
5515 "send_offset = %d, unsend_size = %d, edit_division = %d.");
5517 for (it = recv_data.send_status_list.begin();
5518 it != recv_data.send_status_list.end();
5521 formatter % i % it->status % it->send_end_size
5522 % it->send_rest_size % it->send_possible_size
5523 % it->send_offset % it->unsend_size % it->edit_division;
5524 datadump += formatter.str();
5527 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5528 "handle_sorryserver_recv() : send status list dump : send status list size = %d.%s");
5530 formatter % recv_data.send_status_list.size() % datadump;
5531 putLogDebug(100181, formatter.str(), __FILE__, __LINE__ );
5533 /*------DEBUG LOG END------*/
5534 //recive buffer process
5535 //buffer rest size < request size
5536 if (recv_data.recive_buffer_rest_size < recvlen)
5538 //buffer max size < remain size + request size
5539 //buffer is need reallocate
5540 if (recv_data.recive_buffer_max_size < data_remain_size + recvlen)
5542 //the buffer's size that will be allocated is exceed the upper limit value
5543 if (MAX_SESSIONLESS_MODULE_BUFFER_SIZE < data_remain_size + recvlen)
5545 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : the buffer's size that will be allacted is exceed the upper limit value." << std::endl;
5546 boost::format formatter("The buffer's size that will be allocated is exceed the upper limit value. thread id : %d.");
5547 formatter % boost::this_thread::get_id();
5548 putLogError(100094, formatter.str(), __FILE__, __LINE__ );
5549 /*-------- DEBUG LOG --------*/
5550 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5552 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5553 "handle_sorryserver_recv(const boost::thread::id thread_id, "
5554 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
5555 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5556 "const size_t recvlen) : return_value = %d. thread id : %d.");
5557 formatter % FINALIZE % boost::this_thread::get_id();
5558 putLogDebug(100182, formatter.str(), __FILE__, __LINE__ );
5560 /*------DEBUG LOG END------*/
5563 //recive_buffer1's memory allocate and initialization
5564 buffer_size = (data_remain_size + recvlen) > MAX_BUFFER_SIZE ? (data_remain_size + recvlen) : MAX_BUFFER_SIZE;
5565 buffer1 = new char[buffer_size];
5566 /*-------- DEBUG LOG --------*/
5567 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5569 boost::format formatter("new : address = &(%d), size = %lu.");
5570 formatter % static_cast<void*>(buffer1) % buffer_size;
5571 putLogDebug(100183, formatter.str(), __FILE__, __LINE__ );
5573 /*-------- DEBUG LOG END--------*/
5574 memset(buffer1, 0, buffer_size);
5575 //recive_buffer2's memory allocate and initialization
5576 buffer2 = new char[buffer_size];
5577 /*-------- DEBUG LOG --------*/
5578 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5580 boost::format formatter("new : address = &(%d), size = %lu.");
5581 formatter % static_cast<void*>(buffer2) % buffer_size;
5582 putLogDebug(100184, formatter.str(), __FILE__, __LINE__ );
5584 /*-------- DEBUG LOG END--------*/
5585 memset(buffer2, 0, buffer_size);
5587 /*-------- DEBUG LOG --------*/
5588 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5590 std::string datadump;
5591 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
5592 boost::format formatter(
5593 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5594 "handle_sorryserver_recv() : before memcpy (data dump) : "
5595 "data begin = %d, data_size = %d, data = %s");
5596 formatter % data_remain_start % data_remain_size % datadump;
5597 putLogDebug(100185, formatter.str(), __FILE__, __LINE__ );
5599 /*------DEBUG LOG END------*/
5600 //copy data from old buffer to new buffer
5601 memcpy(buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
5602 /*-------- DEBUG LOG --------*/
5603 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5605 std::string datadump;
5606 dump_memory(buffer1, data_remain_size, datadump);
5607 boost::format formatter(
5608 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5609 "handle_sorryserver_recv() : after memcpy (data dump) : "
5610 "data begin = 0, data_size = %d, data = %s");
5611 formatter % data_remain_size % datadump;
5612 putLogDebug(100186, formatter.str(), __FILE__, __LINE__ );
5614 /*------DEBUG LOG END------*/
5616 /*-------- DEBUG LOG --------*/
5617 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5619 std::string datadump;
5620 dump_memory(recvbuffer.data(), recvlen, datadump);
5621 boost::format formatter(
5622 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5623 "handle_sorryserver_recv() : before memcpy (data dump) : "
5624 "data begin = 0, data_size = %d, data = %s");
5625 formatter % recvlen % datadump;
5626 putLogDebug(100187, formatter.str(), __FILE__, __LINE__ );
5628 /*------DEBUG LOG END------*/
5629 memcpy(buffer1 + data_remain_size, recvbuffer.data(), recvlen);
5630 /*-------- DEBUG LOG --------*/
5631 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5633 std::string datadump;
5634 dump_memory(buffer1 + data_remain_size, recvlen, datadump);
5635 boost::format formatter(
5636 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5637 "handle_sorryserver_recv() : after memcpy (data dump) : "
5638 "data begin = %d, data_size = %d, data = %s");
5639 formatter % data_remain_size % recvlen % datadump;
5640 putLogDebug(100188, formatter.str(), __FILE__, __LINE__ );
5642 /*------DEBUG LOG END------*/
5643 //free old buffer1 and old buffer2
5644 if (recv_data.recive_buffer1 != NULL)
5646 /*-------- DEBUG LOG --------*/
5647 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5649 boost::format formatter("delete : address = &(%d).");
5650 formatter % static_cast<void*>(recv_data.recive_buffer1);
5651 putLogDebug(100189, formatter.str(), __FILE__,
5654 /*------DEBUG LOG END------*/
5655 delete[] recv_data.recive_buffer1;
5656 recv_data.recive_buffer1 = NULL;
5659 if (recv_data.recive_buffer2 != NULL)
5661 /*-------- DEBUG LOG --------*/
5662 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5664 boost::format formatter("delete : address = &(%d).");
5665 formatter % static_cast<void*>(recv_data.recive_buffer2);
5666 putLogDebug(100190, formatter.str(), __FILE__,
5669 /*------DEBUG LOG END------*/
5670 delete[] recv_data.recive_buffer2;
5671 recv_data.recive_buffer2 = NULL;
5674 //set new buffer pointer
5675 recv_data.recive_buffer1 = buffer1;
5676 recv_data.recive_buffer2 = buffer2;
5677 recv_data.recive_buffer = recv_data.recive_buffer1;
5678 //set new buffer's max size
5679 recv_data.recive_buffer_max_size = buffer_size;
5681 //buffer's max size >= remain data size + requst size
5682 //buffer isn't need reallocate, but switch
5685 //pointer valid check
5686 if (unlikely(recv_data.recive_buffer1 == NULL || recv_data.recive_buffer2 == NULL))
5688 boost::format formatter("Invalid pointer. thread id : %d.");
5689 formatter % boost::this_thread::get_id();
5690 putLogError(100095, formatter.str(), __FILE__, __LINE__ );
5693 //using buffer is buffer1
5694 if (recv_data.recive_buffer == recv_data.recive_buffer1)
5696 //buffer2 initialization
5697 memset(recv_data.recive_buffer2, 0, recv_data.recive_buffer_max_size);
5698 /*-------- DEBUG LOG --------*/
5699 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5701 std::string datadump;
5702 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
5703 boost::format formatter(
5704 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5705 "handle_sorryserver_recv() : before memcpy (data dump) : "
5706 "data begin = %d, data_size = %d, data = %s");
5707 formatter % data_remain_start % data_remain_size % datadump;
5708 putLogDebug(100191, formatter.str(), __FILE__, __LINE__ );
5710 /*------DEBUG LOG END------*/
5711 //copy data from buffer1 to buffer2
5712 memcpy(recv_data.recive_buffer2, recv_data.recive_buffer + data_remain_start, data_remain_size);
5713 /*-------- DEBUG LOG --------*/
5714 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5716 std::string datadump;
5717 dump_memory(recv_data.recive_buffer2, data_remain_size, datadump);
5718 boost::format formatter(
5719 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5720 "handle_sorryserver_recv() : after memcpy (data dump) : "
5721 "data begin = 0, data_size = %d, data = %s");
5722 formatter % data_remain_size % datadump;
5723 putLogDebug(100192, formatter.str(), __FILE__, __LINE__ );
5725 /*------DEBUG LOG END------*/
5726 /*-------- DEBUG LOG --------*/
5727 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5729 std::string datadump;
5730 dump_memory(recvbuffer.data(), recvlen, datadump);
5731 boost::format formatter(
5732 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5733 "handle_sorryserver_recv() : before memcpy (data dump) : "
5734 "data begin = 0, data_size = %d, data = %s");
5735 formatter % recvlen % datadump;
5736 putLogDebug(100193, formatter.str(), __FILE__, __LINE__ );
5738 /*------DEBUG LOG END------*/
5739 memcpy(recv_data.recive_buffer2 + data_remain_size, recvbuffer.data(), recvlen);
5740 /*-------- DEBUG LOG --------*/
5741 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5743 std::string datadump;
5744 dump_memory(recv_data.recive_buffer2 + data_remain_size, recvlen, datadump);
5745 boost::format formatter(
5746 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5747 "handle_sorryserver_recv() : after memcpy (data dump) : "
5748 "data begin = %d, data_size = %d, data = %s");
5749 formatter % data_remain_size % recvlen % datadump;
5750 putLogDebug(100194, formatter.str(), __FILE__, __LINE__ );
5752 /*------DEBUG LOG END------*/
5753 //set buffer2 as using buffer
5754 recv_data.recive_buffer = recv_data.recive_buffer2;
5756 //using buffer is buffer2
5759 //buffer1 initializtion
5760 memset(recv_data.recive_buffer1, 0, recv_data.recive_buffer_max_size);
5761 /*-------- DEBUG LOG --------*/
5762 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5764 std::string datadump;
5765 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, 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 = %d, data_size = %d, data = %s");
5770 formatter % data_remain_start % data_remain_size % datadump;
5771 putLogDebug(100195, formatter.str(), __FILE__, __LINE__ );
5773 /*------DEBUG LOG END------*/
5774 //copy data from buffer2 to buffer1
5775 memcpy(recv_data.recive_buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
5776 /*-------- DEBUG LOG --------*/
5777 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5779 std::string datadump;
5780 dump_memory(recv_data.recive_buffer1, data_remain_size, datadump);
5781 boost::format formatter(
5782 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5783 "handle_sorryserver_recv() : after memcpy (data dump) : "
5784 "data begin = 0, data_size = %d, data = %s");
5785 formatter % data_remain_size % datadump;
5786 putLogDebug(100196, formatter.str(), __FILE__, __LINE__ );
5788 /*------DEBUG LOG END------*/
5790 /*-------- DEBUG LOG --------*/
5791 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5793 std::string datadump;
5794 dump_memory(recvbuffer.data(), recvlen, datadump);
5795 boost::format formatter(
5796 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5797 "handle_sorryserver_recv() : before memcpy (data dump) : "
5798 "data begin = 0, data_size = %d, data = %s");
5799 formatter % recvlen % datadump;
5800 putLogDebug(100197, formatter.str(), __FILE__, __LINE__ );
5802 /*------DEBUG LOG END------*/
5803 memcpy(recv_data.recive_buffer1 + data_remain_size, recvbuffer.data(), recvlen);
5804 /*-------- DEBUG LOG --------*/
5805 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5807 std::string datadump;
5808 dump_memory(recv_data.recive_buffer1 + data_remain_size, recvlen, datadump);
5809 boost::format formatter(
5810 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5811 "handle_sorryserver_recv() : after memcpy (data dump) : "
5812 "data begin = %d, data_size = %d, data = %s");
5813 formatter % data_remain_size % recvlen % datadump;
5814 putLogDebug(100198, formatter.str(), __FILE__, __LINE__ );
5816 /*------DEBUG LOG END------*/
5817 //set buffer1 as using buffer
5818 recv_data.recive_buffer = recv_data.recive_buffer1;
5822 //set buffer's rest size
5823 recv_data.recive_buffer_rest_size = recv_data.recive_buffer_max_size - data_remain_size - recvlen;
5825 //remain_size recalc
5826 data_remain_size += recvlen;
5828 send_status_it it_begin = recv_data.send_status_list.begin();
5829 send_status_it it_end = recv_data.send_status_list.end();
5831 for (; it_begin != it_end; ++it_begin)
5833 it_begin->send_offset -= data_remain_start;
5836 //buffer's rest size >= request size
5840 //pointer valid check
5841 if (unlikely(recv_data.recive_buffer == NULL))
5843 boost::format formatter("Invalid pointer. thread id : %d");
5844 formatter % boost::this_thread::get_id();
5845 putLogError(100096, formatter.str(), __FILE__, __LINE__ );
5848 /*-------- DEBUG LOG --------*/
5849 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5851 std::string datadump;
5852 dump_memory(recvbuffer.data(), recvlen, datadump);
5853 boost::format formatter(
5854 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5855 "handle_sorryserver_recv() : before memcpy (data dump) : "
5856 "data begin = 0, data_size = %d, data = %s");
5857 formatter % recvlen % datadump;
5858 putLogDebug(100199, formatter.str(), __FILE__, __LINE__ );
5860 /*------DEBUG LOG END------*/
5862 //copy data from parameter to using buffer
5863 memcpy(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
5864 recvbuffer.data(), recvlen);
5865 /*-------- DEBUG LOG --------*/
5866 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5868 std::string datadump;
5869 dump_memory(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size, recvlen, datadump);
5870 boost::format formatter(
5871 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5872 "handle_sorryserver_recv() : after memcpy (data dump) : "
5873 "data begin = %d, data_size = %d, data = %s");
5874 formatter % (recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size) % recvlen % datadump;
5875 putLogDebug(100200, formatter.str(), __FILE__, __LINE__ );
5877 /*------DEBUG LOG END------*/
5878 //buffer's rest size recalc
5879 recv_data.recive_buffer_rest_size -= recvlen;
5880 //remain data size recalc
5881 data_remain_size += recvlen;
5884 it = recv_data.send_status_list.begin();
5885 it_end = recv_data.send_status_list.end();
5886 //request rest size initialization
5887 request_data_remain_size = recvlen;
5888 //original status process
5889 for (; it != it_end; ++it)
5891 //status is SEND_CONTINUE
5892 if (it->status == SEND_CONTINUE)
5895 if (it->send_rest_size > request_data_remain_size)
5897 it->send_possible_size = request_data_remain_size;
5898 it->send_rest_size -= request_data_remain_size;
5899 it->send_end_size = 0;
5900 request_data_remain_size = 0;
5904 it->send_possible_size = it->send_rest_size;
5905 request_data_remain_size -= it->send_rest_size;
5906 it->send_end_size = 0;
5907 it->send_rest_size = 0;
5910 //change status from SEND_CONTINUE to SEND_OK
5911 it->status = SEND_OK;
5914 else if (it->status == SEND_NG)
5917 check_result = check_status_code(recv_data.recive_buffer + it->send_offset, data_remain_size);
5918 /*-------- DEBUG LOG --------*/
5919 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5921 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5922 "handle_sorryserver_recv() : call check_status_code : "
5923 "return_value = %d. thread id : %d.");
5924 formatter % check_result % boost::this_thread::get_id();
5925 putLogDebug(100201, formatter.str(), __FILE__, __LINE__ );
5927 /*------DEBUG LOG END------*/
5928 //check http method result is OK
5929 if (check_result == CHECK_OK)
5931 //check http version
5932 check_result = check_http_version(recv_data.recive_buffer + it->send_offset, data_remain_size);
5933 /*-------- DEBUG LOG --------*/
5934 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5936 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5937 "handle_sorryserver_recv() : call check_http_version : "
5938 "return_value = %d. thread id : %d.");
5939 formatter % check_result % boost::this_thread::get_id();
5940 putLogDebug(100202, formatter.str(), __FILE__, __LINE__ );
5942 /*------DEBUG LOG END------*/
5944 //check method and version result is OK
5945 if (check_result == CHECK_OK)
5947 //search http header
5948 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size, http_header,
5949 header_offset, header_offset_len);
5950 /*-------- DEBUG LOG --------*/
5951 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5953 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5954 "handle_sorryserver_recv() : call find_http_header : "
5955 "return_value = %d. thread id : %d.");
5956 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
5957 putLogDebug(100203, formatter.str(), __FILE__, __LINE__ );
5959 /*------DEBUG LOG END------*/
5960 //search http header result is OK
5963 //search Content_Length header
5964 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size,
5965 content_header, content_length_header_offset, content_length_header_len);
5966 /*-------- DEBUG LOG --------*/
5967 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5969 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5970 "handle_sorryserver_recv() : call find_http_header : "
5971 "return_value = %d. thread id : %d.");
5972 formatter % static_cast<int>(bret) %boost::this_thread::get_id();
5973 putLogDebug(100204, formatter.str(), __FILE__, __LINE__ );
5975 /*------DEBUG LOG END------*/
5976 //search Content_Length result is OK
5979 //Get Content_Length header's numeric value
5980 for (pos = 0; recv_data.recive_buffer[it->send_offset + content_length_header_offset + pos] != ':' && pos
5981 < content_length_header_len; ++pos)
5983 if (pos == content_length_header_len)
5985 throw std::string("Content_Length field's value is invalid.");
5990 str_value.assign(recv_data.recive_buffer + it->send_offset + content_length_header_offset + pos,
5991 content_length_header_len - pos);
5993 size_t pos_end = str_value.find_last_of('\r');
5994 if (pos_end != std::string::npos)
5996 str_value = str_value.erase(pos_end);
5999 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos)
6002 str_value = str_value.substr(pos);
6006 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
6008 catch (const boost::bad_lexical_cast& ex)
6010 throw std::string("Content_Length field's value is invalid.");
6012 //send_rest_size recalc
6013 //set whole http header's length + Content_Length's value
6014 it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
6016 //search Content_Length result is NG
6019 //send_rest_size recalc
6020 //set whole http header's length
6021 it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
6024 //search http header result is NG
6027 it->unsend_size += request_data_remain_size;
6028 request_data_remain_size = 0;
6032 //check method or version result is NG
6033 else if (check_result == CHECK_NG)
6035 it->send_rest_size = it->unsend_size+request_data_remain_size;
6037 //check method and version result is CHECK_INPOSSIBLE
6040 it->unsend_size += request_data_remain_size;
6041 request_data_remain_size = 0;
6045 //recalc fields value according to send_rest_size and request rest size
6046 if (it->send_rest_size > it->unsend_size + request_data_remain_size)
6048 it->send_possible_size = it->unsend_size + request_data_remain_size;
6049 it->send_rest_size -= (it->unsend_size + request_data_remain_size);
6050 it->send_end_size = 0;
6051 it->unsend_size = 0;
6052 request_data_remain_size = 0;
6056 it->send_possible_size = it->send_rest_size;
6057 request_data_remain_size = it->unsend_size + request_data_remain_size - it->send_rest_size;
6058 it->send_end_size = 0;
6059 it->unsend_size = 0;
6060 it->send_rest_size = 0;
6063 //change status from SEND_NG to SEND_OK
6064 it->status = SEND_OK;
6066 //no request rest data to process
6067 if (request_data_remain_size <= 0)
6072 /*-------- DEBUG LOG --------*/
6073 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6075 std::string datadump;
6076 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
6077 "send_rest_size = %d, send_possible_size = %d, "
6078 "send_offset = %d, unsend_size = %d, edit_division = %d.");
6080 for (it = recv_data.send_status_list.begin();
6081 it != recv_data.send_status_list.end();
6084 formatter % i % it->status % it->send_end_size
6085 % it->send_rest_size % it->send_possible_size
6086 % it->send_offset % it->unsend_size % it->edit_division;
6087 datadump += formatter.str();
6090 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6091 "handle_sorryserver_recv() : send status list dump : send status list size = %d.%s");
6093 formatter % recv_data.send_status_list.size() % datadump;
6094 putLogDebug(100205, formatter.str(), __FILE__, __LINE__ );
6096 /*------DEBUG LOG END------*/
6098 //there are still rest data need to process
6099 //new status created and add to status list
6100 while (request_data_remain_size > 0)
6102 //new status created
6103 send_status new_send_state;
6104 new_send_state.edit_division = EDIT_DIVISION_NO_EDIT;
6105 new_send_state.send_end_size = 0;
6106 new_send_state.send_offset = 0;
6107 new_send_state.send_possible_size = 0;
6108 new_send_state.unsend_size = 0;
6109 new_send_state.send_rest_size = 0;
6110 //status initialize to SEND_NG
6111 new_send_state.status = SEND_NG;
6112 //add new status to status_list
6113 recv_data.send_status_list.push_back(new_send_state);
6114 std::list<send_status>::reverse_iterator new_send_it = recv_data.send_status_list.rbegin();
6116 new_send_it->send_offset = recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size
6117 - request_data_remain_size;
6120 check_result = check_status_code(recv_data.recive_buffer + new_send_it->send_offset,
6121 request_data_remain_size);
6122 /*-------- DEBUG LOG --------*/
6123 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6125 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6126 "handle_sorryserver_recv() : call check_status_code : "
6127 "return_value = %d. thread id : %d.");
6128 formatter % check_result % boost::this_thread::get_id();
6129 putLogDebug(100206, formatter.str(), __FILE__, __LINE__ );
6131 /*------DEBUG LOG END------*/
6132 //check http method result is OK
6133 if (check_result == CHECK_OK)
6135 //check http version
6136 check_result = check_http_version(recv_data.recive_buffer + new_send_it->send_offset,
6137 request_data_remain_size);
6138 /*-------- DEBUG LOG --------*/
6139 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6141 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6142 "handle_sorryserver_recv() : call check_http_version : "
6143 "return_value = %d. thread id : %d.");
6144 formatter % check_result % boost::this_thread::get_id();
6145 putLogDebug(100207, formatter.str(), __FILE__, __LINE__ );
6147 /*------DEBUG LOG END------*/
6149 //check http method and version result is OK
6150 if (check_result == CHECK_OK)
6152 //search whole http header, get whole http header's offset and length
6153 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset, request_data_remain_size,
6154 http_header, header_offset, header_offset_len);
6155 /*-------- DEBUG LOG --------*/
6156 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6158 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6159 "handle_sorryserver_recv() : call find_http_header : "
6160 "return_value = %d. thread id : %d.");
6161 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
6162 putLogDebug(100208, formatter.str(), __FILE__, __LINE__ );
6164 /*------DEBUG LOG END------*/
6165 //searched whole http header
6168 //search ContentLength http header, get ContentLength header's offset and length
6169 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset,
6170 request_data_remain_size, content_header, content_length_header_offset, content_length_header_len);
6171 /*-------- DEBUG LOG --------*/
6172 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6174 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6175 "handle_sorryserver_recv() : call find_http_header : "
6176 "return_value = %d. thread id : %d.");
6177 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
6178 putLogDebug(100209, formatter.str(), __FILE__, __LINE__ );
6180 /*------DEBUG LOG END------*/
6182 //searched ContentLength http header
6185 //Get Content_Length header's numeric value
6186 for (pos = 0; recv_data.recive_buffer[new_send_it->send_offset + content_length_header_offset + pos] != ':'
6187 && pos < content_length_header_len; ++pos)
6189 if (pos == content_length_header_len)
6191 throw std::string("Content_Length field's value is invalid.");
6195 str_value.assign(recv_data.recive_buffer + new_send_it->send_offset + content_length_header_offset + pos,
6196 content_length_header_len - pos);
6198 size_t pos_end = str_value.find_last_of('\r');
6199 if (pos_end != std::string::npos)
6201 str_value = str_value.erase(pos_end);
6204 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos)
6207 str_value = str_value.substr(pos);
6210 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
6212 catch (const boost::bad_lexical_cast& ex)
6214 throw std::string("Content_Length field's value is invalid.");
6216 //send_rest_size recalc
6217 //set whole http header's + whole http header's length + Content_Length's value
6218 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
6220 //not searched ContentLength http header
6223 //send_rest_size recalc
6224 //set whole http header's + whole http header's length
6225 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
6228 //not searched whole http header
6231 new_send_it->unsend_size = request_data_remain_size;
6232 request_data_remain_size = 0;
6236 //check http method or version result is NG
6237 else if (check_result == CHECK_NG)
6239 new_send_it->send_rest_size = request_data_remain_size;
6241 //check http method or version result is impossible
6244 new_send_it->unsend_size = request_data_remain_size;
6245 request_data_remain_size = 0;
6249 //recalc fields value according to send_rest_size and request rest size
6250 if (new_send_it->send_rest_size > request_data_remain_size)
6252 new_send_it->send_possible_size = request_data_remain_size;
6253 new_send_it->send_rest_size -= request_data_remain_size;
6254 new_send_it->send_end_size = 0;
6255 request_data_remain_size = 0;
6259 new_send_it->send_possible_size = new_send_it->send_rest_size;
6260 request_data_remain_size -= new_send_it->send_rest_size;
6261 new_send_it->send_end_size = 0;
6262 new_send_it->send_rest_size = 0;
6265 //change status from SEND_NG to SEND_OK
6266 new_send_it->status = SEND_OK;
6268 /*-------- DEBUG LOG --------*/
6269 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6271 std::string datadump;
6272 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
6273 "send_rest_size = %d, send_possible_size = %d, "
6274 "send_offset = %d, unsend_size = %d, edit_division = %d.");
6276 for (it = recv_data.send_status_list.begin();
6277 it != recv_data.send_status_list.end();
6280 formatter % i % it->status % it->send_end_size
6281 % it->send_rest_size % it->send_possible_size
6282 % it->send_offset % it->unsend_size % it->edit_division;
6283 datadump += formatter.str();
6286 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6287 "handle_sorryserver_recv() : send status list dump : send status list size = %d.%s");
6289 formatter % recv_data.send_status_list.size() % datadump;
6290 putLogDebug(100210, formatter.str(), __FILE__, __LINE__ );
6292 /*------DEBUG LOG END------*/
6294 //search for send_possible item in status list
6295 send_status_it it_find = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
6296 data_send_possible());
6297 //the data that can be sent possible is exist
6298 if (it_find != recv_data.send_status_list.end())
6300 status = CLIENT_CONNECTION_CHECK;
6302 //the data that can be sent possible is not exist
6305 status = SORRYSERVER_RECV;
6310 /*-------- DEBUG LOG --------*/
6311 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6313 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6314 "handle_sorryserver_recv() : catch exception e = %d. thread id : %d.");
6315 formatter % e % boost::this_thread::get_id();
6316 putLogDebug(100211, formatter.str(), __FILE__, __LINE__ );
6318 /*------DEBUG LOG END------*/
6321 catch (const std::string& ex)
6323 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : exception : " << ex << std::endl;
6324 boost::format formatter("protocol_module_sessionless::handle_sorryserver_recv() : exception : %s. thread id : %d.");
6325 formatter % ex.c_str() % boost::this_thread::get_id();
6326 putLogError(100097, formatter.str(), __FILE__, __LINE__ );
6329 catch (const std::bad_alloc&)
6331 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : exception : Could not allocate memory." << std::endl;
6332 boost::format formatter("Could not allocate memory. thread id : %d.");
6333 formatter % boost::this_thread::get_id();
6334 putLogError(100098, formatter.str(), __FILE__, __LINE__ );
6337 catch (const std::exception& ex)
6339 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : exception : error = " << ex.what() << "." << std::endl;
6340 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6341 "handle_sorryserver_recv() : exception : error = %s. thread id : %d.");
6342 formatter % ex.what() % boost::this_thread::get_id();
6343 putLogError(100099, formatter.str(), __FILE__, __LINE__ );
6349 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : Unknown exception." << std::endl;
6350 boost::format formatter("function : protocol_module_base::EVENT_TAG "
6351 "protocol_module_sessionless::handle_sorryserver_recv() : "
6352 "Unknown exception. thread id : %d.");
6353 formatter % boost::this_thread::get_id();
6354 putLogError(100100, formatter.str(), __FILE__, __LINE__ );
6358 /*-------- DEBUG LOG --------*/
6359 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6361 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6362 "handle_sorryserver_recv(const boost::thread::id thread_id, "
6363 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
6364 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
6365 "const size_t recvlen) : return_value = %d. thread id : %d.");
6366 formatter % status % boost::this_thread::get_id();
6367 putLogDebug(100212, formatter.str(), __FILE__, __LINE__ );
6369 /*------DEBUG LOG END------*/
6374 //! called from UPSTEEARM thread. make module original message.
6375 //! @param[in] downstream thread id.
6376 //! @return session use EVENT mode
6377 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_response_send_inform(
6378 const boost::thread::id thread_id)
6380 /*-------- DEBUG LOG --------*/
6381 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6383 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6384 "handle_response_send_inform(const boost::thread::id thread_id) : "
6385 "return_value = %d. thread id : %d.");
6386 formatter % STOP % boost::this_thread::get_id();
6387 putLogDebug(100213, formatter.str(), __FILE__, __LINE__ );
6389 /*------DEBUG LOG END------*/
6393 //! called from after client connection check. use TCP/IP only. create client send message.
6394 //! @param[in] downstream thread id
6395 //! @param[out] send budffer reference
6396 //! @param[out] send data length
6397 //! @return session use EVENT mode
6398 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_connection_check(
6399 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
6402 /*-------- DEBUG LOG --------*/
6403 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6405 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6406 "handle_client_connection_check(const boost::thread::id thread_id, "
6407 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
6409 formatter % thread_id;
6410 putLogDebug(100214, formatter.str(), __FILE__, __LINE__ );
6412 /*------DEBUG LOG END------*/
6414 EVENT_TAG status = FINALIZE;
6415 size_t send_buffer_size = sendbuffer.max_size();
6416 thread_data_ptr session_data;
6417 session_thread_data_map_it session_thread_it;
6418 recive_data_map_it recive_data_it;
6423 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
6425 session_thread_it = session_thread_data_map.find(thread_id);
6426 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
6428 boost::format formatter("Invalid thread id. thread id : %d.");
6429 formatter % boost::this_thread::get_id();
6430 putLogError(100101, formatter.str(), __FILE__, __LINE__ );
6434 session_data = session_thread_it->second;
6437 recive_data_it = session_data->recive_data_map.find(session_data->target_endpoint);
6438 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
6440 boost::format formatter("Invalid endpoint. thread id : %d.");
6441 formatter % boost::this_thread::get_id();
6442 putLogError(100102, formatter.str(), __FILE__, __LINE__ );
6446 recive_data& recv_data = recive_data_it->second;
6448 //get the data that can be sent possible
6449 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
6450 data_send_possible());
6451 if (unlikely(it == recv_data.send_status_list.end()))
6453 boost::format formatter("Sending possible data is not existed. thread id : %d.");
6454 formatter % boost::this_thread::get_id();
6455 putLogError(100103, formatter.str(), __FILE__, __LINE__ );
6459 //buffer size >= sending_possible size
6460 if (send_buffer_size > it->send_possible_size)
6462 /*-------- DEBUG LOG --------*/
6463 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6465 std::string datadump;
6466 dump_memory(recv_data.recive_buffer + it->send_offset, it->send_possible_size, datadump);
6468 boost::format formatter(
6469 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6470 "handle_client_connection_check() : before memcpy (data dump) : "
6471 "data begin = %d, data_size = %d, data = %s");
6472 formatter % it->send_offset % (it->send_possible_size) % datadump;
6473 putLogDebug(100215, formatter.str(), __FILE__, __LINE__ );
6475 /*------DEBUG LOG END------*/
6476 //copy data from recive_buffer to sendbuffer by sending_possible size
6477 memcpy(sendbuffer.data(), recv_data.recive_buffer + it->send_offset, it->send_possible_size);
6478 /*-------- DEBUG LOG --------*/
6479 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6481 std::string datadump;
6482 dump_memory(sendbuffer.data(), it->send_possible_size, datadump);
6484 boost::format formatter(
6485 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6486 "handle_client_connection_check() : after memcpy (data dump) : "
6487 "data begin = 0, data_size = %d, data = %s");
6488 formatter % (it->send_possible_size) % datadump;
6489 putLogDebug(100216, formatter.str(), __FILE__, __LINE__ );
6491 /*------DEBUG LOG END------*/
6492 //send_end_size recalc
6493 it->send_end_size = it->send_possible_size;
6494 //set copyed data length
6495 datalen = it->send_possible_size;
6496 //sending_possible size recalc
6497 it->send_possible_size = 0;
6499 //buffer size < sending_possible size
6502 /*-------- DEBUG LOG --------*/
6503 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6505 std::string datadump;
6506 dump_memory(recv_data.recive_buffer + it->send_offset, send_buffer_size, datadump);
6508 boost::format formatter(
6509 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6510 "handle_client_connection_check() : before memcpy (data dump) : "
6511 "data begin = %d, data_size = %d, data = %s");
6512 formatter % it->send_offset % send_buffer_size % datadump;
6513 putLogDebug(100217, formatter.str(), __FILE__, __LINE__ );
6515 /*------DEBUG LOG END------*/
6516 //copy data from recive_buffer to sendbuffer by buffer size
6517 memcpy(sendbuffer.data(), recv_data.recive_buffer + it->send_offset, send_buffer_size);
6518 /*-------- DEBUG LOG --------*/
6519 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6521 std::string datadump;
6522 dump_memory(sendbuffer.data(), send_buffer_size, datadump);
6524 boost::format formatter(
6525 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6526 "handle_client_connection_check() : after memcpy (data dump) : "
6527 "data begin = 0, data_size = %d, data = %s");
6528 formatter % send_buffer_size % datadump;
6529 putLogDebug(100218, formatter.str(), __FILE__, __LINE__ );
6531 /*------DEBUG LOG END------*/
6532 //send_end_size recalc
6533 it->send_end_size = send_buffer_size;
6534 //sending_possible size recalc
6535 it->send_possible_size -= send_buffer_size;
6536 //set copyed data length
6537 datalen = send_buffer_size;
6540 status = CLIENT_SEND;
6544 /*-------- DEBUG LOG --------*/
6545 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6547 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6548 "handle_client_connection_check() : catch exception e = %d. thread id : %d.");
6549 formatter % e % boost::this_thread::get_id();
6550 putLogDebug(100219, formatter.str(), __FILE__, __LINE__ );
6552 /*------DEBUG LOG END------*/
6555 catch (const std::exception& ex)
6557 std::cerr << "protocol_module_sessionless::handle_client_connection_check() : exception : error = " << ex.what() << "." << std::endl;
6558 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6559 "handle_client_connection_check() : exception : error = %s. thread id : %d.");
6560 formatter % ex.what() % boost::this_thread::get_id();
6561 putLogError(100104, formatter.str(), __FILE__, __LINE__ );
6566 std::cerr << "protocol_module_sessionless::handle_client_connection_check() : Unknown exception." << std::endl;
6567 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6568 "handle_client_connection_check() : Unknown exception. thread id : %d.");
6569 formatter % boost::this_thread::get_id();
6570 putLogError(100105, formatter.str(), __FILE__, __LINE__ );
6574 /*-------- DEBUG LOG --------*/
6575 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6577 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6578 "handle_client_connection_check(const boost::thread::id thread_id, "
6579 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)"
6580 " : return_value = %d. thread id : %d.");
6581 formatter % status % boost::this_thread::get_id();
6582 putLogDebug(100220, formatter.str(), __FILE__, __LINE__ );
6584 /*------DEBUG LOG END------*/
6588 //! called from after client select. use UDP only
6589 //! @param[in] downstream thread id
6590 //! @param[in] client udp endpoint
6591 //! @param[out] send buffer reference
6592 //! @param[out] send data length
6593 //! @return session use EVENT mode
6594 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_select(
6595 const boost::thread::id thread_id, boost::asio::ip::udp::endpoint& cl_endpoint, boost::array<char,
6596 MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
6598 /*-------- DEBUG LOG --------*/
6599 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6601 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6602 "handle_client_select(const boost::thread::id thread_id, "
6603 "boost::asio::ip::udp::endpoint& cl_endpoint, "
6604 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
6605 "size_t& datalen) : "
6606 "return_value = %d. thread id : %d.");
6607 formatter % STOP % boost::this_thread::get_id();
6608 putLogDebug(100221, formatter.str(), __FILE__, __LINE__ );
6610 /*------DEBUG LOG END------*/
6614 //! called from after client send
6615 //! @param[in] downstream thread id
6616 //! @return session use EVENT mode
6617 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_send(
6618 const boost::thread::id thread_id)
6620 /*-------- DEBUG LOG --------*/
6621 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6623 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6624 "handle_client_send(const boost::thread::id thread_id) : "
6626 formatter % thread_id;
6627 putLogDebug(100222, formatter.str(), __FILE__, __LINE__ );
6629 /*------DEBUG LOG END------*/
6630 EVENT_TAG status = FINALIZE;
6631 thread_data_ptr session_data;
6632 session_thread_data_map_it session_thread_it;
6633 recive_data_map_it recive_data_it;
6638 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
6640 session_thread_it = session_thread_data_map.find(thread_id);
6641 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
6643 boost::format formatter("Invalid thread id. thread id : %d.");
6644 formatter % boost::this_thread::get_id();
6645 putLogError(100106, formatter.str(), __FILE__, __LINE__ );
6648 session_data = session_thread_it->second;
6651 recive_data_it = session_data->recive_data_map.find(session_data->target_endpoint);
6652 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
6654 boost::format formatter("Invalid endpoint. thread id : %d.");
6655 formatter % boost::this_thread::get_id();
6656 putLogError(100107, formatter.str(), __FILE__, __LINE__ );
6660 recive_data& recv_data = recive_data_it->second;
6662 send_status_it it = recv_data.send_status_list.begin();
6663 send_status_it it_end = recv_data.send_status_list.end();
6666 it = std::adjacent_find(it, it_end, data_send_list_incorrect());
6667 if (unlikely(it != it_end))
6669 boost::format formatter("Sending possible data is invalid. thread id : %d.");
6670 formatter % boost::this_thread::get_id();
6671 putLogError(100108, formatter.str(), __FILE__, __LINE__ );
6675 it = recv_data.send_status_list.begin();
6676 it = find_if(it, it_end, data_send_ok());
6677 if (unlikely(it == it_end))
6679 boost::format formatter("Sending possible data is not existed. thread id : %d.");
6680 formatter % boost::this_thread::get_id();
6681 putLogError(100109, formatter.str(), __FILE__, __LINE__ );
6685 //sending possible data is exist
6686 if (it->send_possible_size > 0)
6688 //status remain SEND_OK
6689 it->status = SEND_OK;
6691 it->send_offset += it->send_end_size;
6692 //send_end_size recalc
6693 it->send_end_size = 0;
6695 //sending possible data is not exist
6698 //can recive from clent continue
6699 if (it->send_rest_size > 0)
6701 //change status from SEND_OK to SEND_CONTINUE
6702 it->status = SEND_CONTINUE;
6704 //can not recive from clent continue
6707 //change status from SEND_OK to SEND_END
6708 it->status = SEND_END;
6712 it = recv_data.send_status_list.begin();
6713 it = find_if(it, it_end, data_send_ok());
6714 //send_ok item is exist
6717 status = CLIENT_CONNECTION_CHECK;
6719 //send_ok item is not exist
6723 if (session_data->end_flag == END_FLAG_ON)
6725 status = CLIENT_DISCONNECT;
6731 if (session_data->sorry_flag == SORRY_FLAG_ON)
6733 status = SORRYSERVER_RECV;
6738 status = REALSERVER_RECV;
6745 /*-------- DEBUG LOG --------*/
6746 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6748 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6749 "handle_client_send() : catch exception e = %d. thread id : %d.");
6750 formatter % e % boost::this_thread::get_id();
6751 putLogDebug(100223, formatter.str(), __FILE__, __LINE__ );
6753 /*------DEBUG LOG END------*/
6756 catch (const std::exception& ex)
6758 std::cerr << "protocol_module_sessionless::handle_client_send() : exception : error = " << ex.what() << "." << std::endl;
6759 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6760 "handle_client_send() : exception : error = %s. thread id : %d.");
6761 formatter % ex.what() % boost::this_thread::get_id();
6762 putLogError(100110, formatter.str(), __FILE__, __LINE__ );
6767 std::cerr << "protocol_module_sessionless::handle_client_send() : Unknown exception." << std::endl;
6768 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6769 "handle_client_send() : Unknown exception. thread id : %d.");
6770 formatter % boost::this_thread::get_id();
6771 putLogError(100111, formatter.str(), __FILE__, __LINE__ );
6775 /*-------- DEBUG LOG --------*/
6776 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6778 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6779 "handle_client_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
6780 formatter % status % boost::this_thread::get_id();
6781 putLogDebug(100224, formatter.str(), __FILE__, __LINE__ );
6783 /*------DEBUG LOG END------*/
6788 //! call from client disconnect event. use upstream thread and downstream thread.
6789 //! @param[in] upstream and downstream thread id( check! one thread one event! )
6790 //! @return session use EVENT mode
6791 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_disconnect(
6792 const boost::thread::id thread_id)
6794 /*-------- DEBUG LOG --------*/
6795 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6797 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6798 "handle_client_disconnect(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
6799 formatter % FINALIZE % boost::this_thread::get_id();
6800 putLogDebug(100225, formatter.str(), __FILE__, __LINE__ );
6802 /*------DEBUG LOG END------*/
6806 //! call from sorry mode event. use upstream thread and downstream thread
6807 //! @param[in] upstream and downstream thread id( check! one thread one event and first time call pattern )
6808 //! @return session use EVENT mode
6809 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorry_enable(
6810 const boost::thread::id thread_id)
6812 /*-------- DEBUG LOG --------*/
6813 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6815 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6816 "handle_sorry_enable(const boost::thread::id thread_id) : "
6818 formatter % thread_id;
6819 putLogDebug(100226, formatter.str(), __FILE__, __LINE__ );
6821 /*------DEBUG LOG END------*/
6823 EVENT_TAG status = FINALIZE;
6824 boost::asio::ip::tcp::endpoint endpoint;
6825 bool send_possible = false;
6826 bool send_continue = false;
6827 bool send_disable = false;
6828 thread_data_ptr session_data;
6829 session_thread_data_map_it session_thread_it;
6830 recive_data_map_it recive_data_it;
6835 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
6837 session_thread_it = session_thread_data_map.find(thread_id);
6838 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
6840 boost::format formatter("Invalid thread id. thread id : %d.");
6841 formatter % boost::this_thread::get_id();
6842 putLogError(100112, formatter.str(), __FILE__, __LINE__ );
6846 session_data = session_thread_it->second;
6849 endpoint = session_data->thread_division == THREAD_DIVISION_UP_STREAM ? session_data->client_endpoint_tcp
6850 : session_data->target_endpoint;
6851 recive_data_it = session_data->recive_data_map.find(endpoint);
6852 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
6854 //must be down thread
6855 if (unlikely(session_data->thread_division == THREAD_DIVISION_UP_STREAM))
6857 boost::format formatter("Invalid endpoint. thread id : %d.");
6858 formatter % boost::this_thread::get_id();
6859 putLogError(100113, formatter.str(), __FILE__, __LINE__ );
6862 session_data->sorry_flag = SORRY_FLAG_ON;
6863 /*-------- DEBUG LOG --------*/
6864 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6866 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6867 "handle_sorry_enable() : SORRY_FLAG_ON. thread id : %d.");
6868 formatter % boost::this_thread::get_id();
6869 putLogDebug(100227, formatter.str(), __FILE__, __LINE__ );
6871 /*------DEBUG LOG END------*/
6872 status = SORRYSERVER_RECV;
6876 recive_data& recv_data = recive_data_it->second;
6878 //get this thread sending possible data
6879 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
6880 data_send_possible());
6881 if (it != recv_data.send_status_list.end())
6883 send_possible = true;
6886 it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_continue());
6887 if (it != recv_data.send_status_list.end())
6889 send_continue = true;
6892 it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_disable());
6893 if (it != recv_data.send_status_list.end())
6895 send_disable = true;
6899 if (session_data->thread_division == THREAD_DIVISION_UP_STREAM)
6901 //accept_end_flag is off
6902 if (session_data->accept_end_flag == ACCEPT_END_FLAG_OFF)
6905 session_data->sorry_flag = SORRY_FLAG_ON;
6906 /*-------- DEBUG LOG --------*/
6907 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6909 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6910 "handle_sorry_enable() : SORRY_FLAG_ON. thread id : %d.");
6911 formatter % boost::this_thread::get_id();
6912 putLogDebug(100228, formatter.str(), __FILE__, __LINE__ );
6914 /*------DEBUG LOG END------*/
6917 //accept_end_flag is on
6921 if (session_data->sorry_flag == SORRY_FLAG_ON)
6925 status = SORRYSERVER_CONNECT;
6929 status = SORRYSERVER_SELECT;
6933 //set sorry flag off
6936 //the data that can be sent continue is exist
6940 session_data->end_flag = END_FLAG_ON;
6941 /*-------- DEBUG LOG --------*/
6942 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6944 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6945 "handle_sorry_enable() : END_FLAG_ON. thread id : %d.");
6946 formatter % boost::this_thread::get_id();
6947 putLogDebug(100229, formatter.str(), __FILE__, __LINE__ );
6949 /*------DEBUG LOG END------*/
6950 status = REALSERVER_DISCONNECT;
6952 //the data that can be sent continue is not exist
6955 //set sorryserver_switch_flag on
6956 session_data->sorryserver_switch_flag = SORRYSERVER_SWITCH_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() : SORRYSERVER_SWITCH_FLAG_ON. thread id : %d.");
6962 formatter % boost::this_thread::get_id();
6963 putLogDebug(100230, formatter.str(), __FILE__, __LINE__ );
6965 /*------DEBUG LOG END------*/
6967 session_data->sorry_flag = SORRY_FLAG_ON;
6968 /*-------- DEBUG LOG --------*/
6969 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6971 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6972 "handle_sorry_enable() : SORRY_FLAG_ON. thread id : %d.");
6973 formatter % boost::this_thread::get_id();
6974 putLogDebug(100231, formatter.str(), __FILE__, __LINE__ );
6976 /*------DEBUG LOG END------*/
6977 status = REALSERVER_DISCONNECT;
6986 if (session_data->sorry_flag == SORRY_FLAG_ON)
6988 //sending possible data is exist
6991 status = CLIENT_CONNECTION_CHECK;
6993 //sending possible data is not exist
6996 status = SORRYSERVER_RECV;
7003 session_data->sorry_flag = SORRY_FLAG_ON;
7004 /*-------- DEBUG LOG --------*/
7005 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7007 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7008 "handle_sorry_enable() : SORRY_FLAG_ON. thread id : %d.");
7009 formatter % boost::this_thread::get_id();
7010 putLogDebug(100232, formatter.str(), __FILE__, __LINE__ );
7012 /*------DEBUG LOG END------*/
7013 session_data->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_ON;
7014 /*-------- DEBUG LOG --------*/
7015 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7017 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7018 "handle_sorry_enable() : SORRYSERVER_SWITCH_FLAG_ON. thread id : %d.");
7019 formatter % boost::this_thread::get_id();
7020 putLogDebug(100233, formatter.str(), __FILE__, __LINE__ );
7022 /*------DEBUG LOG END------*/
7024 //sending ng data is exist or send_rest_size > 0
7028 session_data->end_flag = END_FLAG_ON;
7029 /*-------- DEBUG LOG --------*/
7030 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7032 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7033 "handle_sorry_enable() : END_FLAG_ON. thread id : %d.");
7034 formatter % boost::this_thread::get_id();
7035 putLogDebug(100234, formatter.str(), __FILE__, __LINE__ );
7037 /*------DEBUG LOG END------*/
7038 status = REALSERVER_DISCONNECT;
7043 //sending possible data is exist
7046 status = CLIENT_CONNECTION_CHECK;
7048 //sending possible data is not exist
7051 status = SORRYSERVER_RECV;
7060 /*-------- DEBUG LOG --------*/
7061 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7063 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7064 "handle_sorry_enable() : catch exception e = %d. thread id : %d.");
7065 formatter % e % boost::this_thread::get_id();
7066 putLogDebug(100235, formatter.str(), __FILE__, __LINE__ );
7068 /*------DEBUG LOG END------*/
7071 catch (const std::exception& ex)
7073 std::cerr << "protocol_module_sessionless::handle_sorry_enable() : exception : error = " << ex.what() << "." << std::endl;
7074 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7075 "handle_sorry_enable() : exception : error = %s. thread id : %d.");
7076 formatter % ex.what() % boost::this_thread::get_id();
7077 putLogError(100114, formatter.str(), __FILE__, __LINE__ );
7082 std::cerr << "protocol_module_sessionless::handle_sorry_enable() : Unknown exception." << std::endl;
7083 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7084 "handle_sorry_enable() : Unknown exception. thread id : %d.");
7085 formatter % boost::this_thread::get_id();
7086 putLogError(100115, formatter.str(), __FILE__, __LINE__ );
7090 /*-------- DEBUG LOG --------*/
7091 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7093 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7094 "handle_sorry_enable(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
7095 formatter % status % boost::this_thread::get_id();
7096 putLogDebug(100236, formatter.str(), __FILE__, __LINE__ );
7098 /*------DEBUG LOG END------*/
7103 //! call from sorry mode disable. use upstream thread and downstream thread.
7104 //! @param[in] upstream and downstream thread id( check! one thread one event )
7105 //! @return session use EVENT mode
7106 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorry_disable(
7107 const boost::thread::id thread_id)
7109 /*-------- DEBUG LOG --------*/
7110 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7112 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7113 "handle_sorry_disable(const boost::thread::id thread_id) : "
7115 formatter % thread_id;
7116 putLogDebug(100237, formatter.str(), __FILE__, __LINE__ );
7118 /*------DEBUG LOG END------*/
7119 EVENT_TAG status = FINALIZE;
7120 boost::asio::ip::tcp::endpoint endpoint;
7121 bool send_possible = false;
7122 bool send_disable = false;
7123 bool send_continue = false;
7124 thread_data_ptr session_data;
7129 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
7131 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
7132 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
7134 boost::format formatter("Invalid thread id. thread id : %d.");
7135 formatter % boost::this_thread::get_id();
7136 putLogError(100116, formatter.str(), __FILE__, __LINE__ );
7140 session_data = session_thread_it->second;
7143 endpoint = session_data->thread_division == THREAD_DIVISION_UP_STREAM ? session_data->client_endpoint_tcp
7144 : session_data->target_endpoint;
7145 recive_data_map_it recive_data_it = session_data->recive_data_map.find(endpoint);
7146 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
7148 //must be down thread
7149 if (unlikely(session_data->thread_division == THREAD_DIVISION_UP_STREAM))
7151 boost::format formatter("Invalid endpoint. thread id : %d.");
7152 formatter % boost::this_thread::get_id();
7153 putLogError(100117, formatter.str(), __FILE__, __LINE__ );
7157 session_data->sorry_flag = SORRY_FLAG_OFF;
7158 /*-------- DEBUG LOG --------*/
7159 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7161 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7162 "handle_sorry_disable() : SORRY_FLAG_OFF. thread id : %d.");
7163 formatter % boost::this_thread::get_id();
7164 putLogDebug(100238, formatter.str(), __FILE__, __LINE__ );
7166 /*------DEBUG LOG END------*/
7167 status = REALSERVER_RECV;
7171 recive_data& recv_data = recive_data_it->second;
7173 //get this thread sending possible data
7174 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
7175 data_send_possible());
7176 if (it != recv_data.send_status_list.end())
7178 send_possible = true;
7181 //sending ng data is exist or send_rest_size > 0
7182 it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_disable());
7183 if (it != recv_data.send_status_list.end())
7185 send_disable = true;
7188 //the data that can be sent continue is exist
7189 it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_continue());
7190 if (it != recv_data.send_status_list.end())
7192 send_continue = true;
7196 if (session_data->thread_division == THREAD_DIVISION_UP_STREAM)
7198 //accept_end_flag is off
7199 if (session_data->accept_end_flag == ACCEPT_END_FLAG_OFF)
7201 //set sorry flag off
7202 session_data->sorry_flag = SORRY_FLAG_OFF;
7203 /*-------- DEBUG LOG --------*/
7204 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7206 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7207 "handle_sorry_disable() : SORRY_FLAG_OFF. thread id : %d.");
7208 formatter % boost::this_thread::get_id();
7209 putLogDebug(100239, formatter.str(), __FILE__, __LINE__ );
7211 /*------DEBUG LOG END------*/
7215 //accept_end_flag is on
7219 if (session_data->sorry_flag == SORRY_FLAG_ON)
7221 //the data that can be sent continue is exist
7225 session_data->end_flag = END_FLAG_ON;
7226 /*-------- DEBUG LOG --------*/
7227 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7229 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7230 "handle_sorry_disable() : END_FLAG_ON. thread id : %d.");
7231 formatter % boost::this_thread::get_id();
7232 putLogDebug(100240, formatter.str(), __FILE__, __LINE__ );
7234 /*------DEBUG LOG END------*/
7235 status = SORRYSERVER_DISCONNECT;
7237 //the data that can be sent continue is not exist
7240 //set realserver_switch_flag on
7241 session_data->realserver_switch_flag = REALSERVER_SWITCH_FLAG_ON;
7242 /*-------- DEBUG LOG --------*/
7243 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7245 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7246 "handle_sorry_disable() : REALSERVER_SWITCH_FLAG_ON. thread id : %d.");
7247 formatter % boost::this_thread::get_id();
7248 putLogDebug(100241, formatter.str(), __FILE__, __LINE__ );
7250 /*------DEBUG LOG END------*/
7251 //set sorry_flag off
7252 session_data->sorry_flag = SORRY_FLAG_OFF;
7253 /*-------- DEBUG LOG --------*/
7254 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7256 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7257 "handle_sorry_disable() : SORRY_FLAG_OFF. thread id : %d.");
7258 formatter % boost::this_thread::get_id();
7259 putLogDebug(100242, formatter.str(), __FILE__, __LINE__ );
7261 /*------DEBUG LOG END------*/
7262 status = SORRYSERVER_DISCONNECT;
7270 status = REALSERVER_CONNECT;
7274 status = REALSERVER_SELECT;
7283 if (session_data->sorry_flag == SORRY_FLAG_ON)
7285 //set sorry_flag off
7286 session_data->sorry_flag = SORRY_FLAG_OFF;
7287 /*-------- DEBUG LOG --------*/
7288 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7290 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7291 "handle_sorry_disable() : SORRY_FLAG_OFF. thread id : %d.");
7292 formatter % boost::this_thread::get_id();
7293 putLogDebug(100243, formatter.str(), __FILE__, __LINE__ );
7295 /*------DEBUG LOG END------*/
7296 session_data->realserver_switch_flag = REALSERVER_SWITCH_FLAG_ON;
7297 /*-------- DEBUG LOG --------*/
7298 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7300 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7301 "handle_sorry_disable() : REALSERVER_SWITCH_FLAG_ON. thread id : %d.");
7302 formatter % boost::this_thread::get_id();
7303 putLogDebug(100244, formatter.str(), __FILE__, __LINE__ );
7305 /*------DEBUG LOG END------*/
7306 //sending ng data is exist or send_rest_size > 0
7310 session_data->end_flag = END_FLAG_ON;
7311 /*-------- DEBUG LOG --------*/
7312 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7314 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7315 "handle_sorry_disable() : END_FLAG_ON. thread id : %d.");
7316 formatter % boost::this_thread::get_id();
7317 putLogDebug(100245, formatter.str(), __FILE__, __LINE__ );
7319 /*------DEBUG LOG END------*/
7320 status = SORRYSERVER_DISCONNECT;
7325 //sending possible data is exist
7328 status = CLIENT_CONNECTION_CHECK;
7330 //sending possible data is not exist
7333 status = REALSERVER_RECV;
7340 //sending possible data is exist
7343 status = CLIENT_CONNECTION_CHECK;
7345 //sending possible data is not exist
7348 status = REALSERVER_RECV;
7358 /*-------- DEBUG LOG --------*/
7359 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7361 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7362 "handle_sorry_disable() : catch exception e = %d. thread id : %d.");
7363 formatter % e % boost::this_thread::get_id();
7364 putLogDebug(100246, formatter.str(), __FILE__, __LINE__ );
7366 /*------DEBUG LOG END------*/
7369 catch (std::exception& ex)
7371 std::cerr << "protocol_module_sessionless::handle_sorry_disable() : exception : error = " << ex.what() << "." << std::endl;
7372 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7373 "handle_sorry_disable() : exception : error = %s. thread id : %d.");
7374 formatter % ex.what() % boost::this_thread::get_id();
7375 putLogError(100118, formatter.str(), __FILE__, __LINE__ );
7380 std::cerr << "protocol_module_sessionless::handle_sorry_disable() : Unknown exception." << std::endl;
7381 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7382 "handle_sorry_disable() : Unknown exception. thread id : %d.");
7383 formatter % boost::this_thread::get_id();
7384 putLogError(100119, formatter.str(), __FILE__, __LINE__ );
7388 /*-------- DEBUG LOG --------*/
7389 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7391 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7392 "handle_sorry_disable(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
7393 formatter % status % boost::this_thread::get_id();
7394 putLogDebug(100247, formatter.str(), __FILE__, __LINE__ );
7396 /*------DEBUG LOG END------*/
7401 //! call from realserver disconnect. use upstream thread and downstream thread
7402 //! @param[in] upstream and downstream thread id( check! one thread one event )
7403 //! @param[in] disconnected realserver endpoint.
7404 //! @return session use EVENT mode
7405 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_disconnect(
7406 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint)
7408 /*-------- DEBUG LOG --------*/
7409 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7411 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7412 "handle_realserver_disconnect(const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint) : "
7413 "thread_id = %d, rs_endpoint = [%s]:%d.");
7414 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
7415 putLogDebug(100248, formatter.str(), __FILE__, __LINE__ );
7417 /*------DEBUG LOG END------*/
7418 EVENT_TAG status = FINALIZE;
7419 bool possible_flag = false;
7420 thread_data_ptr session_data;
7421 boost::asio::ip::tcp::endpoint endpoint;
7426 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
7428 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
7429 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
7431 boost::format formatter("Invalid thread id. thread id : %d.");
7432 formatter % boost::this_thread::get_id();
7433 putLogError(100120, formatter.str(), __FILE__, __LINE__ );
7437 session_data = session_thread_it->second;
7440 endpoint = session_data->thread_division == THREAD_DIVISION_UP_STREAM ? session_data->client_endpoint_tcp
7441 : session_data->target_endpoint;
7442 recive_data_map_it recive_data_it = session_data->recive_data_map.find(endpoint);
7443 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
7445 boost::format formatter("Invalid endpoint. thread id : %d.");
7446 formatter % boost::this_thread::get_id();
7447 putLogError(100121, formatter.str(), __FILE__, __LINE__ );
7451 recive_data& recv_data = recive_data_it->second;
7453 //the data that can be sent possible is exist
7454 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
7455 data_send_possible());
7456 if (it != recv_data.send_status_list.end())
7458 possible_flag = true;
7462 if (session_data->thread_division == THREAD_DIVISION_UP_STREAM)
7465 if (session_data->end_flag == END_FLAG_ON)
7467 status = CLIENT_RECV;
7472 //sorryserver_switch_flag is on
7473 if (session_data->sorryserver_switch_flag == SORRYSERVER_SWITCH_FLAG_ON)
7475 session_data->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_OFF;
7476 /*-------- DEBUG LOG --------*/
7477 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7479 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7480 "handle_realserver_disconnect() : SORRYSERVER_SWITCH_FLAG_OFF. thread id : %d.");
7481 formatter % boost::this_thread::get_id();
7482 putLogDebug(100249, formatter.str(), __FILE__, __LINE__ );
7484 /*------DEBUG LOG END------*/
7486 status = SORRYSERVER_SELECT;
7489 //sorryserver_switch_flag is off
7493 session_data->end_flag = END_FLAG_ON;
7494 /*-------- DEBUG LOG --------*/
7495 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7497 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7498 "handle_realserver_disconnect() : END_FLAG_ON. thread id : %d.");
7499 formatter % boost::this_thread::get_id();
7500 putLogDebug(100250, formatter.str(), __FILE__, __LINE__ );
7502 /*------DEBUG LOG END------*/
7503 status = CLIENT_RECV;
7510 if (session_data->end_flag == END_FLAG_ON)
7512 status = CLIENT_DISCONNECT;
7516 if (session_data->sorryserver_switch_flag == SORRYSERVER_SWITCH_FLAG_ON)
7518 session_data->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_OFF;
7519 /*-------- DEBUG LOG --------*/
7520 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7522 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7523 "handle_realserver_disconnect() : SORRYSERVER_SWITCH_FLAG_OFF. thread id : %d.");
7524 formatter % boost::this_thread::get_id();
7525 putLogDebug(100251, formatter.str(), __FILE__, __LINE__ );
7527 /*------DEBUG LOG END------*/
7528 status = SORRYSERVER_RECV;
7533 session_data->end_flag = END_FLAG_ON;
7534 /*-------- DEBUG LOG --------*/
7535 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7537 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7538 "handle_realserver_disconnect() : END_FLAG_ON. thread id : %d.");
7539 formatter % boost::this_thread::get_id();
7540 putLogDebug(100252, formatter.str(), __FILE__, __LINE__ );
7542 /*------DEBUG LOG END------*/
7543 status = CLIENT_DISCONNECT;
7547 //the data that can be sent possible is exist
7550 status = CLIENT_CONNECTION_CHECK;
7556 /*-------- DEBUG LOG --------*/
7557 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7559 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7560 "handle_realserver_disconnect() : catch exception e = %d. thread id : %d.");
7561 formatter % e % boost::this_thread::get_id();
7562 putLogDebug(100253, formatter.str(), __FILE__, __LINE__ );
7564 /*------DEBUG LOG END------*/
7567 catch (std::exception& ex)
7569 std::cerr << "protocol_module_sessionless::handle_realserver_disconnect() : exception: error = " << ex.what() << "." << std::endl;
7570 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7571 "handle_realserver_disconnect() : exception : error = %s. thread id : %d.");
7572 formatter % ex.what() % boost::this_thread::get_id();
7573 putLogError(100122, formatter.str(), __FILE__, __LINE__ );
7578 std::cerr << "protocol_module_sessionless::handle_realserver_disconnect() : Unknown exception." << std::endl;
7579 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7580 "handle_realserver_disconnect() : Unknown exception. thread id : %d.");
7581 formatter % boost::this_thread::get_id();
7582 putLogError(100123, formatter.str(), __FILE__, __LINE__ );
7586 /*-------- DEBUG LOG --------*/
7587 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7589 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7590 "handle_realserver_disconnect(const boost::thread::id thread_id, "
7591 "const boost::asio::ip::tcp::endpoint & rs_endpoint) : return_value = %d. thread id : %d.");
7592 formatter % status % boost::this_thread::get_id();
7593 putLogDebug(100254, formatter.str(), __FILE__, __LINE__ );
7595 /*------DEBUG LOG END------*/
7600 //! call from sorry server disconnect. use upstraem thread and downstream thread
7601 //! @param[in] upstream and downstream thread id( check! one thread one event )
7602 //! @param[in] disconnect sorryserver endpoint
7603 //! @return session use EVENT mode
7604 //! @return session use EVENT mode
7605 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_disconnect(
7606 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint)
7608 /*-------- DEBUG LOG --------*/
7609 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7613 "in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7614 "handle_sorryserver_disconnect(const boost::thread::id thread_id, "
7615 "const boost::asio::ip::tcp::endpoint & sorry_endpoint) : "
7616 "thread_id = %d, sorry_endpoint = [%s]:%d.");
7617 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port() ;
7618 putLogDebug(100255, formatter.str(), __FILE__, __LINE__ );
7620 /*------DEBUG LOG END------*/
7621 EVENT_TAG status = FINALIZE;
7622 bool possible_flag = false;
7623 thread_data_ptr session_data;
7624 boost::asio::ip::tcp::endpoint endpoint;
7629 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
7631 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
7632 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
7634 boost::format formatter("Invalid thread id. thread id : %d.");
7635 formatter % boost::this_thread::get_id();
7636 putLogError(100124, formatter.str(), __FILE__, __LINE__ );
7640 session_data = session_thread_it->second;
7643 endpoint = session_data->thread_division == THREAD_DIVISION_UP_STREAM ? session_data->client_endpoint_tcp
7644 : session_data->target_endpoint;
7645 recive_data_map_it recive_data_it = session_data->recive_data_map.find(endpoint);
7646 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
7648 boost::format formatter("Invalid endpoint. thread id : %d.");
7649 formatter % boost::this_thread::get_id();
7650 putLogError(100125, formatter.str(), __FILE__, __LINE__ );
7654 recive_data& recv_data = recive_data_it->second;
7656 //the data that can be sent possible is exist
7657 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
7658 data_send_possible());
7659 if (it != recv_data.send_status_list.end())
7661 possible_flag = true;
7665 if (session_data->thread_division == THREAD_DIVISION_UP_STREAM)
7668 if (session_data->end_flag == END_FLAG_ON)
7670 status = CLIENT_RECV;
7675 //realserver_switch_flag is on
7676 if (session_data->realserver_switch_flag == REALSERVER_SWITCH_FLAG_ON)
7678 session_data->realserver_switch_flag = REALSERVER_SWITCH_FLAG_OFF;
7679 /*-------- DEBUG LOG --------*/
7680 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7682 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7683 "handle_sorryserver_disconnect() : REALSERVER_SWITCH_FLAG_OFF. thread id : %d.");
7684 formatter % boost::this_thread::get_id();
7685 putLogDebug(100256, formatter.str(), __FILE__, __LINE__ );
7687 /*------DEBUG LOG END------*/
7688 status = REALSERVER_SELECT;
7690 //realserver_switch_flag is off
7694 session_data->end_flag = END_FLAG_ON;
7695 /*-------- DEBUG LOG --------*/
7696 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7698 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7699 "handle_sorryserver_disconnect() : END_FLAG_ON. thread id : %d.");
7700 formatter % boost::this_thread::get_id();
7701 putLogDebug(100257, formatter.str(), __FILE__, __LINE__ );
7703 /*------DEBUG LOG END------*/
7704 status = CLIENT_RECV;
7711 if (session_data->end_flag == END_FLAG_ON)
7713 status = CLIENT_DISCONNECT;
7717 if (session_data->realserver_switch_flag == REALSERVER_SWITCH_FLAG_ON)
7719 session_data->realserver_switch_flag = REALSERVER_SWITCH_FLAG_OFF;
7720 /*-------- DEBUG LOG --------*/
7721 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7723 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7724 "handle_sorryserver_disconnect() : REALSERVER_SWITCH_FLAG_OFF. thread id : %d.");
7725 formatter % boost::this_thread::get_id();
7726 putLogDebug(100258, formatter.str(), __FILE__, __LINE__ );
7728 /*------DEBUG LOG END------*/
7729 status = REALSERVER_RECV;
7733 session_data->end_flag = END_FLAG_ON;
7734 /*-------- DEBUG LOG --------*/
7735 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7737 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7738 "handle_sorryserver_disconnect() : END_FLAG_ON. thread id : %d.");
7739 formatter % boost::this_thread::get_id();
7740 putLogDebug(100259, formatter.str(), __FILE__, __LINE__ );
7742 /*------DEBUG LOG END------*/
7743 status = CLIENT_DISCONNECT;
7747 //the data that can be sent possible is exist
7750 status = CLIENT_CONNECTION_CHECK;
7756 /*-------- DEBUG LOG --------*/
7757 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7759 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7760 "handle_sorryserver_disconnect() : catch exception e = %d. thread id : %d.");
7761 formatter % e % boost::this_thread::get_id();
7762 putLogDebug(100260, formatter.str(), __FILE__, __LINE__ );
7764 /*------DEBUG LOG END------*/
7767 catch (const std::exception& ex)
7769 std::cerr << "protocol_module_sessionless::handle_sorryserver_disconnect() : exception : error = " << ex.what() << "." << std::endl;
7770 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7771 "handle_sorryserver_disconnect() : exception : error = %s. thread id : %d.");
7772 formatter % ex.what() % boost::this_thread::get_id();
7773 putLogError(100126, formatter.str(), __FILE__, __LINE__ );
7778 std::cerr << "protocol_module_sessionless::handle_sorryserver_disconnect() : Unknown exception." << std::endl;
7779 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7780 "handle_sorryserver_disconnect() : Unknown exception. thread id : %d.");
7781 formatter % boost::this_thread::get_id();
7782 putLogError(100127, formatter.str(), __FILE__, __LINE__ );
7786 /*-------- DEBUG LOG --------*/
7787 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7791 "out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7792 "handle_sorryserver_disconnect(const boost::thread::id thread_id, "
7793 "const boost::asio::ip::tcp::endpoint& sorry_endpoint) : return_value = %d. thread id : %d.");
7794 formatter % status % boost::this_thread::get_id();
7795 putLogDebug(100261, formatter.str(), __FILE__, __LINE__ );
7797 /*------DEBUG LOG END------*/
7802 //! call from realserver disconnect. use upstream thread and downstream thread.
7803 //! @param[in] upstream and downstream thread id( check! one thread one event )
7804 //! @param[in] disconnect realserver endpoint
7805 //! @return session use EVENT mode.
7806 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_close(
7807 const boost::thread::id thread_id, const boost::asio::ip::udp::endpoint & rs_endpoint)
7809 /*-------- DEBUG LOG --------*/
7810 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7812 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7813 "handle_realserver_close(const boost::thread::id thread_id, "
7814 "const boost::asio::ip::udp::endpoint & rs_endpoint) : "
7815 "return_value = %d. thread id : %d.");
7816 formatter % STOP % boost::this_thread::get_id();
7817 putLogDebug(100262, formatter.str(), __FILE__, __LINE__ );
7819 /*------DEBUG LOG END------*/
7825 extern "C" l7vs::protocol_module_base*
7828 return dynamic_cast<l7vs::protocol_module_base*>(new l7vs::protocol_module_sessionless());
7832 destroy_module( l7vs::protocol_module_base* in )