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 --------*/
723 //! TCP/IP scheduled function registation.
724 //! @param[in] schedule module TCP/IP scheduled function object type
725 void protocol_module_sessionless::register_schedule(tcp_schedule_func_type inschedule)
727 /*-------- DEBUG LOG --------*/
728 if (unlikely(LOG_LV_DEBUG == getloglevel()))
730 putLogDebug(100019, "in_function : void protocol_module_sessionless::register_schedule("
731 "tcp_schedule_func_type inschedule).", __FILE__, __LINE__ );
733 /*------DEBUG LOG END------*/
734 schedule_tcp = inschedule;
735 /*-------- DEBUG LOG --------*/
736 if (unlikely(LOG_LV_DEBUG == getloglevel()))
738 putLogDebug(100020, "out_function : void protocol_module_sessionless::register_schedule("
739 "tcp_schedule_func_type inschedule).", __FILE__, __LINE__ );
741 /*------DEBUG LOG END------*/
744 //! UDP scheduled function registation
745 //! @param[in] schedule module UDP scheduled funtion object type
746 void protocol_module_sessionless::register_schedule(udp_schedule_func_type inschedule)
748 /*-------- DEBUG LOG --------*/
749 if (unlikely(LOG_LV_DEBUG == getloglevel()))
752 "in/out_function : void protocol_module_sessionless::register_schedule(udp_schedule_func_type inschedule).",
753 __FILE__, __LINE__ );
755 /*------DEBUG LOG END------*/
758 //! called from session initialzie use in upstream_thread
759 //! @param[in] upstream thread id.
760 //! @param[in] downstream thread id
761 //! @return session use EVENT mode.
762 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_session_initialize(
763 const boost::thread::id up_thread_id, const boost::thread::id down_thread_id,
764 const boost::asio::ip::tcp::endpoint& client_endpoint_tcp,
765 const boost::asio::ip::udp::endpoint& client_endpoint_udp)
767 /*-------- DEBUG LOG --------*/
768 if (unlikely(LOG_LV_DEBUG == getloglevel()))
770 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
771 "handle_session_initialize(const boost::thread::id up_thread_id, "
772 "const boost::thread::id down_thread_id, const boost::asio::ip::tcp::endpoint& client_endpoint_tcp, "
773 "const boost::asio::ip::udp::endpoint& client_endpoint_udp) : "
774 "up_thread_id = %d, down_thread_id = %d, client_endpoint_tcp = [%s]:%d.");
775 formatter % up_thread_id % down_thread_id % client_endpoint_tcp.address().to_string() % client_endpoint_tcp.port() ;
776 putLogDebug(100022, formatter.str(), __FILE__, __LINE__ );
778 /*------DEBUG LOG END------*/
779 EVENT_TAG status = FINALIZE;
781 //session thread initialization
784 thread_data_ptr p_up(new session_thread_data_sessionless);
785 /*-------- DEBUG LOG --------*/
786 if (unlikely(LOG_LV_DEBUG == getloglevel()))
788 boost::format formatter("new : address = &(%d), size = %lu.");
789 formatter % static_cast<void*>(p_up.get()) % sizeof(session_thread_data_sessionless);
790 putLogDebug(100023, formatter.str(), __FILE__, __LINE__ );
792 /*------DEBUG LOG END------*/
793 p_up->thread_id = up_thread_id;
794 p_up->thread_division = THREAD_DIVISION_UP_STREAM;
795 p_up->pair_thread_id = down_thread_id;
796 p_up->accept_end_flag = ACCEPT_END_FLAG_OFF;
797 p_up->end_flag = END_FLAG_OFF;
798 p_up->sorry_flag = SORRY_FLAG_OFF;
799 p_up->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_OFF;
800 p_up->realserver_switch_flag = REALSERVER_SWITCH_FLAG_OFF;
801 p_up->last_status = INITIALIZE;
802 p_up->client_endpoint_tcp = client_endpoint_tcp;
804 recive_data recv_data;
805 p_up->recive_data_map[client_endpoint_tcp] = recv_data;
807 /*-------- DEBUG LOG --------*/
808 if (unlikely(LOG_LV_DEBUG == getloglevel()))
812 formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
813 "handle_session_initialize() : session_thread_data_sessionless(up_thread_id) : "
814 "thread_id = %d, thread_division = %d, "
815 "pair_thread_id = %d, accept_end_flag = %d, end_flag = %d, "
816 "sorry_flag = %d, sorryserver_switch_flag = %d, realserver_switch_flag = %d, last_status = %d, client_endpoint_tcp = [%s]:%d.");
817 formatter % p_up->thread_id % p_up->thread_division % p_up->pair_thread_id % p_up->accept_end_flag
818 % p_up->end_flag % p_up->sorry_flag % p_up->sorryserver_switch_flag % p_up->realserver_switch_flag
819 % p_up->last_status % client_endpoint_tcp.address().to_string() % client_endpoint_tcp.port();
820 putLogDebug(100024, formatter.str(), __FILE__, __LINE__ );
822 /*------DEBUG LOG END------*/
824 thread_data_ptr p_down(new session_thread_data_sessionless);
825 /*-------- DEBUG LOG --------*/
826 if (unlikely(LOG_LV_DEBUG == getloglevel()))
828 boost::format formatter("new : address = &(%d), size = %lu.");
829 formatter % static_cast<void*>(p_down.get()) % sizeof(session_thread_data_sessionless);
830 putLogDebug(100025, formatter.str(), __FILE__, __LINE__ );
832 /*------DEBUG LOG END------*/
833 p_down->thread_id = down_thread_id;
834 p_down->thread_division = THREAD_DIVISION_DOWN_STREAM;
835 p_down->pair_thread_id = up_thread_id;
836 p_down->accept_end_flag = ACCEPT_END_FLAG_OFF;
837 p_down->end_flag = END_FLAG_OFF;
838 p_down->sorry_flag = SORRY_FLAG_OFF;
839 p_down->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_OFF;
840 p_down->realserver_switch_flag = REALSERVER_SWITCH_FLAG_OFF;
841 p_down->last_status = INITIALIZE;
842 p_down->client_endpoint_tcp = client_endpoint_tcp;
843 /*-------- DEBUG LOG --------*/
844 if (unlikely(LOG_LV_DEBUG == getloglevel()))
847 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
848 "handle_session_initialize() : session_thread_data_sessionless(down_thread_id) : "
849 "thread_id = %d, thread_division = %d, pair_thread_id = %d, accept_end_flag = %d, end_flag = %d, "
850 "sorry_flag = %d, sorryserver_switch_flag = %d, realserver_switch_flag = %d, "
851 "last_status = %d, client_endpoint_tcp = [%s]:%d.");
852 formatter % p_down->thread_id % p_down->thread_division % p_down->pair_thread_id % p_down->accept_end_flag
853 % p_down->end_flag % p_down->sorry_flag % p_down->sorryserver_switch_flag
854 % p_down->realserver_switch_flag % p_down->last_status % client_endpoint_tcp.address().to_string() % client_endpoint_tcp.port();
855 putLogDebug(100026, formatter.str(), __FILE__, __LINE__ );
857 /*------DEBUG LOG END------*/
859 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
861 session_thread_data_map[up_thread_id] = p_up;
862 session_thread_data_map[down_thread_id] = p_down;
866 catch (const std::bad_alloc&)
868 std::cerr << "protocol_module_sessionless::handle_session_initialize() : exception : Could not allocate memory." << std::endl;
869 boost::format formatter("Could not allocate memory. thread id : %d.");
870 formatter % boost::this_thread::get_id();
871 putLogError(100017, formatter.str(), __FILE__, __LINE__ );
874 catch (const std::exception& ex)
876 std::cerr << "protocol_module_sessionless::handle_session_initialize() : exception : error = " << ex.what() << "." << std::endl;
877 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
878 "handle_session_initialize() : exception : error = %s. thread id : %d.");
879 formatter % ex.what() % boost::this_thread::get_id();
880 putLogError(100018, formatter.str(), __FILE__, __LINE__ );
885 std::cerr << "protocol_module_sessionless::handle_session_initialize() : Unknown exception." << std::endl;
886 boost::format formatter("function : protocol_module_base::check_message_result "
887 "protocol_module_sessionless::handle_session_initialize() : "
888 "Unknown exception. thread id : %d.");
889 formatter % boost::this_thread::get_id();
890 putLogError(100019, formatter.str(), __FILE__, __LINE__ );
895 /*-------- DEBUG LOG --------*/
896 if (unlikely(LOG_LV_DEBUG == getloglevel()))
898 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
899 "handle_session_initialize(const boost::thread::id up_thread_id, "
900 "const boost::thread::id down_thread_id, const boost::asio::ip::tcp::endpoint& client_endpoint_tcp, "
901 "const boost::asio::ip::udp::endpoint& client_endpoint_udp) : return_value = %d. thread id : %d.");
902 formatter % status % boost::this_thread::get_id();
903 putLogDebug(100027, formatter.str(), __FILE__, __LINE__ );
905 /*------DEBUG LOG END------*/
909 //! called from session finalize use in upstream thread.
910 //! @param[in] upstream thread id.
911 //! @param[in] downstream thread id
912 //! @return session use EVENT mode.
913 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_session_finalize(
914 const boost::thread::id up_thread_id, const boost::thread::id down_thread_id)
917 /*-------- DEBUG LOG --------*/
918 if (unlikely(LOG_LV_DEBUG == getloglevel()))
920 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
921 "handle_session_finalize(const boost::thread::id up_thread_id, "
922 "const boost::thread::id down_thread_id) : "
923 "up_thread_id = %d, down_thread_id = %d.");
924 formatter % up_thread_id % down_thread_id;
925 putLogDebug(100028, formatter.str(), __FILE__, __LINE__ );
927 /*------DEBUG LOG END------*/
928 EVENT_TAG status = STOP;
929 thread_data_ptr p_up;
930 thread_data_ptr p_down;
931 session_thread_data_map_it session_thread_data_it;
932 recive_data_map_it recive_data_it;
934 //session thread free
937 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
939 session_thread_data_it = session_thread_data_map.find(up_thread_id);
940 if (session_thread_data_it != session_thread_data_map.end())
942 p_up = session_thread_data_it->second;
943 /*-------- DEBUG LOG --------*/
944 if (unlikely(LOG_LV_DEBUG == getloglevel()))
946 boost::format formatter("delete : address = &(%d).");
947 formatter % static_cast<void*>(p_up.get());
948 putLogDebug(100029, formatter.str(), __FILE__, __LINE__ );
950 /*------DEBUG LOG END------*/
951 session_thread_data_map.erase(up_thread_id);
954 session_thread_data_it = session_thread_data_map.find(down_thread_id);
955 if (session_thread_data_it != session_thread_data_map.end())
957 /*-------- DEBUG LOG --------*/
958 if (unlikely(LOG_LV_DEBUG == getloglevel()))
960 boost::format formatter("delete : address = &(%d).");
961 formatter % static_cast<void*>(p_down.get());
962 putLogDebug(100030, formatter.str(), __FILE__,
965 /*------DEBUG LOG END------*/
966 session_thread_data_map.erase(down_thread_id);
971 catch (const std::exception& ex)
973 std::cerr << "protocol_module_sessionless::handle_session_finalize() : exception : error = " << ex.what() << "." << std::endl;
974 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
975 "handle_session_finalize() : exception : error = %s. thread id : %d.");
976 formatter % ex.what() % boost::this_thread::get_id();
977 putLogError(100020, formatter.str(), __FILE__, __LINE__ );
982 std::cerr << "protocol_module_sessionless::handle_session_finalize() : Unknown exception." << std::endl;
983 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
984 "handle_session_finalize() : "
985 "Unknown exception. thread id : %d.");
986 formatter % boost::this_thread::get_id();
987 putLogError(100021, formatter.str(), __FILE__, __LINE__ );
991 /*-------- DEBUG LOG --------*/
992 if (unlikely(LOG_LV_DEBUG == getloglevel()))
994 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
995 "handle_session_finalize(const boost::thread::id up_thread_id, "
996 "const boost::thread::id down_thread_id) : return_value = %d. thread id : %d.");
997 formatter % status % boost::this_thread::get_id();
998 putLogDebug(100031, formatter.str(), __FILE__, __LINE__ );
1000 /*------DEBUG LOG END------*/
1004 //! called from after session accept.in client socket use in upstream thread.
1005 //! @param[in] upstream thread id.
1006 //! @return session use EVENT mode.
1007 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_accept(const boost::thread::id thread_id)
1010 /*-------- DEBUG LOG --------*/
1011 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1013 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1014 "handle_accept(const boost::thread::id thread_id) : thread_id = %d.");
1015 formatter % thread_id;
1016 putLogDebug(100032, formatter.str(), __FILE__, __LINE__ );
1018 /*------DEBUG LOG END------*/
1020 EVENT_TAG status = FINALIZE;
1021 thread_data_ptr session_data;
1022 session_thread_data_map_it session_thread_it;
1026 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
1028 session_thread_it = session_thread_data_map.find(thread_id);
1029 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
1031 boost::format formatter("Invalid thread id. thread id : %d.");
1032 formatter % boost::this_thread::get_id();
1033 putLogError(100022, formatter.str(), __FILE__, __LINE__ );
1037 session_data = session_thread_it->second;
1039 //set accept end flag ON
1040 session_data->accept_end_flag = ACCEPT_END_FLAG_ON;
1041 /*-------- DEBUG LOG --------*/
1042 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1044 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1045 "handle_accept(const boost::thread::id thread_id) : ACCEPT_END_FLAG_ON. thread id : %d.");
1046 formatter % boost::this_thread::get_id();
1047 putLogDebug(100033, formatter.str(), __FILE__, __LINE__ );
1049 /*------DEBUG LOG END------*/
1052 if (session_data->sorry_flag == SORRY_FLAG_ON)
1055 status = SORRYSERVER_SELECT;
1061 status = REALSERVER_SELECT;
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() : catch exception e = %d. thread id : %d.");
1071 formatter % e % boost::this_thread::get_id();
1072 putLogDebug(100034, formatter.str(), __FILE__, __LINE__ );
1075 /*------DEBUG LOG END------*/
1077 catch (const std::exception& ex)
1079 std::cerr << "protocol_module_sessionless::handle_accept() : exception : error = " << ex.what() << "." << std::endl;
1080 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1081 "handle_accept() : exception : error = %s. thread id : %d.");
1082 formatter % ex.what() % boost::this_thread::get_id();
1083 putLogError(100023, formatter.str(), __FILE__, __LINE__ );
1089 std::cerr << "protocol_module_sessionless::handle_accept() : Unknown exception." << std::endl;
1090 boost::format formatter("function : protocol_module_base::EVENT_TAG "
1091 "protocol_module_sessionless::handle_accept() : "
1092 "Unknown exception. thread id : %d.");
1093 formatter % boost::this_thread::get_id();
1094 putLogError(100024, formatter.str(), __FILE__, __LINE__ );
1098 /*-------- DEBUG LOG --------*/
1099 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1101 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1102 "handle_accept(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
1103 formatter % status % boost::this_thread::get_id();
1104 putLogDebug(100035, formatter.str(), __FILE__, __LINE__ );
1106 /*------DEBUG LOG END------*/
1110 //! called from after session recv in client socket. use in upstream thread.
1111 //! @param[in] upstream thread id
1112 //! @param[in] recive buffer refarence.
1113 //! @param[in] recive length
1114 //! @return session use EVENT mode.
1115 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_recv(const boost::thread::id thread_id,
1116 const boost::array<char, MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
1118 /*-------- DEBUG LOG --------*/
1119 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1121 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
1123 dump_memory(recvbuffer.data(), buffer_size, buffer);
1124 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1125 "handle_client_recv(const boost::thread::id thread_id, "
1126 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1127 "const size_t recvlen) : thread_id = %d, recvbuffer = %s, recvlen = %d.");
1128 formatter % thread_id % buffer % recvlen;
1129 putLogDebug(100036, formatter.str(), __FILE__, __LINE__ );
1131 /*------DEBUG LOG END------*/
1133 EVENT_TAG status = FINALIZE;
1134 size_t data_remain_start = 0;
1135 size_t data_remain_size = 0;
1136 size_t request_data_remain_size = 0;
1137 size_t header_offset = 0;
1138 size_t header_offset_len = 0;
1139 size_t content_length_header_offset = 0;
1140 size_t content_length_header_len = 0;
1141 size_t content_len_value = 0;
1143 size_t buffer_size = 0;
1144 const size_t cr_lf_len = strlen("\r\n\r\n");
1145 std::string str_value;
1146 const std::string http_header = "";
1147 const std::string content_header = "Content-Length";
1148 thread_data_ptr session_data;
1149 char* buffer1 = NULL;
1150 char* buffer2 = NULL;
1152 CHECK_RESULT_TAG check_result;
1153 session_thread_data_map_it session_thread_it;
1154 recive_data_map_it recive_data_it;
1157 if (recvlen > recvbuffer.size())
1159 std::cerr << "protocol_module_sessionless::handle_client_recv() : Data size bigger than buffer size." << std::endl;
1160 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
1161 formatter % boost::this_thread::get_id();
1162 putLogError(100025, formatter.str(), __FILE__, __LINE__ );
1163 /*-------- DEBUG LOG --------*/
1164 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1166 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1167 "handle_client_recv(const boost::thread::id thread_id, "
1168 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1169 "const size_t recvlen) : return_value = %d. thread id : %d.");
1170 formatter % FINALIZE % boost::this_thread::get_id();
1171 putLogDebug(100037, formatter.str(), __FILE__, __LINE__ );
1173 /*------DEBUG LOG END------*/
1180 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
1182 session_thread_it = session_thread_data_map.find(thread_id);
1183 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
1185 boost::format formatter("Invalid thread id. thread id : %d.");
1186 formatter % boost::this_thread::get_id();
1187 putLogError(100026, formatter.str(), __FILE__, __LINE__ );
1191 session_data = session_thread_it->second;
1195 if (session_data->end_flag == END_FLAG_ON)
1197 status = CLIENT_RECV;
1202 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
1203 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
1205 boost::format formatter("Invalid endpoint. thread id : %d.");
1206 formatter % boost::this_thread::get_id();
1207 putLogError(100027, formatter.str(), __FILE__, __LINE__ );
1211 recive_data& recv_data = recive_data_it->second;
1213 send_status_it it = recv_data.send_status_list.begin();
1214 send_status_it it_end = recv_data.send_status_list.end();
1217 it = std::find_if(it, it_end, data_send_ok());
1218 if (unlikely(it != it_end))
1220 boost::format formatter("Sending data is not correct. thread id : %d.");
1221 formatter % boost::this_thread::get_id();
1222 putLogError(100028, formatter.str(), __FILE__, __LINE__ );
1227 it = recv_data.send_status_list.begin();
1228 it = std::adjacent_find(it, it_end, data_send_repeated());
1229 if (unlikely(it != it_end))
1231 boost::format formatter("Sending data is not correct. thread id : %d.");
1232 formatter % boost::this_thread::get_id();
1233 putLogError(100029, formatter.str(), __FILE__, __LINE__ );
1237 /*-------- DEBUG LOG --------*/
1238 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1240 std::string datadump;
1241 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
1242 "send_rest_size = %d, send_possible_size = %d, "
1243 "send_offset = %d, unsend_size = %d, edit_division = %d.");
1245 for (it = recv_data.send_status_list.begin();
1246 it != recv_data.send_status_list.end();
1249 formatter % i % it->status % it->send_end_size
1250 % it->send_rest_size % it->send_possible_size
1251 % it->send_offset % it->unsend_size % it->edit_division;
1252 datadump += formatter.str();
1255 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1256 "handle_client_recv() : send status list dump : send status list size = %d.%s");
1258 formatter % recv_data.send_status_list.size() % datadump;
1259 putLogDebug(100038, formatter.str(), __FILE__, __LINE__ );
1261 /*------DEBUG LOG END------*/
1263 it = recv_data.send_status_list.begin();
1264 //get original status info
1265 while (it != it_end)
1267 //item status is SEND_END
1268 if (it->status == SEND_END)
1271 recv_data.send_status_list.erase(it++);
1274 //item status is SEND_CONTINUE
1275 else if (it->status == SEND_CONTINUE)
1277 it->send_offset += it->send_end_size;
1278 data_remain_start = it->send_offset;
1281 //item status is SEND_NG
1284 data_remain_start = it->send_offset;
1285 data_remain_size = it->unsend_size;
1291 /*-------- DEBUG LOG --------*/
1292 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1294 std::string datadump;
1295 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
1296 "send_rest_size = %d, send_possible_size = %d, "
1297 "send_offset = %d, unsend_size = %d, edit_division = %d.");
1299 for (it = recv_data.send_status_list.begin();
1300 it != recv_data.send_status_list.end();
1303 formatter % i % it->status % it->send_end_size
1304 % it->send_rest_size % it->send_possible_size
1305 % it->send_offset % it->unsend_size % it->edit_division;
1306 datadump += formatter.str();
1309 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1310 "handle_client_recv() : send status list dump : send status list size = %d.%s");
1312 formatter % recv_data.send_status_list.size() % datadump;
1313 putLogDebug(100039, formatter.str(), __FILE__, __LINE__ );
1315 /*------DEBUG LOG END------*/
1317 //recive buffer process
1318 //buffer rest size < request size
1319 if (recv_data.recive_buffer_rest_size < recvlen)
1321 //buffer max size < remain size + request size
1322 //buffer is need reallocate
1323 if (recv_data.recive_buffer_max_size < data_remain_size + recvlen)
1325 //the buffer's size that will be allocated is exceed the upper limit value
1326 if (MAX_SESSIONLESS_MODULE_BUFFER_SIZE < data_remain_size + recvlen)
1328 std::cerr << "protocol_module_sessionless::handle_client_recv() : the buffer's size that will be allacted is exceed the upper limit value." << std::endl;
1329 boost::format formatter("The buffer's size that will be allocated is exceed the upper limit value. thread id : %d.");
1330 formatter % boost::this_thread::get_id();
1331 putLogError(100030, formatter.str(), __FILE__, __LINE__ );
1332 /*-------- DEBUG LOG --------*/
1333 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1335 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1336 "handle_client_recv(const boost::thread::id thread_id, "
1337 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1338 "const size_t recvlen) : return_value = %d. thread id : %d.");
1339 formatter % FINALIZE % boost::this_thread::get_id();
1340 putLogDebug(100040, formatter.str(), __FILE__, __LINE__ );
1342 /*------DEBUG LOG END------*/
1346 buffer_size = (data_remain_size + recvlen) > MAX_BUFFER_SIZE ? (data_remain_size + recvlen) : MAX_BUFFER_SIZE;
1347 //recive_buffer1's memory allocate and initialization
1348 buffer1 = new char[buffer_size];
1349 /*-------- DEBUG LOG --------*/
1350 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1352 boost::format formatter("new : address = &(%d), size = %lu.");
1353 formatter % static_cast<void*>(buffer1) % buffer_size;
1354 putLogDebug(100041, formatter.str(), __FILE__, __LINE__ );
1356 /*------DEBUG LOG END------*/
1357 memset(buffer1, 0, buffer_size);
1358 //recive_buffer2's memory allocate and initialization
1359 buffer2 = new char[buffer_size];
1360 /*-------- DEBUG LOG --------*/
1361 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1363 boost::format formatter("new : address = &(%d), size = %lu.");
1364 formatter % static_cast<void*>(buffer2) % buffer_size;
1365 putLogDebug(100042, formatter.str(), __FILE__, __LINE__ );
1367 /*------DEBUG LOG END------*/
1368 memset(buffer2, 0, buffer_size);
1370 /*-------- DEBUG LOG --------*/
1371 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1373 std::string datadump;
1374 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
1375 boost::format formatter(
1376 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1377 "handle_client_recv() : before memcpy (data dump) : "
1378 "data begin = %d, data_size = %d, data = %s");
1379 formatter % data_remain_start % data_remain_size % datadump;
1380 putLogDebug(100043, formatter.str(), __FILE__, __LINE__ );
1382 /*------DEBUG LOG END------*/
1383 //copy data from old buffer to new buffer
1384 memcpy(buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
1385 /*-------- DEBUG LOG --------*/
1386 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1388 std::string datadump;
1389 dump_memory(buffer1, data_remain_size, datadump);
1390 boost::format formatter(
1391 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1392 "handle_client_recv() : after memcpy (data dump) : "
1393 "data begin = 0, data_size = %d, data = %s");
1394 formatter % data_remain_size % datadump;
1395 putLogDebug(100044, formatter.str(), __FILE__, __LINE__ );
1397 /*------DEBUG LOG END------*/
1399 /*-------- DEBUG LOG --------*/
1400 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1402 std::string datadump;
1403 dump_memory(recvbuffer.data(), recvlen, datadump);
1404 boost::format formatter(
1405 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1406 "handle_client_recv() : before memcpy (data dump) : "
1407 "data begin = 0, data_size = %d, data = %s");
1408 formatter % recvlen % datadump;
1409 putLogDebug(100045, formatter.str(), __FILE__, __LINE__ );
1411 /*------DEBUG LOG END------*/
1412 memcpy(buffer1 + data_remain_size, recvbuffer.data(), recvlen);
1413 /*-------- DEBUG LOG --------*/
1414 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1416 std::string datadump;
1417 dump_memory(buffer1 + data_remain_size, recvlen, datadump);
1418 boost::format formatter(
1419 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1420 "handle_client_recv() : after memcpy (data dump) : "
1421 "data begin = %d, data_size = %d, data = %s");
1422 formatter % data_remain_size % recvlen % datadump;
1423 putLogDebug(100046, formatter.str(), __FILE__, __LINE__ );
1425 /*------DEBUG LOG END------*/
1426 //free old buffer1 and old buffer2
1427 if (recv_data.recive_buffer1 != NULL)
1429 /*-------- DEBUG LOG --------*/
1430 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1432 boost::format formatter("delete : address = &(%d).");
1433 formatter % static_cast<void*>(recv_data.recive_buffer1);
1434 putLogDebug(100047, formatter.str(), __FILE__,
1437 /*------DEBUG LOG END------*/
1438 delete[] recv_data.recive_buffer1;
1439 recv_data.recive_buffer1 = NULL;
1442 if (recv_data.recive_buffer2 != NULL)
1444 /*-------- DEBUG LOG --------*/
1445 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1447 boost::format formatter("delete : address = &(%d).");
1448 formatter % static_cast<void*>(recv_data.recive_buffer2);
1449 putLogDebug(100048, formatter.str(), __FILE__,
1452 /*------DEBUG LOG END------*/
1453 delete[] recv_data.recive_buffer2;
1454 recv_data.recive_buffer2 = NULL;
1457 //set new buffer pointer
1458 recv_data.recive_buffer1 = buffer1;
1459 recv_data.recive_buffer2 = buffer2;
1460 recv_data.recive_buffer = recv_data.recive_buffer1;
1461 //set new buffer's max size
1462 recv_data.recive_buffer_max_size = buffer_size;
1464 //buffer's max size >= remain data size + requst size
1465 //buffer isn't need reallocate, but switch
1468 //pointer valid check
1469 if (unlikely(recv_data.recive_buffer1 == NULL || recv_data.recive_buffer2 == NULL))
1471 boost::format formatter("Invalid pointer. thread id : %d.");
1472 formatter % boost::this_thread::get_id();
1473 putLogError(100031, formatter.str(), __FILE__, __LINE__ );
1476 //using buffer is buffer1
1477 if (recv_data.recive_buffer == recv_data.recive_buffer1)
1479 //buffer2 initialization
1480 memset(recv_data.recive_buffer2, 0, recv_data.recive_buffer_max_size);
1481 /*-------- DEBUG LOG --------*/
1482 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1484 std::string datadump;
1485 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
1486 boost::format formatter(
1487 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1488 "handle_client_recv() : before memcpy (data dump) : "
1489 "data begin = %d, data_size = %d, data = %s");
1490 formatter % data_remain_start % data_remain_size % datadump;
1491 putLogDebug(100049, formatter.str(), __FILE__, __LINE__ );
1493 /*------DEBUG LOG END------*/
1494 //copy data from buffer1 to buffer2
1495 memcpy(recv_data.recive_buffer2, recv_data.recive_buffer + data_remain_start, data_remain_size);
1496 /*-------- DEBUG LOG --------*/
1497 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1499 std::string datadump;
1500 dump_memory(recv_data.recive_buffer2, recvlen, datadump);
1501 boost::format formatter(
1502 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1503 "handle_client_recv() : after memcpy (data dump) : "
1504 "data begin = 0, data_size = %d, data = %s");
1505 formatter % recvlen % datadump;
1506 putLogDebug(100050, formatter.str(), __FILE__, __LINE__ );
1508 /*------DEBUG LOG END------*/
1509 /*-------- DEBUG LOG --------*/
1510 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1512 std::string datadump;
1513 dump_memory(recvbuffer.data(), recvlen, datadump);
1514 boost::format formatter(
1515 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1516 "handle_client_recv() : before memcpy (data dump) : "
1517 "data begin = 0, data_size = %d, data = %s");
1518 formatter % recvlen % datadump;
1519 putLogDebug(100051, formatter.str(), __FILE__, __LINE__ );
1521 /*------DEBUG LOG END------*/
1522 memcpy(recv_data.recive_buffer2 + data_remain_size, recvbuffer.data(), recvlen);
1523 /*-------- DEBUG LOG --------*/
1524 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1526 std::string datadump;
1527 dump_memory(recv_data.recive_buffer2 + data_remain_size, recvlen, datadump);
1528 boost::format formatter(
1529 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1530 "handle_client_recv() : after memcpy (data dump) : "
1531 "data begin = %d, data_size = %d, data = %s");
1532 formatter % data_remain_size % recvlen % datadump;
1533 putLogDebug(100052, formatter.str(), __FILE__, __LINE__ );
1535 /*------DEBUG LOG END------*/
1536 //set buffer2 as using buffer
1537 recv_data.recive_buffer = recv_data.recive_buffer2;
1539 //using buffer is buffer2
1542 //buffer1 initializtion
1543 memset(recv_data.recive_buffer1, 0, recv_data.recive_buffer_max_size);
1544 /*-------- DEBUG LOG --------*/
1545 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1547 std::string datadump;
1548 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
1549 boost::format formatter(
1550 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1551 "handle_client_recv() : before memcpy (data dump) : "
1552 "data begin = %d, data_size = %d, data = %s");
1553 formatter % data_remain_start % data_remain_size % datadump;
1554 putLogDebug(100053, formatter.str(), __FILE__, __LINE__ );
1556 /*------DEBUG LOG END------*/
1557 //copy data from buffer2 to buffer1
1558 memcpy(recv_data.recive_buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
1559 /*-------- DEBUG LOG --------*/
1560 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1562 std::string datadump;
1563 dump_memory(recv_data.recive_buffer1, data_remain_size, datadump);
1564 boost::format formatter(
1565 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1566 "handle_client_recv() : after memcpy (data dump) : "
1567 "data begin = 0, data_size = %d, data = %s");
1568 formatter % data_remain_size % datadump;
1569 putLogDebug(100054, formatter.str(), __FILE__, __LINE__ );
1571 /*------DEBUG LOG END------*/
1572 /*-------- DEBUG LOG --------*/
1573 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1575 std::string datadump;
1576 dump_memory(recvbuffer.data(), recvlen, datadump);
1577 boost::format formatter(
1578 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1579 "handle_client_recv() : before memcpy (data dump) : "
1580 "data begin = 0, data_size = %d, data = %s");
1581 formatter % recvlen % datadump;
1582 putLogDebug(100055, formatter.str(), __FILE__, __LINE__ );
1584 /*------DEBUG LOG END------*/
1585 memcpy(recv_data.recive_buffer1 + data_remain_size, recvbuffer.data(), recvlen);
1586 /*-------- DEBUG LOG --------*/
1587 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1589 std::string datadump;
1590 dump_memory(recv_data.recive_buffer1 + data_remain_size, recvlen, datadump);
1591 boost::format formatter(
1592 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1593 "handle_client_recv() : after memcpy (data dump) : "
1594 "data begin = %d, data_size = %d, data = %s");
1595 formatter % data_remain_size % recvlen % datadump;
1596 putLogDebug(100056, formatter.str(), __FILE__, __LINE__ );
1598 /*------DEBUG LOG END------*/
1599 //set buffer1 as using buffer
1600 recv_data.recive_buffer = recv_data.recive_buffer1;
1604 //set buffer's rest size
1605 recv_data.recive_buffer_rest_size = recv_data.recive_buffer_max_size - data_remain_size - recvlen;
1607 //remain_size recalc
1608 data_remain_size += recvlen;
1610 send_status_it it_begin = recv_data.send_status_list.begin();
1611 send_status_it it_end = recv_data.send_status_list.end();
1614 for (; it_begin != it_end; ++it_begin)
1616 it_begin->send_offset -= data_remain_start;
1619 //buffer's rest size >= request size
1622 //pointer valid check
1623 if (unlikely(recv_data.recive_buffer == NULL))
1625 boost::format formatter("Invalid pointer. thread id : %d.");
1626 formatter % boost::this_thread::get_id();
1627 putLogError(100032, formatter.str(), __FILE__, __LINE__ );
1630 /*-------- DEBUG LOG --------*/
1631 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1633 std::string datadump;
1634 dump_memory(recvbuffer.data(), recvlen, datadump);
1635 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1636 "handle_client_recv() : before memcpy (data dump) : "
1637 "data begin = 0, data_size = %d, data = %s");
1638 formatter % recvlen % datadump;
1639 putLogDebug(100057, formatter.str(), __FILE__, __LINE__ );
1641 /*------DEBUG LOG END------*/
1642 //copy data from parameter to using buffer
1643 memcpy(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
1644 recvbuffer.data(), recvlen);
1645 /*-------- DEBUG LOG --------*/
1646 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1648 std::string datadump;
1649 dump_memory(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
1651 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1652 "handle_client_recv() : after memcpy (data dump) : "
1653 "data begin = %d, data_size = %d, data = %s");
1654 formatter % (recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size )
1655 % recvlen % datadump;
1656 putLogDebug(100058, formatter.str(), __FILE__, __LINE__ );
1658 /*------DEBUG LOG END------*/
1659 //buffer's rest size recalc
1660 recv_data.recive_buffer_rest_size -= recvlen;
1661 //remain data size recalc
1662 data_remain_size += recvlen;
1665 it = recv_data.send_status_list.begin();
1666 it_end = recv_data.send_status_list.end();
1668 //set request rest size
1669 request_data_remain_size = recvlen;
1671 //original status process
1672 for (; it != it_end; ++it)
1674 //status is SEND_CONTINUE
1675 if (it->status == SEND_CONTINUE)
1677 //send rest size > request size
1678 if (it->send_rest_size > request_data_remain_size)
1680 //send possible size recalc
1681 it->send_possible_size = request_data_remain_size;
1682 //send rest size recalc
1683 it->send_rest_size -= request_data_remain_size;
1684 //send end size recalc
1685 it->send_end_size = 0;
1686 //request size recalc
1687 request_data_remain_size = 0;
1689 //send rest size <= request size
1692 //send possible size recalc
1693 it->send_possible_size = it->send_rest_size;
1694 //send rest size recalc
1695 request_data_remain_size -= it->send_rest_size;
1696 //send end size recalc
1697 it->send_end_size = 0;
1698 //request size recalc
1699 it->send_rest_size = 0;
1701 //set edit_division flag off
1702 it->edit_division = EDIT_DIVISION_NO_EDIT;
1703 //set status SEND_OK
1704 it->status = SEND_OK;
1707 else if (it->status == SEND_NG)
1710 check_result = check_http_method(recv_data.recive_buffer + it->send_offset, data_remain_size);
1711 /*-------- DEBUG LOG --------*/
1712 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1714 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1715 "handle_client_recv() : call check_http_method : "
1716 "return_value = %d. thread id : %d.");
1717 formatter % check_result % boost::this_thread::get_id();
1718 putLogDebug(100059, formatter.str(), __FILE__, __LINE__ );
1720 /*------DEBUG LOG END------*/
1721 //check http method result is OK
1722 if (check_result == CHECK_OK)
1724 //check http version
1725 check_result = check_http_version(recv_data.recive_buffer + it->send_offset, data_remain_size);
1726 /*-------- DEBUG LOG --------*/
1727 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1729 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1730 "handle_client_recv() : call check_http_version : "
1731 "return_value = %d. thread id : %d.");
1732 formatter % check_result % boost::this_thread::get_id();
1733 putLogDebug(100060, formatter.str(), __FILE__, __LINE__ );
1735 /*------DEBUG LOG END------*/
1737 //check method and version result is OK
1738 if (check_result == CHECK_OK)
1740 //search http header
1741 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size, http_header,
1742 header_offset, header_offset_len);
1743 /*-------- DEBUG LOG --------*/
1744 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1746 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1747 "handle_client_recv() : call find_http_header : "
1748 "return_value = %d. thread id : %d.");
1749 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
1750 putLogDebug(100061, formatter.str(), __FILE__, __LINE__ );
1752 /*------DEBUG LOG END------*/
1753 //search http header result is OK
1756 //search Content_Length header
1757 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size,
1758 content_header, content_length_header_offset, content_length_header_len);
1759 /*-------- DEBUG LOG --------*/
1760 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1762 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1763 "handle_client_recv() : call find_http_header : "
1764 "return_value = %d. thread id : %d.");
1765 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
1766 putLogDebug(100062, formatter.str(), __FILE__, __LINE__ );
1768 /*------DEBUG LOG END------*/
1769 //search Content_Length result is OK
1772 //Get Content_Length header's numeric value
1773 for (pos = 0; recv_data.recive_buffer[it->send_offset + content_length_header_offset + pos] != ':' && pos
1774 < content_length_header_len; ++pos)
1776 if (pos == content_length_header_len)
1778 throw std::string("Content_Length field's value is invalid.");
1783 str_value.assign(recv_data.recive_buffer + it->send_offset + content_length_header_offset + pos,
1784 content_length_header_len - pos);
1786 size_t pos_end = str_value.find_last_of('\r');
1787 if (pos_end != std::string::npos)
1789 str_value = str_value.erase(pos_end);
1792 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos);
1794 str_value = str_value.substr(pos);
1798 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
1800 catch (const boost::bad_lexical_cast& ex)
1802 throw std::string("Content_Length field's value is invalid.");
1805 //send_rest_size recalc
1806 //set whole http header's length + Content_Length's value
1807 it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
1809 //search Content_Length result is NG
1812 //send_rest_size recalc
1813 //set whole http header's length
1814 it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
1816 //set edit_division flag on
1817 it->edit_division = EDIT_DIVISION_EDIT;
1819 //search http header result is NG
1822 //unsend_size recalc
1823 it->unsend_size += request_data_remain_size;
1824 //request data rest size recalc
1825 request_data_remain_size = 0;
1829 //check method and version result is NG
1830 else if (check_result == CHECK_NG)
1832 //set edit_division flag off
1833 it->edit_division = EDIT_DIVISION_NO_EDIT;
1834 //send_rest_size recalc
1835 it->send_rest_size = it->unsend_size + request_data_remain_size;
1837 //check method and version result is CHECK_INPOSSIBLE
1840 //unsend_size recalc
1841 it->unsend_size += request_data_remain_size;
1842 //request data rest size recalc
1843 request_data_remain_size = 0;
1847 //recalc fields value according to send_rest_size and request rest size
1848 if (it->send_rest_size > it->unsend_size + request_data_remain_size)
1850 it->send_possible_size = it->unsend_size + request_data_remain_size;
1851 it->send_rest_size -= (it->unsend_size + request_data_remain_size);
1852 it->send_end_size = 0;
1853 it->unsend_size = 0;
1854 request_data_remain_size = 0;
1858 it->send_possible_size = it->send_rest_size;
1859 request_data_remain_size = it->unsend_size + request_data_remain_size - it->send_rest_size;
1860 it->send_end_size = 0;
1861 it->unsend_size = 0;
1862 it->send_rest_size = 0;
1865 //change status from SEND_NG to SEND_OK
1866 it->status = SEND_OK;
1868 //no request rest data to process
1869 if (request_data_remain_size <= 0)
1874 /*-------- DEBUG LOG --------*/
1875 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1877 std::string datadump;
1878 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
1879 "send_rest_size = %d, send_possible_size = %d, "
1880 "send_offset = %d, unsend_size = %d, edit_division = %d.");
1882 for (it = recv_data.send_status_list.begin();
1883 it != recv_data.send_status_list.end();
1886 formatter % i % it->status % it->send_end_size
1887 % it->send_rest_size % it->send_possible_size
1888 % it->send_offset % it->unsend_size % it->edit_division;
1889 datadump += formatter.str();
1892 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1893 "handle_client_recv() : send status list dump : send status list size = %d.%s");
1895 formatter % recv_data.send_status_list.size() % datadump;
1896 putLogDebug(100063, formatter.str(), __FILE__, __LINE__ );
1898 /*------DEBUG LOG END------*/
1899 //there are still rest data need to process
1900 //new status created and add to status list
1901 while (request_data_remain_size > 0)
1903 //new status created
1904 send_status new_send_state;
1906 new_send_state.edit_division = EDIT_DIVISION_NO_EDIT;
1907 new_send_state.send_end_size = 0;
1908 new_send_state.send_offset = 0;
1909 new_send_state.send_possible_size = 0;
1910 new_send_state.unsend_size = 0;
1911 new_send_state.send_rest_size = 0;
1912 //status initialize to SEND_NG
1913 new_send_state.status = SEND_NG;
1914 //add new status to status_list
1915 recv_data.send_status_list.push_back(new_send_state);
1916 std::list<send_status>::reverse_iterator new_send_it = recv_data.send_status_list.rbegin();
1918 new_send_it->send_offset = recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size
1919 - request_data_remain_size;
1922 check_result = check_http_method(recv_data.recive_buffer + new_send_it->send_offset,
1923 request_data_remain_size);
1924 /*-------- DEBUG LOG --------*/
1925 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1927 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1928 "handle_client_recv() : call check_http_method : "
1929 "return_value = %d. thread id : %d.");
1930 formatter % check_result % boost::this_thread::get_id();
1931 putLogDebug(100064, formatter.str(), __FILE__, __LINE__ );
1933 /*------DEBUG LOG END------*/
1934 //check http method result is OK
1935 if (check_result == CHECK_OK)
1937 //check http version
1938 check_result = check_http_version(recv_data.recive_buffer + new_send_it->send_offset,
1939 request_data_remain_size);
1940 /*-------- DEBUG LOG --------*/
1941 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1943 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1944 "handle_client_recv() : call check_http_version : "
1945 "return_value = %d. thread id : %d.");
1946 formatter % check_result % boost::this_thread::get_id();
1947 putLogDebug(100065, formatter.str(), __FILE__, __LINE__ );
1949 /*------DEBUG LOG END------*/
1951 //check http method and version result is OK
1952 if (check_result == CHECK_OK)
1954 //search whole http header, get whole http header's offset and length
1955 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset, request_data_remain_size,
1956 http_header, header_offset, header_offset_len);
1957 /*-------- DEBUG LOG --------*/
1958 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1960 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1961 "handle_client_recv() : call find_http_header : "
1962 "return_value = %d. thread id : %d.");
1963 formatter % check_result % boost::this_thread::get_id();
1964 putLogDebug(100066, formatter.str(), __FILE__, __LINE__ );
1966 /*------DEBUG LOG END------*/
1967 //searched whole http header
1970 //search ContentLength http header, get ContentLength header's offset and length
1971 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset,
1972 request_data_remain_size, content_header, content_length_header_offset, content_length_header_len);
1973 /*-------- DEBUG LOG --------*/
1974 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1976 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
1977 "handle_client_recv() : call find_http_header : "
1978 "return_value = %d. thread id : %d.");
1979 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
1980 putLogDebug(100067, formatter.str(), __FILE__, __LINE__ );
1982 /*------DEBUG LOG END------*/
1984 //searched ContentLength http header
1987 //Get Content_Length header's numeric value
1989 recv_data.recive_buffer[new_send_it->send_offset + content_length_header_offset + pos] != ':'
1990 && pos < content_length_header_len;
1992 if (pos == content_length_header_len)
1994 throw std::string("Content_Length field's value is invalid.");
1999 str_value.assign(recv_data.recive_buffer + new_send_it->send_offset + content_length_header_offset + pos,
2000 content_length_header_len - pos);
2002 size_t pos_end = str_value.find_last_of('\r');
2003 if (pos_end != std::string::npos)
2005 str_value = str_value.erase(pos_end);
2008 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos);
2010 str_value = str_value.substr(pos);
2013 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
2015 catch (const boost::bad_lexical_cast& ex)
2017 throw std::string("Content_Length field's value is invalid.");
2019 //send_rest_size recalc
2020 //set whole http header's + whole http header's length + Content_Length's value
2021 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
2023 //not searched ContentLength http header
2026 //send_rest_size recalc
2027 //set whole http header's + whole http header's length
2028 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
2031 //set edit_division flag on
2032 new_send_it->edit_division = EDIT_DIVISION_EDIT;
2034 //not searched whole http header
2037 new_send_it->unsend_size = request_data_remain_size;
2038 request_data_remain_size = 0;
2042 //check http method or version result is NG
2043 else if (check_result == CHECK_NG)
2045 new_send_it->edit_division = EDIT_DIVISION_NO_EDIT;
2046 new_send_it->send_rest_size = request_data_remain_size;
2049 //check http method or version result is impossible
2052 new_send_it->unsend_size = request_data_remain_size;
2053 request_data_remain_size = 0;
2057 //recalc fields value according to send_rest_size and request rest size
2058 if (new_send_it->send_rest_size > request_data_remain_size)
2060 new_send_it->send_possible_size = request_data_remain_size;
2061 new_send_it->send_rest_size -= request_data_remain_size;
2062 new_send_it->send_end_size = 0;
2063 request_data_remain_size = 0;
2067 new_send_it->send_possible_size = new_send_it->send_rest_size;
2068 request_data_remain_size -= new_send_it->send_rest_size;
2069 new_send_it->send_end_size = 0;
2070 new_send_it->send_rest_size = 0;
2073 //change status from SEND_NG to SEND_OK
2074 new_send_it->status = SEND_OK;
2077 /*-------- DEBUG LOG --------*/
2078 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2080 std::string datadump;
2081 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
2082 "send_rest_size = %d, send_possible_size = %d, "
2083 "send_offset = %d, unsend_size = %d, edit_division = %d.");
2085 for (it = recv_data.send_status_list.begin();
2086 it != recv_data.send_status_list.end();
2089 formatter % i % it->status % it->send_end_size
2090 % it->send_rest_size % it->send_possible_size
2091 % it->send_offset % it->unsend_size % it->edit_division;
2092 datadump += formatter.str();
2095 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2096 "handle_client_recv() : send status list dump : send status list size = %d.%s");
2098 formatter % recv_data.send_status_list.size() % datadump;
2099 putLogDebug(100068, formatter.str(), __FILE__, __LINE__ );
2101 /*------DEBUG LOG END------*/
2102 //search for send_possible item in status list
2103 send_status_it it_find = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
2104 data_send_possible());
2105 //the data that can be sent possible is exist
2106 if (it_find != recv_data.send_status_list.end())
2109 if (session_data->sorry_flag == SORRY_FLAG_ON)
2111 status = SORRYSERVER_CONNECT;
2116 status = REALSERVER_CONNECT;
2119 //the data that can be sent possible is not exist
2122 status = CLIENT_RECV;
2128 /*-------- DEBUG LOG --------*/
2129 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2131 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2132 "handle_client_recv() : catch exception e = %d. thread id : %d.");
2133 formatter % e % boost::this_thread::get_id();
2134 putLogDebug(100069, formatter.str(), __FILE__, __LINE__ );
2136 /*------DEBUG LOG END------*/
2139 catch (const std::string& ex)
2141 std::cerr << "protocol_module_sessionless::handle_client_recv() : exception : " << ex << std::endl;
2142 boost::format formatter("protocol_module_sessionless::handle_client_recv() : exception : %s. thread id : %d.");
2143 formatter % ex.c_str() % boost::this_thread::get_id();
2144 putLogError(100033, formatter.str(), __FILE__, __LINE__ );
2147 catch (const std::bad_alloc&)
2149 std::cerr << "protocol_module_sessionless::handle_client_recv() : exception : Could not allocate memory." << std::endl;
2150 boost::format formatter("Could not allocate memory. thread id : %d.");
2151 formatter % boost::this_thread::get_id();
2152 putLogError(100034, formatter.str(), __FILE__, __LINE__ );
2155 catch (const std::exception& ex)
2157 std::cerr << "protocol_module_sessionless::handle_client_recv() : exception : error = " << ex.what() << "." << std::endl;
2158 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2159 "handle_client_recv() : exception : error = %s. thread id : %d.");
2160 formatter % ex.what() % boost::this_thread::get_id();
2161 putLogError(100035, formatter.str(), __FILE__, __LINE__ );
2167 std::cerr << "protocol_module_sessionless::handle_client_recv() : Unknown exception." << std::endl;
2168 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2169 "protocol_module_sessionless::handle_client_recv() : "
2170 "Unknown exception. thread id : %d.");
2171 formatter % boost::this_thread::get_id();
2172 putLogError(100036, formatter.str(), __FILE__, __LINE__ );
2176 /*-------- DEBUG LOG --------*/
2177 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2179 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2180 "handle_client_recv(const boost::thread::id thread_id, "
2181 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
2182 "const size_t recvlen) : return_value = %d. thread id : %d.");
2183 formatter % status % boost::this_thread::get_id();
2184 putLogDebug(100070, formatter.str(), __FILE__, __LINE__ );
2186 /*------DEBUG LOG END------*/
2191 //! called from after realserver select.use in upstream thread.
2192 //! @param[in] upstream thread id
2193 //! @param[out] realserver TCP endpoint
2194 //! @return session use EVENT mode.
2195 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_select(
2196 const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint & rs_endpoint)
2198 /*-------- DEBUG LOG --------*/
2199 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2201 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2202 "handle_realserver_select(const boost::thread::id thread_id, "
2203 "boost::asio::ip::tcp::endpoint & rs_endpoint) : "
2204 "thread_id = %d, rs_endpoint = [%s]:%d.");
2205 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
2206 putLogDebug(100071, formatter.str(), __FILE__, __LINE__ );
2208 /*------DEBUG LOG END------*/
2209 EVENT_TAG status = FINALIZE;
2210 boost::asio::ip::tcp::endpoint tmp_endpoint;
2211 thread_data_ptr session_data;
2212 session_thread_data_map_it session_thread_it;
2213 session_thread_data_map_it session_thread_it_end;
2214 recive_data_map_it recive_data_it;
2216 if (schedule_tcp.empty())
2218 std::cerr << "protocol_module_sessionless::handle_realserver_select() : Schedule_tcp function is empty." << std::endl;
2219 boost::format formatter("Schedule_tcp function is empty. thread id : %d.");
2220 formatter % boost::this_thread::get_id();
2221 putLogError(100037, formatter.str(), __FILE__, __LINE__ );
2222 /*-------- DEBUG LOG --------*/
2223 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2225 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2226 "handle_realserver_select(const boost::thread::id thread_id, "
2227 "boost::asio::ip::tcp::endpoint & rs_endpoint)"
2228 " : return_value = %d. thread id : %d.");
2229 formatter % FINALIZE % boost::this_thread::get_id();
2230 putLogDebug(100072, formatter.str(), __FILE__, __LINE__ );
2232 /*------DEBUG LOG END------*/
2239 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
2241 session_thread_it = session_thread_data_map.find(thread_id);
2242 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2244 boost::format formatter("Invalid thread id. thread id : %d.");
2245 formatter % boost::this_thread::get_id();
2246 putLogError(100038, formatter.str(), __FILE__, __LINE__ );
2250 session_data = session_thread_it->second;
2253 //call schedule_module's schedule function, get realserver endpoint
2254 schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, rs_endpoint);
2255 /*-------- DEBUG LOG --------*/
2256 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2258 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2259 "handle_realserver_select() : call schedule_tcp : "
2260 "rs_endpoint = [%s]:%d. thread id : %d.");
2261 formatter % rs_endpoint.address().to_string() % rs_endpoint.port() % boost::this_thread::get_id();
2262 putLogDebug(100073, formatter.str(), __FILE__, __LINE__ );
2264 /*------DEBUG LOG END------*/
2267 if (rs_endpoint != tmp_endpoint)
2270 session_data->target_endpoint = rs_endpoint;
2272 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
2273 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
2275 boost::format formatter("Invalid endpoint. thread id : %d.");
2276 formatter % boost::this_thread::get_id();
2277 putLogError(100039, formatter.str(), __FILE__, __LINE__ );
2280 recive_data& recv_data = recive_data_it->second;
2282 send_status_it it = recv_data.send_status_list.begin();
2283 send_status_it it_end = recv_data.send_status_list.end();
2285 it = find_if(it, it_end, data_send_possible());
2288 status = REALSERVER_CONNECT;
2292 status = CLIENT_RECV;
2298 session_data->end_flag = END_FLAG_ON;
2299 /*-------- DEBUG LOG --------*/
2300 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2302 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2303 "handle_realserver_select() : END_FLAG_ON. thread id : %d.");
2304 formatter % boost::this_thread::get_id();
2305 putLogDebug(100074, formatter.str(), __FILE__, __LINE__ );
2307 /*------DEBUG LOG END------*/
2308 status = CLIENT_DISCONNECT;
2313 /*-------- DEBUG LOG --------*/
2314 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2316 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2317 "handle_realserver_select() : catch exception e = %d. thread id : %d.");
2318 formatter % e % boost::this_thread::get_id();
2319 putLogDebug(100075, formatter.str(), __FILE__, __LINE__ );
2322 /*------DEBUG LOG END------*/
2324 catch (const std::exception& ex)
2326 std::cerr << "protocol_module_sessionless::handle_realserver_select() : exception : error = " << ex.what() << "." << std::endl;
2327 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2328 "handle_realserver_select() : exception : error = %s. thread id : %d.");
2329 formatter % ex.what() % boost::this_thread::get_id();
2330 putLogError(100040, formatter.str(), __FILE__, __LINE__ );
2335 std::cerr << "protocol_module_sessionless::handle_realserver_select() : Unknown exception." << std::endl;
2336 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2337 "protocol_module_sessionless::handle_realserver_select() : "
2338 "Unknown exception. thread id : %d.");
2339 formatter % boost::this_thread::get_id();
2340 putLogError(100041, formatter.str(), __FILE__, __LINE__ );
2344 /*-------- DEBUG LOG --------*/
2345 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2347 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2348 "handle_realserver_select(const boost::thread::id thread_id, "
2349 "boost::asio::ip::tcp::endpoint & rs_endpoint)"
2350 " : return_value = %d. thread id : %d.");
2351 formatter % status % boost::this_thread::get_id();
2352 putLogDebug(100076, formatter.str(), __FILE__, __LINE__ );
2354 /*------DEBUG LOG END------*/
2359 //! called from after realserver select
2360 //! @param[in] upstream thread id
2361 //! @param[out] realserver UDP endpoint
2362 //! @param[out] sendbuffer reference
2363 //! @param[out] send data length
2364 //! @return session use EVENT mode.
2365 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_select(
2366 const boost::thread::id thread_id, boost::asio::ip::udp::endpoint& rs_endpoint, boost::array<char,
2367 MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
2369 /*-------- DEBUG LOG --------*/
2370 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2372 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2373 "handle_realserver_select(const boost::thread::id thread_id, "
2374 "boost::asio::ip::udp::endpoint& rs_endpoint, boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
2375 "size_t& datalen) : "
2376 "return_value = %d. thread id : %d.");
2377 formatter % STOP % boost::this_thread::get_id();
2378 putLogDebug(100077, formatter.str(), __FILE__, __LINE__ );
2380 /*------DEBUG LOG END------*/
2383 //! called from after realserver connect
2384 //! @param[in] upstream thread id
2385 //! @param[out] sendbuffer reference
2386 //! @param[out] send data length
2387 //! @return session use EVENT mode.
2388 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_connect(
2389 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
2391 /*-------- DEBUG LOG --------*/
2392 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2394 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2395 "handle_realserver_connect(const boost::thread::id thread_id, "
2396 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
2398 formatter % thread_id;
2399 putLogDebug(100078, formatter.str(), __FILE__, __LINE__ );
2401 /*------DEBUG LOG END------*/
2403 EVENT_TAG status = FINALIZE;
2405 size_t header_offset = 0;
2406 size_t header_offset_len = 0;
2407 size_t send_buffer_remian_size = 0;
2408 size_t copy_size = 0;
2409 const int send_buffer_end_size = sendbuffer.max_size();
2410 const std::string http_header = "";
2411 const std::string str_forword_for = "X-Forwarded-For";
2412 thread_data_ptr session_data;
2413 session_thread_data_map_it session_thread_it;
2414 recive_data_map_it recive_data_it;
2419 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
2422 session_thread_it = session_thread_data_map.find(thread_id);
2423 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2425 boost::format formatter("Invalid thread id. thread id : %d.");
2426 formatter % boost::this_thread::get_id();
2427 putLogError(100042, formatter.str(), __FILE__, __LINE__ );
2431 session_data = session_thread_it->second;
2435 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
2436 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
2438 boost::format formatter("Invalid endpoint. thread id : %d.");
2439 formatter % boost::this_thread::get_id();
2440 putLogError(100043, formatter.str(), __FILE__, __LINE__ );
2444 //recive_buffer pointer check
2445 recive_data& recv_data = recive_data_it->second;
2446 if (unlikely(recv_data.recive_buffer == NULL))
2448 boost::format formatter("Invalid pointer. thread id : %d.");
2449 formatter % boost::this_thread::get_id();
2450 putLogError(100044, formatter.str(), __FILE__, __LINE__ );
2455 send_status_it it = recv_data.send_status_list.begin();
2456 send_status_it it_end = recv_data.send_status_list.end();
2457 it = find_if(it, it_end, data_send_possible());
2458 if (unlikely(it == it_end))
2460 boost::format formatter("Sending possible data is not existed. thread id : %d.");
2461 formatter % boost::this_thread::get_id();
2462 putLogError(100045, formatter.str(), __FILE__, __LINE__ );
2466 //send buffer rest size initialization
2467 send_buffer_remian_size = send_buffer_end_size;
2469 //edit_division flag on
2470 if (it->edit_division == EDIT_DIVISION_EDIT && forwarded_for == FORWARDED_FOR_ON)
2472 //edit list is empty
2473 if (it->edit_data_list.empty())
2477 edata.data_size = 0;
2478 edata.insert_posission = 0;
2479 edata.replace_size = 0;
2480 //search X-Forwarded-For header
2481 ret = find_http_header(recv_data.recive_buffer + it->send_offset, it->send_possible_size,
2482 str_forword_for, header_offset, header_offset_len);
2483 /*-------- DEBUG LOG --------*/
2484 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2486 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2487 "handle_realserver_connect() : call find_http_header : "
2488 "return_value = %d. thread id : %d.");
2489 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
2490 putLogDebug(100079, formatter.str(), __FILE__, __LINE__ );
2492 /*------DEBUG LOG END------*/
2493 //search http header result is OK
2496 //edit X-Forwarded-For header, set it to edata.data
2497 edata.data.assign(recv_data.recive_buffer + it->send_offset + header_offset, header_offset_len);
2499 edata.data += session_data->client_endpoint_tcp.address().to_string();
2500 //save new X-Forwarded-For header offset
2501 edata.insert_posission = header_offset;
2502 //save new X-Forwarded-For header length
2503 edata.data_size = edata.data.size();
2504 //save old X-Forwarded-For header length
2505 edata.replace_size = header_offset_len;
2507 //search http header result is NG
2510 //search whole http header, get whole http header's offset and length
2511 ret = find_http_header(recv_data.recive_buffer + it->send_offset, it->send_possible_size, "",
2512 header_offset, header_offset_len);
2513 /*-------- DEBUG LOG --------*/
2514 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2516 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2517 "handle_realserver_connect() : call find_http_header : "
2518 "return_value = %d. thread id : %d.");
2519 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
2520 putLogDebug(100080, formatter.str(), __FILE__, __LINE__ );
2522 /*------DEBUG LOG END------*/
2525 boost::format formatter("find_http_header() function failure. thread id : %d.");
2526 formatter % boost::this_thread::get_id();
2527 putLogError(100046, formatter.str(), __FILE__, __LINE__ );
2528 /*-------- DEBUG LOG --------*/
2529 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2531 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2532 "handle_realserver_connect(const boost::thread::id thread_id, "
2533 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
2534 "size_t& datalen) : return_value = %d. thread id : %d.");
2535 formatter % FINALIZE % boost::this_thread::get_id();
2536 putLogDebug(100081, formatter.str(), __FILE__, __LINE__ );
2538 /*------DEBUG LOG END------*/
2541 //create X-Forwarded-For header, put it to edata.data
2542 edata.data = str_forword_for;
2544 edata.data += session_data->client_endpoint_tcp.address().to_string();
2545 edata.data += "\r\n";
2546 //save new X-Forwarded-For header offset
2547 edata.insert_posission = header_offset;
2548 //save new X-Forwarded-For header length
2549 edata.data_size = edata.data.size();
2550 //save old X-Forwarded-For header length
2551 edata.replace_size = 0;
2554 //add to edit_data_list
2555 it->edit_data_list.push_back(edata);
2558 /*-------- DEBUG LOG --------*/
2559 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2561 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2562 "handle_realserver_connect() : Copy data loop start. thread id : %d.");
2563 formatter % boost::this_thread::get_id();
2564 putLogDebug(100082, formatter.str(), __FILE__, __LINE__ );
2566 /*------DEBUG LOG END------*/
2569 //edit_data_list is empty
2570 if (it->edit_data_list.empty())
2572 //set edit_division flag on
2573 it->edit_division = EDIT_DIVISION_NO_EDIT;
2575 if (send_buffer_remian_size > 0 && it->send_possible_size > 0)
2577 //send_buffer_remian_size is larger
2578 if (send_buffer_remian_size >= it->send_possible_size)
2580 copy_size = it->send_possible_size;
2581 /*-------- DEBUG LOG --------*/
2582 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2584 std::string datadump;
2585 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
2586 it->send_possible_size, datadump);
2587 boost::format formatter(
2588 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2589 "handle_realserver_connect() : before memcpy (data dump) : "
2590 "data begin = %d, data_size = %d, data = %s");
2591 formatter % (it->send_offset + it->send_end_size)
2592 % copy_size % datadump;
2593 putLogDebug(100083, formatter.str(), __FILE__, __LINE__ );
2595 /*------DEBUG LOG END------*/
2596 //copy data from recive_buffer to sendbuffer by sending_possible size
2597 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2598 recv_data.recive_buffer + it->send_offset + it->send_end_size,
2599 it->send_possible_size);
2600 /*-------- DEBUG LOG --------*/
2601 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2603 std::string datadump;
2604 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2605 it->send_possible_size, datadump);
2607 boost::format formatter(
2608 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2609 "handle_realserver_connect() : after memcpy (data dump) : "
2610 "data begin = %d, data_size = %d, data = %s");
2611 formatter % (send_buffer_end_size - send_buffer_remian_size)
2612 % copy_size % datadump;
2613 putLogDebug(100084, formatter.str(), __FILE__, __LINE__ );
2615 /*------DEBUG LOG END------*/
2617 it->send_end_size += copy_size;
2618 it->send_possible_size = 0;
2619 send_buffer_remian_size -= copy_size;
2621 //send_possible_size is larger
2624 copy_size = send_buffer_remian_size;
2625 /*-------- DEBUG LOG --------*/
2626 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2628 std::string datadump;
2629 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
2630 copy_size, datadump);
2632 boost::format formatter(
2633 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2634 "handle_realserver_connect() : before memcpy (data dump) : "
2635 "data begin = %d, data_size = %d, data = %s");
2636 formatter % (it->send_offset + it->send_end_size)
2637 % copy_size % datadump;
2638 putLogDebug(100085, formatter.str(), __FILE__, __LINE__ );
2640 /*------DEBUG LOG END------*/
2641 //copy data from recive_buffer to sendbuffer by send buffer rest size
2642 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2643 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
2644 /*-------- DEBUG LOG --------*/
2645 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2647 std::string datadump;
2648 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2649 copy_size, datadump);
2651 boost::format formatter(
2652 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2653 "handle_realserver_connect() : after memcpy (data dump) : "
2654 "data begin = %d, data_size = %d, data = %s");
2655 formatter % (send_buffer_end_size - send_buffer_remian_size)
2656 % copy_size % datadump;
2657 putLogDebug(100086, formatter.str(), __FILE__, __LINE__ );
2659 /*------DEBUG LOG END------*/
2660 it->send_end_size += copy_size;
2661 it->send_possible_size -= copy_size;
2662 send_buffer_remian_size = 0;
2667 //edit_data_list is not empty
2670 //find the item in the list which has mininum insert_posission
2671 std::list<edit_data>::iterator edit_min = std::min_element(it->edit_data_list.begin(),
2672 it->edit_data_list.end());
2673 //send_buffer_remian_size is larger than data that before X-Forwarded-For
2674 if (send_buffer_remian_size >= edit_min->insert_posission - it->send_end_size)
2676 //copy data before X-Forwarded-For
2677 copy_size = edit_min->insert_posission - it->send_end_size;
2678 /*-------- DEBUG LOG --------*/
2679 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2681 std::string datadump;
2682 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
2683 copy_size, datadump);
2685 boost::format formatter(
2686 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2687 "handle_realserver_connect() : before memcpy (data dump) : "
2688 "data begin = %d, data_size = %d, data = %s");
2689 formatter % (it->send_offset + it->send_end_size)
2690 % copy_size % datadump;
2691 putLogDebug(100087, formatter.str(), __FILE__, __LINE__ );
2693 /*------DEBUG LOG END------*/
2694 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2695 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
2696 /*-------- DEBUG LOG --------*/
2697 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2699 std::string datadump;
2700 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2701 copy_size, datadump);
2702 boost::format formatter(
2703 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2704 "handle_realserver_connect() : after memcpy (data dump) : "
2705 "data begin = %d, data_size = %d, data = %s");
2706 formatter % (send_buffer_end_size - send_buffer_remian_size)
2707 % copy_size % datadump;
2708 putLogDebug(100088, formatter.str(), __FILE__, __LINE__ );
2710 /*------DEBUG LOG END------*/
2711 it->send_end_size += copy_size;
2712 it->send_possible_size -= copy_size;
2713 send_buffer_remian_size -= copy_size;
2715 //there is remain buffer for copy X-Forwarded-For
2716 if (send_buffer_remian_size >= edit_min->data_size)
2718 /*-------- DEBUG LOG --------*/
2719 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2721 std::string datadump;
2722 dump_memory(edit_min->data.c_str(),
2723 edit_min->data_size, datadump);
2725 boost::format formatter(
2726 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2727 "handle_realserver_connect() : before memcpy (data dump) : "
2728 "data begin = 0, data_size = %d, data = %s");
2729 formatter % edit_min->data_size % datadump;
2730 putLogDebug(100089, formatter.str(), __FILE__, __LINE__ );
2732 /*------DEBUG LOG END------*/
2733 //copy X-Forwarded-For
2734 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2735 edit_min->data.c_str(), edit_min->data_size);
2736 /*-------- DEBUG LOG --------*/
2737 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2739 std::string datadump;
2740 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2741 edit_min->data_size, datadump);
2742 boost::format formatter(
2743 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2744 "handle_realserver_connect() : after memcpy (data dump) : "
2745 "data begin = %d, data_size = %d, data = %s");
2746 formatter % (send_buffer_end_size - send_buffer_remian_size)
2747 % edit_min->data_size % datadump;
2748 putLogDebug(100090, formatter.str(), __FILE__, __LINE__ );
2750 /*------DEBUG LOG END------*/
2751 it->send_end_size += edit_min->replace_size;
2752 it->send_possible_size -= edit_min->replace_size;
2753 send_buffer_remian_size -= edit_min->data_size;
2754 it->edit_data_list.erase(edit_min);
2762 //data that before X-Forwarded-For is larger than send_buffer_remian_size
2765 copy_size = send_buffer_remian_size;
2766 /*-------- DEBUG LOG --------*/
2767 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2769 std::string datadump;
2770 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
2771 copy_size, datadump);
2773 boost::format formatter(
2774 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2775 "handle_realserver_connect() : before memcpy (data dump) : "
2776 "data begin = %d, data_size = %d, data = %s");
2777 formatter % (it->send_offset + it->send_end_size)
2778 % copy_size % datadump;
2779 putLogDebug(100091, formatter.str(), __FILE__, __LINE__ );
2781 /*------DEBUG LOG END------*/
2782 //copy data as large as possible
2783 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2784 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
2785 /*-------- DEBUG LOG --------*/
2786 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2788 std::string datadump;
2789 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
2790 copy_size, datadump);
2792 boost::format formatter(
2793 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2794 "handle_realserver_connect() : after memcpy (data dump) : "
2795 "data begin = %d, data_size = %d, data = %s");
2796 formatter % (send_buffer_end_size - send_buffer_remian_size)
2797 % copy_size % datadump;
2798 putLogDebug(100092, formatter.str(), __FILE__, __LINE__ );
2800 /*------DEBUG LOG END------*/
2802 it->send_end_size += copy_size;
2803 it->send_possible_size -= copy_size;
2804 send_buffer_remian_size -= copy_size;
2809 /*-------- DEBUG LOG --------*/
2810 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2812 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2813 "handle_realserver_connect() : Copy data loop end. thread id : %d.");
2814 formatter % boost::this_thread::get_id();
2815 putLogDebug(100093, formatter.str(), __FILE__, __LINE__ );
2817 /*------DEBUG LOG END------*/
2819 //edit_division flag is off
2822 //copy data as large as possible
2823 //send_possible_size is larger
2824 if (send_buffer_remian_size >= it->send_possible_size)
2826 copy_size = it->send_possible_size;
2827 /*-------- DEBUG LOG --------*/
2828 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2830 std::string datadump;
2831 dump_memory(recv_data.recive_buffer + it->send_offset,
2832 copy_size, datadump);
2833 boost::format formatter(
2834 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2835 "handle_realserver_connect() : before memcpy (data dump) : "
2836 "data begin = %d, data_size = %d, data = %s");
2837 formatter % it->send_offset
2838 % copy_size % datadump;
2839 putLogDebug(100094, formatter.str(), __FILE__, __LINE__ );
2841 /*------DEBUG LOG END------*/
2842 //copy data by send_possible size
2843 memcpy(sendbuffer.data(), recv_data.recive_buffer + it->send_offset, copy_size);
2844 /*-------- DEBUG LOG --------*/
2845 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2847 std::string datadump;
2848 dump_memory(sendbuffer.data(), copy_size, datadump);
2849 boost::format formatter(
2850 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2851 "handle_realserver_connect() : after memcpy (data dump) : "
2852 "data begin = 0, data_size = %d, data = %s");
2853 formatter % copy_size % datadump;
2854 putLogDebug(100095, formatter.str(), __FILE__, __LINE__ );
2856 /*------DEBUG LOG END------*/
2857 it->send_end_size = copy_size;
2858 it->send_possible_size = 0;
2859 send_buffer_remian_size -= copy_size;
2861 //buffer rest size is larger
2864 /*-------- DEBUG LOG --------*/
2865 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2867 std::string datadump;
2868 dump_memory(recv_data.recive_buffer + it->send_offset, send_buffer_remian_size, datadump);
2870 boost::format formatter(
2871 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2872 "handle_realserver_connect() : before memcpy (data dump) : "
2873 "data begin = %d, data_size = %d, data = %s");
2874 formatter % it->send_offset
2875 % send_buffer_remian_size % datadump;
2876 putLogDebug(100096, formatter.str(), __FILE__, __LINE__ );
2878 /*------DEBUG LOG END------*/
2879 //copy data by buffer rest size
2880 memcpy(sendbuffer.data(), recv_data.recive_buffer + it->send_offset, send_buffer_remian_size);
2881 /*-------- DEBUG LOG --------*/
2882 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2884 std::string datadump;
2885 dump_memory(sendbuffer.data(), send_buffer_remian_size, datadump);
2886 boost::format formatter(
2887 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2888 "handle_realserver_connect() : after memcpy (data dump) : "
2889 "data begin = 0, data_size = %d, data = %s");
2890 formatter % send_buffer_remian_size % datadump;
2891 putLogDebug(100097, formatter.str(), __FILE__, __LINE__ );
2893 /*------DEBUG LOG END------*/
2894 it->send_end_size = send_buffer_remian_size;
2895 it->send_possible_size -= send_buffer_remian_size;
2896 send_buffer_remian_size = 0;
2900 //set copyed data length
2901 datalen = send_buffer_end_size - send_buffer_remian_size;
2902 status = REALSERVER_SEND;
2906 /*-------- DEBUG LOG --------*/
2907 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2909 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2910 "handle_realserver_connect() : catch exception e = %d. thread id : %d.");
2911 formatter % e % boost::this_thread::get_id();
2912 putLogDebug(100098, formatter.str(), __FILE__, __LINE__ );
2915 /*------DEBUG LOG END------*/
2917 catch (const std::exception& ex)
2919 std::cerr << "protocol_module_sessionless::handle_realserver_connect() : exception : error = " << ex.what() << "." << std::endl;
2920 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2921 "handle_realserver_connect() : exception : error = %s. thread id : %d.");
2922 formatter % ex.what() % boost::this_thread::get_id();
2923 putLogError(100047, formatter.str(), __FILE__, __LINE__ );
2928 std::cerr << "protocol_module_sessionless::handle_realserver_connect() : Unknown exception." << std::endl;
2929 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2930 "handle_realserver_connect() : Unknown exception. thread id : %d.");
2931 formatter % boost::this_thread::get_id();
2932 putLogError(100048, formatter.str(), __FILE__, __LINE__ );
2936 /*-------- DEBUG LOG --------*/
2937 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2939 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2940 "handle_realserver_connect(const boost::thread::id thread_id, "
2941 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
2942 "size_t& datalen) : return_value = %d. thread id : %d.");
2943 formatter % status % boost::this_thread::get_id();
2944 putLogDebug(100099, formatter.str(), __FILE__, __LINE__ );
2946 /*------DEBUG LOG END------*/
2951 //! called from after realserver connection fail
2952 //! @param[in] upstream thread id
2953 //! @param[in] fail realserver endpoint reference
2954 //! @return session use EVENT mode.
2955 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_connection_fail(
2956 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint)
2958 /*-------- DEBUG LOG --------*/
2959 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2961 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2962 "handle_realserver_connection_fail(const boost::thread::id thread_id, "
2963 "const boost::asio::ip::tcp::endpoint & rs_endpoint) : "
2964 "thread_id = %d, rs_endpoint = [%s]:%d.");
2965 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
2966 putLogDebug(100100, formatter.str(), __FILE__, __LINE__ );
2968 /*------DEBUG LOG END------*/
2970 EVENT_TAG status = FINALIZE;
2971 thread_data_ptr session_data;
2972 session_thread_data_map_it session_thread_it;
2976 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
2978 session_thread_it = session_thread_data_map.find(thread_id);
2979 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2981 boost::format formatter("Invalid thread id. thread id : %d.");
2982 formatter % boost::this_thread::get_id();
2983 putLogError(100049, formatter.str(), __FILE__, __LINE__ );
2987 session_data = session_thread_it->second;
2990 session_data->end_flag = END_FLAG_ON;
2991 /*-------- DEBUG LOG --------*/
2992 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2994 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
2995 "handle_realserver_connection_fail() : END_FLAG_ON. thread id : %d.");
2996 formatter % boost::this_thread::get_id();
2997 putLogDebug(100101, formatter.str(), __FILE__, __LINE__ );
2999 /*------DEBUG LOG END------*/
3000 status = CLIENT_DISCONNECT;
3004 /*-------- DEBUG LOG --------*/
3005 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3007 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3008 "handle_realserver_connection_fail() : catch exception e = %d. thread id : %d.");
3009 formatter % e % boost::this_thread::get_id();
3010 putLogDebug(100102, formatter.str(), __FILE__, __LINE__ );
3013 /*------DEBUG LOG END------*/
3015 catch (std::exception& ex)
3017 std::cerr << "protocol_module_sessionless::handle_realserver_connection_fail() : exception : error = " << ex.what() << "." << std::endl;
3018 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3019 "handle_realserver_connection_fail() : exception : error = %s. thread id : %d.");
3020 formatter % ex.what() % boost::this_thread::get_id();
3021 putLogError(100050, formatter.str(), __FILE__, __LINE__ );
3026 std::cerr << "protocol_module_sessionless::handle_realserver_connection_fail() : Unknown exception." << std::endl;
3027 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3028 "handle_realserver_connection_fail() : Unknown exception. thread id : %d.");
3029 formatter % boost::this_thread::get_id();
3030 putLogError(100051, formatter.str(), __FILE__, __LINE__ );
3034 /*-------- DEBUG LOG --------*/
3035 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3037 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3038 "handle_realserver_connection_fail(const boost::thread::id thread_id, "
3039 "const boost::asio::ip::tcp::endpoint & rs_endpoint) : return_value = %d. thread id : %d.");
3040 formatter % status % boost::this_thread::get_id();
3041 putLogDebug(100103, formatter.str(), __FILE__, __LINE__ );
3043 /*------DEBUG LOG END------*/
3046 //! called from after realserver send.
3047 //! @param[in] upstream thread id
3048 //! @return session use EVENT mode.
3049 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_send(
3050 const boost::thread::id thread_id)
3052 /*-------- DEBUG LOG --------*/
3053 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3055 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3056 "handle_realserver_send(const boost::thread::id thread_id) : "
3058 formatter % thread_id;
3059 putLogDebug(100104, formatter.str(), __FILE__, __LINE__ );
3061 /*------DEBUG LOG END------*/
3062 EVENT_TAG status = FINALIZE;
3063 thread_data_ptr session_data;
3064 session_thread_data_map_it session_thread_it;
3065 recive_data_map_it recive_data_it;
3070 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
3073 session_thread_it = session_thread_data_map.find(thread_id);
3074 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3076 boost::format formatter("Invalid thread id. thread id : %d.");
3077 formatter % boost::this_thread::get_id();
3078 putLogError(100052, formatter.str(), __FILE__, __LINE__ );
3082 session_data = session_thread_it->second;
3086 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
3087 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
3089 boost::format formatter("Invalid endpoint. thread id : %d.");
3090 formatter % boost::this_thread::get_id();
3091 putLogError(100053, formatter.str(), __FILE__, __LINE__ );
3095 recive_data& recv_data = recive_data_it->second;
3097 send_status_it it = recv_data.send_status_list.begin();
3098 send_status_it it_end = recv_data.send_status_list.end();
3101 it = std::adjacent_find(it, it_end, data_send_list_incorrect());
3102 if (unlikely(it != it_end))
3104 boost::format formatter("Sending possible data is invalid. thread id : %d.");
3105 formatter % boost::this_thread::get_id();
3106 putLogError(100054, formatter.str(), __FILE__, __LINE__ );
3111 it = recv_data.send_status_list.begin();
3112 it = std::find_if(it, it_end, data_send_ok());
3113 if (unlikely(it == it_end))
3115 boost::format formatter("Sending possible data is not existed. thread id : %d.");
3116 formatter % boost::this_thread::get_id();
3117 putLogError(100055, formatter.str(), __FILE__, __LINE__ );
3121 //sending possible data is exist
3122 if (it->send_possible_size > 0)
3124 //status remain SEND_OK
3125 it->status = SEND_OK;
3127 it->send_offset += it->send_end_size;
3129 //insert_posission recalc
3130 for (std::list<edit_data>::iterator list_it = it->edit_data_list.begin(); list_it
3131 != it->edit_data_list.end(); ++list_it)
3133 list_it->insert_posission -= it->send_end_size;
3136 //send_end_size recalc
3137 it->send_end_size = 0;
3139 //sending possible data is not exist
3142 //can recive from client continue
3143 if (it->send_rest_size > 0)
3145 //change status from SEND_OK to SEND_CONTINUE
3146 it->status = SEND_CONTINUE;
3148 //can not recive from client continue
3151 //change status from SEND_OK to SEND_END
3152 it->status = SEND_END;
3156 it = recv_data.send_status_list.begin();
3157 it = find_if(it, it_end, data_send_ok());
3158 //send_ok item is exist
3161 status = REALSERVER_CONNECT;
3163 //send_ok item is exist
3166 status = CLIENT_RECV;
3172 /*-------- DEBUG LOG --------*/
3173 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3175 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3176 "handle_realserver_send() : catch exception e = %d. thread id : %d.");
3177 formatter % e % boost::this_thread::get_id();
3178 putLogDebug(100105, formatter.str(), __FILE__, __LINE__ );
3181 /*------DEBUG LOG END------*/
3183 catch (const std::exception& ex)
3185 std::cerr << "protocol_module_sessionless::handle_realserver_send() : exception : error = " << ex.what() << "." << std::endl;
3186 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3187 "handle_realserver_send() : exception : error = %s. thread id : %d.");
3188 formatter % ex.what() % boost::this_thread::get_id();
3189 putLogError(100056, formatter.str(), __FILE__, __LINE__ );
3195 std::cerr << "protocol_module_sessionless::handle_realserver_send() : Unknown exception." << std::endl;
3196 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3197 "handle_realserver_send() : Unknown exception. thread id : %d.");
3198 formatter % boost::this_thread::get_id();
3199 putLogError(100057, formatter.str(), __FILE__, __LINE__ );
3203 /*-------- DEBUG LOG --------*/
3204 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3206 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3207 "handle_realserver_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
3208 formatter % status % boost::this_thread::get_id();
3209 putLogDebug(100106, formatter.str(), __FILE__, __LINE__ );
3211 /*------DEBUG LOG END------*/
3216 //! called from after sorryserver select
3217 //! @param[in] upstream thread id
3218 //! @param[in] sorryserver endpiont reference
3219 //! @return session use EVENT mode.
3220 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_select(
3221 const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint& sorry_endpoint)
3223 /*-------- DEBUG LOG --------*/
3224 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3226 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3227 "handle_sorryserver_select(const boost::thread::id thread_id, "
3228 "boost::asio::ip::tcp::endpoint& sorry_endpoint) : "
3229 "thread_id = %d, sorry_endpoint = [%s]:%d.");
3230 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port();
3231 putLogDebug(100107, formatter.str(), __FILE__, __LINE__ );
3233 /*------DEBUG LOG END------*/
3234 EVENT_TAG status = FINALIZE;
3235 boost::asio::ip::tcp::endpoint client_endpoint;
3237 thread_data_ptr session_data;
3238 session_thread_data_map_it session_thread_it;
3239 recive_data_map_it recive_data_it;
3243 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
3245 session_thread_it = session_thread_data_map.find(thread_id);
3246 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second== NULL))
3248 boost::format formatter("Invalid thread id. thread id : %d.");
3249 formatter % boost::this_thread::get_id();
3250 putLogError(100058, formatter.str(), __FILE__, __LINE__ );
3254 session_data = session_thread_it->second;
3255 //set sorry_endpoint
3256 session_data->target_endpoint = sorry_endpoint;
3259 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
3260 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
3262 boost::format formatter("Invalid endpoint. thread id : %d.");
3263 formatter % boost::this_thread::get_id();
3264 putLogError(100059, formatter.str(), __FILE__, __LINE__ );
3268 recive_data& recv_data = recive_data_it->second;
3270 send_status_it it = recv_data.send_status_list.begin();
3271 send_status_it it_end = recv_data.send_status_list.end();
3273 it = find_if(it, it_end, data_send_possible());
3276 status = SORRYSERVER_CONNECT;
3280 status = CLIENT_RECV;
3286 /*-------- DEBUG LOG --------*/
3287 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3289 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3290 "handle_sorryserver_select() : catch exception e = %d. thread id : %d.");
3291 formatter % e % boost::this_thread::get_id();
3292 putLogDebug(100108, formatter.str(), __FILE__, __LINE__ );
3295 /*------DEBUG LOG END------*/
3297 catch (const std::bad_alloc& ex)
3299 std::cerr << "protocol_module_sessionless::handle_sorryserver_select() : exception : Could not allocate memory." << std::endl;
3300 boost::format formatter("Could not allocate memory. thread id : %d.");
3301 formatter % boost::this_thread::get_id();
3302 putLogError(100060, formatter.str(), __FILE__, __LINE__ );
3305 catch (const std::exception& ex)
3307 std::cerr << "protocol_module_sessionless::handle_sorryserver_select() : exception : error = " << ex.what() << "." << std::endl;
3308 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3309 "handle_sorryserver_select() : exception : error = %s. thread id : %d.");
3310 formatter % ex.what() % boost::this_thread::get_id();
3311 putLogError(100061, formatter.str(), __FILE__, __LINE__ );
3316 std::cerr << "protocol_module_sessionless::handle_sorryserver_select() : Unknown exception." << std::endl;
3317 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3318 "handle_sorryserver_select() : Unknown exception. thread id : %d.");
3319 formatter % boost::this_thread::get_id();
3320 putLogError(100062, formatter.str(), __FILE__, __LINE__ );
3324 /*-------- DEBUG LOG --------*/
3325 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3329 "out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3330 "handle_sorryserver_select(const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint& sorry_endpoint) : return_value = %d."
3331 " thread id : %d.");
3332 formatter % status % boost::this_thread::get_id();
3333 putLogDebug(100109, formatter.str(), __FILE__, __LINE__ );
3335 /*------DEBUG LOG END------*/
3339 //! called from after sorryserver connect
3340 //! @param[in] upstream thread id
3341 //! @param[out] send buffer reference.
3342 //! @param[out] send length
3343 //! @return session use EVENT mode.
3344 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_connect(
3345 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
3347 /*-------- DEBUG LOG --------*/
3348 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3350 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3351 "handle_sorryserver_connect(const boost::thread::id thread_id, "
3352 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
3354 formatter % thread_id;
3355 putLogDebug(100110, formatter.str(), __FILE__, __LINE__ );
3357 /*------DEBUG LOG END------*/
3358 EVENT_TAG status = FINALIZE;
3360 size_t header_offset = 0;
3361 size_t header_offset_len = 0;
3362 size_t url_offset = 0;
3363 size_t url_offset_len = 0;
3364 size_t send_buffer_remian_size = 0;
3365 size_t copy_size = 0;
3366 const int send_buffer_end_size = sendbuffer.max_size();
3367 const std::string http_header = "";
3368 const std::string str_forword_for = "X-Forwarded-For";
3369 thread_data_ptr session_data;
3370 session_thread_data_map_it session_thread_it;
3371 recive_data_map_it recive_data_it;
3376 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
3379 session_thread_it = session_thread_data_map.find(thread_id);
3380 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3382 boost::format formatter("Invalid thread id. thread id : %d.");
3383 formatter % boost::this_thread::get_id();
3384 putLogError(100063, formatter.str(), __FILE__, __LINE__ );
3388 session_data = session_thread_it->second;
3392 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
3393 if (unlikely(recive_data_it
3394 == session_data->recive_data_map.end()))
3396 boost::format formatter("Invalid endpoint. thread id : %d.");
3397 formatter % boost::this_thread::get_id();
3398 putLogError(100064, formatter.str(), __FILE__, __LINE__ );
3402 //recive_buffer pointer check
3403 recive_data& recv_data = recive_data_it->second;
3404 if (unlikely(recv_data.recive_buffer == NULL))
3406 boost::format formatter("Invalid pointer. thread id : %d.");
3407 formatter % boost::this_thread::get_id();
3408 putLogError(100065, formatter.str(), __FILE__, __LINE__ );
3413 send_status_it it = recv_data.send_status_list.begin();
3414 send_status_it it_end = recv_data.send_status_list.end();
3416 it = find_if(it, it_end, data_send_possible());
3417 if (unlikely(it == it_end))
3419 boost::format formatter("Sending possible data is not existed. thread id : %d.");
3420 formatter % boost::this_thread::get_id();
3421 putLogError(100066, formatter.str(), __FILE__, __LINE__ );
3425 //send buffer rest size initialization
3426 send_buffer_remian_size = send_buffer_end_size;
3428 //edit_division flag on
3429 if (it->edit_division == EDIT_DIVISION_EDIT)
3431 //edit list is empty
3432 if (it->edit_data_list.empty())
3436 edata.data_size = 0;
3437 edata.insert_posission = 0;
3438 edata.replace_size = 0;
3440 if (strlen(sorry_uri.data()) > 0)
3442 ret = find_uri(recv_data.recive_buffer + it->send_offset, it->send_possible_size, url_offset,
3444 /*-------- DEBUG LOG --------*/
3445 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3447 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3448 "handle_sorryserver_connect() : call find_uri : "
3449 "return_value = %d. thread id : %d.");
3450 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
3451 putLogDebug(100111, formatter.str(), __FILE__, __LINE__ );
3453 /*------DEBUG LOG END------*/
3454 //search http header result is OK
3457 //edit sorry_uri, put it to edata.data
3458 edata.data = sorry_uri.data();
3459 //save new uri offset
3460 edata.insert_posission = url_offset;
3461 //save new uri length
3462 edata.data_size = edata.data.size();
3463 //save old uri length
3464 edata.replace_size = url_offset_len;
3465 //add to edit_data_list
3466 it->edit_data_list.push_back(edata);
3470 if (forwarded_for == FORWARDED_FOR_ON)
3472 //search X-Forwarded-For header
3473 ret = find_http_header(recv_data.recive_buffer + it->send_offset, it->send_possible_size,
3474 str_forword_for.c_str(), header_offset, header_offset_len);
3475 /*-------- DEBUG LOG --------*/
3476 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3478 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3479 "handle_sorryserver_connect() : call find_http_header : "
3480 "return_value = %d. thread id : %d.");
3481 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
3482 putLogDebug(100112, formatter.str(), __FILE__, __LINE__ );
3484 /*------DEBUG LOG END------*/
3486 //search http header result is OK
3489 //edit X-Forwarded-For header, put it to edata.data
3490 edata.data.assign(recv_data.recive_buffer + it->send_offset + header_offset, header_offset_len);
3492 edata.data += session_data->client_endpoint_tcp.address().to_string();
3493 //save new X-Forwarded-For header offset
3494 edata.insert_posission = header_offset;
3495 //save new X-Forwarded-For header length
3496 edata.data_size = edata.data.size();
3497 //save old X-Forwarded-For header length
3498 edata.replace_size = header_offset_len;
3500 //search http header result is NG
3503 //search whole http header, get whole http header's offset and length
3504 ret = find_http_header(recv_data.recive_buffer + it->send_offset, it->send_possible_size, "",
3505 header_offset, header_offset_len);
3506 /*-------- DEBUG LOG --------*/
3507 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3509 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3510 "handle_sorryserver_connect() : call find_http_header : "
3511 "return_value = %d. thread id : %d.");
3512 formatter % static_cast<int>(ret) % boost::this_thread::get_id();
3513 putLogDebug(100113, formatter.str(), __FILE__, __LINE__ );
3515 /*------DEBUG LOG END------*/
3518 boost::format formatter("find_http_header() function failure. thread id : %d.");
3519 formatter % boost::this_thread::get_id();
3520 putLogError(100067, formatter.str(), __FILE__, __LINE__ );
3521 /*-------- DEBUG LOG --------*/
3522 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3524 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3525 "handle_sorryserver_connect(const boost::thread::id thread_id, "
3526 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
3527 "size_t& datalen) : return_value = %d. thread id : %d.");
3528 formatter % FINALIZE % boost::this_thread::get_id();
3529 putLogDebug(100114, formatter.str(), __FILE__, __LINE__ );
3531 /*------DEBUG LOG END------*/
3534 //create X-Forwarded-For header, set it to edata.data
3535 edata.data = str_forword_for;
3537 edata.data += session_data->client_endpoint_tcp.address().to_string();
3538 edata.data += "\r\n";
3539 //save new X-Forwarded-For header offset
3540 edata.insert_posission = header_offset;
3541 //save new X-Forwarded-For header length
3542 edata.data_size = edata.data.size();
3543 //save old X-Forwarded-For header length
3544 edata.replace_size = 0;
3547 //add to edit_data_list
3548 it->edit_data_list.push_back(edata);
3552 /*-------- DEBUG LOG --------*/
3553 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3555 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3556 "handle_sorryserver_connect() : Copy data loop start. thread id : %d.");
3557 formatter % boost::this_thread::get_id();
3558 putLogDebug(100115, formatter.str(), __FILE__, __LINE__ );
3560 /*------DEBUG LOG END------*/
3563 //edit_data_list is empty
3564 if (it->edit_data_list.empty())
3566 //set edit_division flag off
3567 it->edit_division = EDIT_DIVISION_NO_EDIT;
3569 if (send_buffer_remian_size > 0 && it->send_possible_size > 0)
3571 //send_buffer_remian_size is larger
3572 if (send_buffer_remian_size > it->send_possible_size)
3574 //copy data from recive_buffer to sendbuffer by sending_possible size
3575 copy_size = it->send_possible_size;
3576 /*-------- DEBUG LOG --------*/
3577 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3579 std::string datadump;
3580 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
3581 copy_size, datadump);
3582 boost::format formatter(
3583 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3584 "handle_sorryserver_connect() : before memcpy (data dump) : "
3585 "data begin = %d, data_size = %d, data = %s");
3586 formatter % (it->send_offset + it->send_end_size)
3587 % copy_size % datadump;
3588 putLogDebug(100116, formatter.str(), __FILE__, __LINE__ );
3590 /*------DEBUG LOG END------*/
3591 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3592 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
3593 /*-------- DEBUG LOG --------*/
3594 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3596 std::string datadump;
3597 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3598 copy_size, datadump);
3599 boost::format formatter(
3600 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3601 "handle_sorryserver_connect() : after memcpy (data dump) : "
3602 "data begin = %d, data_size = %d, data = %s");
3603 formatter % (send_buffer_end_size - send_buffer_remian_size)
3604 % copy_size % datadump;
3605 putLogDebug(100117, formatter.str(), __FILE__, __LINE__ );
3607 /*------DEBUG LOG END------*/
3608 it->send_end_size += copy_size;
3609 it->send_possible_size = 0;
3610 send_buffer_remian_size -= copy_size;
3612 //send_possible_size is larger
3615 copy_size = send_buffer_remian_size;
3616 /*-------- DEBUG LOG --------*/
3617 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3619 std::string datadump;
3620 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
3621 copy_size, datadump);
3622 boost::format formatter(
3623 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3624 "handle_sorryserver_connect() : before memcpy (data dump) : "
3625 "data begin = %d, data_size = %d, data = %s");
3626 formatter % (it->send_offset + it->send_end_size)
3627 % copy_size % datadump;
3628 putLogDebug(100118, formatter.str(), __FILE__, __LINE__ );
3630 /*------DEBUG LOG END------*/
3631 //copy data from recive_buffer to sendbuffer by send buffer rest size
3632 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3633 recv_data.recive_buffer + it->send_offset + it->send_end_size,
3635 /*-------- DEBUG LOG --------*/
3636 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3638 std::string datadump;
3639 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3640 copy_size, datadump);
3641 boost::format formatter(
3642 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3643 "handle_sorryserver_connect() : after memcpy (data dump) : "
3644 "data begin = %d, data_size = %d, data = %s");
3645 formatter % (send_buffer_end_size - send_buffer_remian_size)
3646 % copy_size % datadump;
3647 putLogDebug(100119, formatter.str(), __FILE__, __LINE__ );
3649 /*------DEBUG LOG END------*/
3650 it->send_end_size += copy_size;
3651 it->send_possible_size -= copy_size;
3652 send_buffer_remian_size = 0;
3658 //edit_data_list is not empty
3661 //search item which insert_posission is mininum
3662 std::list<edit_data>::iterator edit_min = std::min_element(it->edit_data_list.begin(),
3663 it->edit_data_list.end());
3664 //send_buffer_remian_size is larger than data that before X-Forwarded-For/uri
3665 if (send_buffer_remian_size >= edit_min->insert_posission - it->send_end_size)
3667 //copy data before X-Forwarded-For/url
3668 copy_size = edit_min->insert_posission - it->send_end_size;
3669 /*-------- DEBUG LOG --------*/
3670 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3672 std::string datadump;
3673 dump_memory(recv_data.recive_buffer + it->send_offset + it->send_end_size,
3674 copy_size, datadump);
3676 boost::format formatter(
3677 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3678 "handle_sorryserver_connect() : before memcpy (data dump) : "
3679 "data begin = %d, data_size = %d, data = %s");
3680 formatter % (it->send_offset + it->send_end_size)
3681 % copy_size % datadump;
3682 putLogDebug(100120, formatter.str(), __FILE__, __LINE__ );
3684 /*------DEBUG LOG END------*/
3685 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3686 recv_data.recive_buffer + it->send_offset + it->send_end_size, copy_size);
3687 /*-------- DEBUG LOG --------*/
3688 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3690 std::string datadump;
3691 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3692 copy_size, datadump);
3693 boost::format formatter(
3694 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3695 "handle_sorryserver_connect() : after memcpy (data dump) : "
3696 "data begin = %d, data_size = %d, data = %s");
3697 formatter % (send_buffer_end_size - send_buffer_remian_size)
3698 % copy_size % datadump;
3699 putLogDebug(100121, formatter.str(), __FILE__, __LINE__ );
3701 /*------DEBUG LOG END------*/
3702 it->send_end_size += copy_size;
3703 it->send_possible_size -= copy_size;
3704 send_buffer_remian_size -= copy_size;
3706 //there is remain buffer for copy X-Forwarded-For/url
3707 if (send_buffer_remian_size >= edit_min->data_size)
3709 /*-------- DEBUG LOG --------*/
3710 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3712 std::string datadump;
3713 dump_memory(edit_min->data.c_str(),
3714 edit_min->data_size, datadump);
3715 boost::format formatter(
3716 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3717 "handle_sorryserver_connect() : before memcpy (data dump) : "
3718 "data begin = 0, data_size = %d, data = %s");
3719 formatter % edit_min->data_size % datadump;
3720 putLogDebug(100122, formatter.str(), __FILE__, __LINE__ );
3722 /*------DEBUG LOG END------*/
3723 //copy X-Forwarded-For/uri
3724 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3725 edit_min->data.c_str(), edit_min->data_size);
3726 /*-------- DEBUG LOG --------*/
3727 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3729 std::string datadump;
3730 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3731 edit_min->data_size, datadump);
3733 boost::format formatter(
3734 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3735 "handle_sorryserver_connect() : after memcpy (data dump) : "
3736 "data begin = %d, data_size = %d, data = %s");
3737 formatter % (send_buffer_end_size - send_buffer_remian_size)
3738 % edit_min->data_size % datadump;
3739 putLogDebug(100123, formatter.str(), __FILE__, __LINE__ );
3741 /*------DEBUG LOG END------*/
3742 it->send_end_size += edit_min->replace_size;
3743 it->send_possible_size -= edit_min->replace_size;
3744 send_buffer_remian_size -= edit_min->data_size;
3745 it->edit_data_list.erase(edit_min);
3753 //data that before X-Forwarded-For/uri is larger than send_buffer_remian_size
3756 copy_size = send_buffer_remian_size;
3757 /*-------- DEBUG LOG --------*/
3758 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3760 std::string datadump;
3761 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3762 copy_size, datadump);
3764 boost::format formatter(
3765 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3766 "handle_sorryserver_connect() : before memcpy (data dump) : "
3767 "data begin = %d, data_size = %d, data = %s");
3768 formatter % (it->send_offset + it->send_end_size)
3769 % copy_size % datadump;
3770 putLogDebug(100124, formatter.str(), __FILE__, __LINE__ );
3772 /*------DEBUG LOG END------*/
3773 //copy data as large as possible
3774 memcpy(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3775 recv_data.recive_buffer + it->send_offset + it->send_end_size, send_buffer_remian_size);
3776 /*-------- DEBUG LOG --------*/
3777 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3779 std::string datadump;
3780 dump_memory(sendbuffer.data() + send_buffer_end_size - send_buffer_remian_size,
3781 copy_size, datadump);
3783 boost::format formatter(
3784 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3785 "handle_sorryserver_connect() : after memcpy (data dump) : "
3786 "data begin = %d, data_size = %d, data = %s");
3787 formatter % (send_buffer_end_size - send_buffer_remian_size)
3788 % copy_size % datadump;
3789 putLogDebug(100125, formatter.str(), __FILE__, __LINE__ );
3791 /*------DEBUG LOG END------*/
3792 it->send_end_size += copy_size;
3793 it->send_possible_size -= copy_size;
3794 send_buffer_remian_size -= copy_size;
3799 /*-------- DEBUG LOG --------*/
3800 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3802 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3803 "handle_sorryserver_connect() : Copy data loop end. thread id : %d.");
3804 formatter % boost::this_thread::get_id();
3805 putLogDebug(100126, formatter.str(), __FILE__, __LINE__ );
3807 /*------DEBUG LOG END------*/
3809 //edit_division flag is off
3812 //copy data as large as possible
3813 //send_possible_size is larger
3814 if (send_buffer_remian_size >= it->send_possible_size)
3816 copy_size = it->send_possible_size;
3817 /*-------- DEBUG LOG --------*/
3818 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3820 std::string datadump;
3821 dump_memory(recv_data.recive_buffer+ it->send_offset, copy_size, datadump);
3823 boost::format formatter(
3824 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3825 "handle_sorryserver_connect() : before memcpy (data dump) : "
3826 "data begin = %d, data_size = %d, data = %s");
3827 formatter % it->send_offset
3828 % copy_size % datadump;
3829 putLogDebug(100127, formatter.str(), __FILE__, __LINE__ );
3831 /*------DEBUG LOG END------*/
3832 //copy data by send_possible size
3833 memcpy(sendbuffer.data(), recv_data.recive_buffer
3834 + it->send_offset, copy_size);
3835 /*-------- DEBUG LOG --------*/
3836 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3838 std::string datadump;
3839 dump_memory(sendbuffer.data(), copy_size, datadump);
3841 boost::format formatter(
3842 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3843 "handle_sorryserver_connect() : after memcpy (data dump) : "
3844 "data begin = 0, data_size = %d, data = %s");
3845 formatter % copy_size % datadump;
3846 putLogDebug(100128, formatter.str(), __FILE__, __LINE__ );
3848 /*------DEBUG LOG END------*/
3849 it->send_end_size = it->send_possible_size;
3850 it->send_possible_size = 0;
3851 send_buffer_remian_size -= copy_size;
3853 //buffer rest size is larger
3856 /*-------- DEBUG LOG --------*/
3857 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3859 std::string datadump;
3860 dump_memory(recv_data.recive_buffer+ it->send_offset, send_buffer_remian_size, datadump);
3862 boost::format formatter(
3863 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3864 "handle_sorryserver_connect() : before memcpy (data dump) : "
3865 "data begin = %d, data_size = %d, data = %s");
3866 formatter % it->send_offset
3867 % send_buffer_remian_size % datadump;
3868 putLogDebug(100129, formatter.str(), __FILE__, __LINE__ );
3870 /*------DEBUG LOG END------*/
3871 //copy data by buffer rest size
3872 memcpy(sendbuffer.data(), recv_data.recive_buffer
3873 + it->send_offset, send_buffer_remian_size);
3874 /*-------- DEBUG LOG --------*/
3875 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3877 std::string datadump;
3878 dump_memory(sendbuffer.data(), send_buffer_remian_size, datadump);
3880 boost::format formatter(
3881 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3882 "handle_sorryserver_connect() : after memcpy (data dump) : "
3883 "data begin = 0, data_size = %d, data = %s");
3884 formatter % send_buffer_remian_size % datadump;
3885 putLogDebug(100130, formatter.str(), __FILE__, __LINE__ );
3887 /*------DEBUG LOG END------*/
3888 it->send_end_size = send_buffer_remian_size;
3889 it->send_possible_size -= send_buffer_remian_size;
3890 send_buffer_remian_size = 0;
3894 //set copyed data length
3895 datalen = send_buffer_end_size - send_buffer_remian_size;
3897 status = SORRYSERVER_SEND;
3902 /*-------- DEBUG LOG --------*/
3903 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3905 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3906 "handle_sorryserver_connect() : catch exception e = %d. thread id : %d.");
3907 formatter % e % boost::this_thread::get_id();
3908 putLogDebug(100131, formatter.str(), __FILE__, __LINE__ );
3911 /*------DEBUG LOG END------*/
3913 catch (const std::exception& ex)
3915 std::cerr << "protocol_module_sessionless::handle_sorryserver_connect() : exception : error = " << ex.what() << "." << std::endl;
3916 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3917 "handle_sorryserver_connect() : exception : error = %s. thread id : %d.");
3918 formatter % ex.what() % boost::this_thread::get_id();
3919 putLogError(100068, formatter.str(), __FILE__, __LINE__ );
3924 std::cerr << "protocol_module_sessionless::handle_sorryserver_connect() : Unknown exception." << std::endl;
3925 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3926 "handle_sorryserver_connect() : Unknown exception. thread id : %d.");
3927 formatter % boost::this_thread::get_id();
3928 putLogError(100069, formatter.str(), __FILE__, __LINE__ );
3932 /*-------- DEBUG LOG --------*/
3933 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3935 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3936 "handle_sorryserver_connect(const boost::thread::id thread_id, "
3937 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
3938 "size_t& datalen) : return_value = %d. thread id : %d.");
3939 formatter % status % boost::this_thread::get_id();
3940 putLogDebug(100132, formatter.str(), __FILE__, __LINE__ );
3942 /*------DEBUG LOG END------*/
3947 //! called from after sorryserver connection fail
3948 //! @param[in] upstream thread id
3949 //! @param[in] sorryserver endpoint reference.
3950 //! @return session use EVENT mode.
3951 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_connection_fail(
3952 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint)
3954 /*-------- DEBUG LOG --------*/
3955 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3957 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3958 "handle_sorryserver_connection_fail(const boost::thread::id thread_id, "
3959 "const boost::asio::ip::tcp::endpoint & sorry_endpoint) : "
3960 "thread_id = %d, sorry_endpoint = [%s]:%d.");
3961 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port();
3962 putLogDebug(100133, formatter.str(), __FILE__, __LINE__ );
3964 /*------DEBUG LOG END------*/
3966 EVENT_TAG status = FINALIZE;
3967 thread_data_ptr session_data;
3968 session_thread_data_map_it session_thread_it;
3972 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
3974 session_thread_it = session_thread_data_map.find(thread_id);
3975 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3977 boost::format formatter("Invalid thread id. thread id : %d.");
3978 formatter % boost::this_thread::get_id();
3979 putLogError(100070, formatter.str(), __FILE__, __LINE__ );
3983 session_data = session_thread_it->second;
3986 session_data->end_flag = END_FLAG_ON;
3987 /*-------- DEBUG LOG --------*/
3988 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3990 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
3991 "handle_sorryserver_connection_fail() : END_FLAG_ON. thread id : %d.");
3992 formatter % boost::this_thread::get_id();
3993 putLogDebug(100134, formatter.str(), __FILE__, __LINE__ );
3995 /*------DEBUG LOG END------*/
3997 status = CLIENT_DISCONNECT;
4001 /*-------- DEBUG LOG --------*/
4002 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4004 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4005 "handle_sorryserver_connection_fail() : catch exception e = %d. thread id : %d.");
4006 formatter % e % boost::this_thread::get_id();
4007 putLogDebug(100135, formatter.str(), __FILE__, __LINE__ );
4010 /*------DEBUG LOG END------*/
4012 catch (const std::exception& ex)
4014 std::cerr << "protocol_module_sessionless::handle_sorryserver_connection_fail() : exception : error=" << ex.what() << "." << std::endl;
4015 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4016 "handle_sorryserver_connection_fail() : exception : error = %s. thread id : %d.");
4017 formatter % ex.what() % boost::this_thread::get_id();
4018 putLogError(100071, formatter.str(), __FILE__, __LINE__ );
4023 std::cerr << "protocol_module_sessionless::handle_sorryserver_connection_fail() : Unknown exception." << std::endl;
4024 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4025 "handle_sorryserver_connection_fail() : Unknown exception. thread id : %d.");
4026 formatter % boost::this_thread::get_id();
4027 putLogError(100072, formatter.str(), __FILE__, __LINE__ );
4031 /*-------- DEBUG LOG --------*/
4032 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4036 "out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4037 "handle_sorryserver_connection_fail( const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint) : return_value = %d."
4038 " thread id : %d.");
4039 formatter % status % boost::this_thread::get_id();
4040 putLogDebug(100136, formatter.str(), __FILE__, __LINE__ );
4042 /*------DEBUG LOG END------*/
4046 //! called from after sorryserver send
4047 //! @param[in] upstream thread id
4048 //! @return session use EVENT mode.
4049 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_send(
4050 const boost::thread::id thread_id)
4052 /*-------- DEBUG LOG --------*/
4053 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4055 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4056 "handle_sorryserver_send(const boost::thread::id thread_id) : "
4058 formatter % thread_id;
4059 putLogDebug(100137, formatter.str(), __FILE__, __LINE__ );
4061 /*------DEBUG LOG END------*/
4062 EVENT_TAG status = FINALIZE;
4063 thread_data_ptr session_data;
4064 session_thread_data_map_it session_thread_it;
4065 recive_data_map_it recive_data_it;
4070 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
4073 session_thread_it = session_thread_data_map.find(thread_id);
4074 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
4076 boost::format formatter("Invalid thread id. thread id : %d.");
4077 formatter % boost::this_thread::get_id();
4078 putLogError(100073, formatter.str(), __FILE__, __LINE__ );
4082 session_data = session_thread_it->second;
4086 recive_data_it = session_data->recive_data_map.find(session_data->client_endpoint_tcp);
4087 if (unlikely(recive_data_it
4088 == session_data->recive_data_map.end()))
4090 boost::format formatter("Invalid endpoint. thread id : %d.");
4091 formatter % boost::this_thread::get_id();
4092 putLogError(100074, formatter.str(), __FILE__, __LINE__ );
4096 recive_data& recv_data = recive_data_it->second;
4098 send_status_it it = recv_data.send_status_list.begin();
4099 send_status_it it_end = recv_data.send_status_list.end();
4101 it = std::adjacent_find(it, it_end, data_send_list_incorrect());
4102 if (unlikely(it != it_end))
4104 boost::format formatter("Sending possible data is invalid. thread id : %d.");
4105 formatter % boost::this_thread::get_id();
4106 putLogError(100075, formatter.str(), __FILE__, __LINE__ );
4111 it = recv_data.send_status_list.begin();
4112 it = find_if(it, it_end, data_send_ok());
4113 if (unlikely(it == it_end))
4115 boost::format formatter("Sending possible data is not existed. thread id : %d.");
4116 formatter % boost::this_thread::get_id();
4117 putLogError(100076, formatter.str(), __FILE__, __LINE__ );
4121 //sending possible data is exist
4122 if (it->send_possible_size > 0)
4124 //status remain SEND_OK
4125 it->status = SEND_OK;
4127 it->send_offset += it->send_end_size;
4129 //insert_posission recalc
4130 for (std::list<edit_data>::iterator list_it = it->edit_data_list.begin(); list_it
4131 != it->edit_data_list.end(); ++list_it)
4133 list_it->insert_posission -= it->send_end_size;
4136 //send_end_size recalc
4137 it->send_end_size = 0;
4139 //sending possible data is not exist
4142 //can recive from clent continue
4143 if (it->send_rest_size > 0)
4145 //change status from SEND_OK to SEND_CONTINUE
4146 it->status = SEND_CONTINUE;
4148 //can not recive from clent continue
4151 //change status from SEND_OK to SEND_END
4152 it->status = SEND_END;
4156 it = recv_data.send_status_list.begin();
4157 it = find_if(it, it_end, data_send_ok());
4158 //send_ok item is exist
4161 status = SORRYSERVER_CONNECT;
4163 //send_ok item is exist
4166 status = CLIENT_RECV;
4172 /*-------- DEBUG LOG --------*/
4173 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4175 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4176 "handle_sorryserver_send() : catch exception e = %d. thread id : %d.");
4177 formatter % e % boost::this_thread::get_id();
4178 putLogDebug(100138, formatter.str(), __FILE__, __LINE__ );
4181 /*------DEBUG LOG END------*/
4183 catch (const std::exception& ex)
4185 std::cerr << "protocol_module_sessionless::handle_sorryserver_send() : exception : error = " << ex.what() << "." << std::endl;
4186 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4187 "handle_sorryserver_send() : exception : error = %s. thread id : %d.");
4188 formatter % ex.what() % boost::this_thread::get_id();
4189 putLogError(100077, formatter.str(), __FILE__, __LINE__ );
4195 std::cerr << "protocol_module_sessionless::handle_sorryserver_send() : Unknown exception." << std::endl;
4196 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4197 "handle_sorryserver_send() : Unknown exception. thread id : %d.");
4198 formatter % boost::this_thread::get_id();
4199 putLogError(100078, formatter.str(), __FILE__, __LINE__ );
4203 /*-------- DEBUG LOG --------*/
4204 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4206 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4207 "handle_sorryserver_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
4208 formatter % status % boost::this_thread::get_id();
4209 putLogDebug(100139, formatter.str(), __FILE__, __LINE__ );
4211 /*------DEBUG LOG END------*/
4216 //! called from after realserver recive.for UDP
4217 //! @param[in] downstream thread id
4218 //! @param[in] realserver UDP endpoint reference
4219 //! @param[in] recive from realserver buffer reference
4220 //! @param[in] recv data length
4221 //! @return session use EVENT mode.
4222 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_recv(
4223 const boost::thread::id thread_id, const boost::asio::ip::udp::endpoint& rs_endpoint, const boost::array<char,
4224 MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
4226 /*-------- DEBUG LOG --------*/
4227 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4229 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4230 "handle_realserver_recv(const boost::thread::id thread_id, "
4231 "const boost::asio::ip::udp::endpoint& rs_endpoint, "
4232 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4233 "const size_t recvlen) : "
4234 "return_value = %d. thread id : %d.");
4235 formatter % STOP % boost::this_thread::get_id();
4236 putLogDebug(100140, formatter.str(), __FILE__, __LINE__ );
4238 /*------DEBUG LOG END------*/
4242 //! called from after realserver recvive for TCP/IP
4243 //! @param[in] downstream thread id
4244 //! @param[in] realserver TCP/IP endpoint reference
4245 //! @param[in] realserver recive buffer reference.
4246 //! @param[in] recv data length
4247 //! @return session use EVENT mode.
4248 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_recv(
4249 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint& rs_endpoint, const boost::array<char,
4250 MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
4252 /*-------- DEBUG LOG --------*/
4253 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4255 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
4257 dump_memory(recvbuffer.data(), buffer_size, buffer);
4258 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4259 "handle_realserver_recv(const boost::thread::id thread_id, "
4260 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
4261 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4262 "const size_t recvlen) : thread_id = %d, rs_endpoint = [%s]:%d, recvbuffer = %s, recvlen = %d.");
4263 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port()
4265 putLogDebug(100141, formatter.str(), __FILE__, __LINE__ );
4267 /*------DEBUG LOG END------*/
4269 EVENT_TAG status = FINALIZE;
4270 size_t data_remain_start = 0;
4271 size_t data_remain_size = 0;
4272 size_t request_data_remain_size = 0;
4273 size_t header_offset = 0;
4274 size_t header_offset_len = 0;
4275 size_t content_length_header_offset = 0;
4276 size_t content_length_header_len = 0;
4277 size_t content_len_value = 0;
4279 size_t buffer_size = 0;
4280 const size_t cr_lf_len = strlen("\r\n\r\n");
4281 thread_data_ptr session_data;
4282 char* buffer1 = NULL;
4283 char* buffer2 = NULL;
4284 std::string str_value;
4285 const std::string http_header = "";
4286 const std::string content_header = "Content-Length";
4288 CHECK_RESULT_TAG check_result;
4289 session_thread_data_map_it session_thread_it;
4290 recive_data_map_it recive_data_it;
4293 if (recvlen > recvbuffer.size())
4295 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : Data size bigger than buffer size." << std::endl;
4296 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
4297 formatter % boost::this_thread::get_id();
4298 putLogError(100079, formatter.str(), __FILE__, __LINE__ );
4299 /*-------- DEBUG LOG --------*/
4300 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4302 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4303 "handle_realserver_recv(const boost::thread::id thread_id, "
4304 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
4305 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4306 "const size_t recvlen) : return_value = %d. thread id : %d.");
4307 formatter % FINALIZE % boost::this_thread::get_id();
4308 putLogDebug(100142, formatter.str(), __FILE__, __LINE__ );
4310 /*------DEBUG LOG END------*/
4317 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
4319 session_thread_it = session_thread_data_map.find(thread_id);
4320 if (unlikely(session_thread_it == session_thread_data_map.end()
4321 ||session_thread_it->second == NULL))
4323 boost::format formatter("Invalid thread id. thread id : %d.");
4324 formatter % boost::this_thread::get_id();
4325 putLogError(100080, formatter.str(), __FILE__, __LINE__ );
4329 session_data = session_thread_it->second;
4332 recive_data_it = session_data->recive_data_map.find(rs_endpoint);
4333 if (recive_data_it == session_data->recive_data_map.end())
4335 recive_data recv_data;
4336 session_data->recive_data_map[rs_endpoint] = recv_data;
4339 session_data->target_endpoint = rs_endpoint;
4341 recive_data& recv_data = session_data->recive_data_map[rs_endpoint];
4343 send_status_it it = recv_data.send_status_list.begin();
4344 send_status_it it_end = recv_data.send_status_list.end();
4347 it = std::find_if(it, it_end, data_send_ok());
4348 if (unlikely(it != it_end))
4350 boost::format formatter("Sending data is not correct. thread id : %d.");
4351 formatter % boost::this_thread::get_id();
4352 putLogError(100081, formatter.str(), __FILE__, __LINE__ );
4357 it = recv_data.send_status_list.begin();
4358 it = std::adjacent_find(it, it_end, data_send_repeated());
4359 if (unlikely(it != it_end))
4361 boost::format formatter("Sending data is not correct. thread id : %d.");
4362 formatter % boost::this_thread::get_id();
4363 putLogError(100082, formatter.str(), __FILE__, __LINE__ );
4367 /*-------- DEBUG LOG --------*/
4368 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4370 std::string datadump;
4371 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
4372 "send_rest_size = %d, send_possible_size = %d, "
4373 "send_offset = %d, unsend_size = %d, edit_division = %d.");
4375 for (it = recv_data.send_status_list.begin();
4376 it != recv_data.send_status_list.end();
4379 formatter % i % it->status % it->send_end_size
4380 % it->send_rest_size % it->send_possible_size
4381 % it->send_offset % it->unsend_size % it->edit_division;
4382 datadump += formatter.str();
4385 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4386 "handle_realserver_recv() : send status list dump : send status list size = %d.%s");
4388 formatter % recv_data.send_status_list.size() % datadump;
4389 putLogDebug(100143, formatter.str(), __FILE__, __LINE__ );
4391 /*------DEBUG LOG END------*/
4392 it = recv_data.send_status_list.begin();
4393 //get original status info
4394 while (it != it_end)
4396 //item status is SEND_END
4397 if (it->status == SEND_END)
4400 recv_data.send_status_list.erase(it++);
4403 //item status is SEND_CONTINUE
4404 else if (it->status == SEND_CONTINUE)
4406 it->send_offset += it->send_end_size;
4407 data_remain_start = it->send_offset;
4410 //item status is SEND_NG
4413 data_remain_start = it->send_offset;
4414 data_remain_size = it->unsend_size;
4420 /*-------- DEBUG LOG --------*/
4421 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4423 std::string datadump;
4424 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
4425 "send_rest_size = %d, send_possible_size = %d, "
4426 "send_offset = %d, unsend_size = %d, edit_division = %d.");
4428 for (it = recv_data.send_status_list.begin();
4429 it != recv_data.send_status_list.end();
4432 formatter % i % it->status % it->send_end_size
4433 % it->send_rest_size % it->send_possible_size
4434 % it->send_offset % it->unsend_size % it->edit_division;
4435 datadump += formatter.str();
4438 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4439 "handle_realserver_recv() : send status list dump : send status list size = %d.%s");
4441 formatter % recv_data.send_status_list.size() % datadump;
4442 putLogDebug(100144, formatter.str(), __FILE__, __LINE__ );
4444 /*------DEBUG LOG END------*/
4445 //recive buffer process
4446 //buffer rest size < request size
4447 if (recv_data.recive_buffer_rest_size < recvlen)
4449 //buffer max size < remain size + request size
4450 //buffer is need reallocate
4451 if (recv_data.recive_buffer_max_size < data_remain_size + recvlen)
4453 //the buffer's size that will be allocated is exceed the upper limit value
4454 if (MAX_SESSIONLESS_MODULE_BUFFER_SIZE < data_remain_size + recvlen)
4456 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : the buffer's size that will be allacted is exceed the upper limit value." << std::endl;
4457 boost::format formatter("The buffer's size that will be allocated is exceed the upper limit value. thread id : %d.");
4458 formatter % boost::this_thread::get_id();
4459 putLogError(100083, formatter.str(), __FILE__, __LINE__ );
4461 /*-------- DEBUG LOG --------*/
4462 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4464 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4465 "handle_realserver_recv(const boost::thread::id thread_id, "
4466 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
4467 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4468 "const size_t recvlen) : return_value = %d. thread id : %d.");
4469 formatter % FINALIZE % boost::this_thread::get_id();
4470 putLogDebug(100145, formatter.str(), __FILE__, __LINE__ );
4472 /*------DEBUG LOG END------*/
4476 //recive_buffer1's memory allocate and initialization
4477 buffer_size = (data_remain_size + recvlen) > MAX_BUFFER_SIZE ? (data_remain_size + recvlen) : MAX_BUFFER_SIZE;
4478 buffer1 = new char[buffer_size];
4479 /*-------- DEBUG LOG --------*/
4480 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4482 boost::format formatter("new : address = &(%d), size = %lu.");
4483 formatter % static_cast<void*>(buffer1) % buffer_size;
4484 putLogDebug(100146, formatter.str(), __FILE__, __LINE__ );
4486 /*-------- DEBUG LOG --------*/
4487 memset(buffer1, 0, buffer_size);
4488 //recive_buffer2's memory allocate and initialization
4489 buffer2 = new char[buffer_size];
4490 /*-------- DEBUG LOG --------*/
4491 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4493 boost::format formatter("new : address = &(%d), size = %lu.");
4494 formatter % static_cast<void*>(buffer2) % buffer_size;
4495 putLogDebug(100147, formatter.str(), __FILE__, __LINE__ );
4497 /*-------- DEBUG LOG END--------*/
4498 memset(buffer2, 0, buffer_size);
4500 /*-------- DEBUG LOG --------*/
4501 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4503 std::string datadump;
4504 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
4506 boost::format formatter(
4507 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4508 "handle_realserver_recv() : before memcpy (data dump) : "
4509 "data begin = %d, data_size = %d, data = %s");
4510 formatter % data_remain_start % data_remain_size % datadump;
4511 putLogDebug(100148, formatter.str(), __FILE__, __LINE__ );
4513 /*------DEBUG LOG END------*/
4514 //copy data from old buffer to new buffer
4515 memcpy(buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
4516 /*-------- DEBUG LOG --------*/
4517 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4519 std::string datadump;
4520 dump_memory(buffer1, data_remain_size, datadump);
4522 boost::format formatter(
4523 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4524 "handle_realserver_recv() : after memcpy (data dump) : "
4525 "data begin = 0, data_size = %d, data = %s");
4526 formatter % data_remain_size % datadump;
4527 putLogDebug(100149, formatter.str(), __FILE__, __LINE__ );
4529 /*------DEBUG LOG END------*/
4531 /*-------- DEBUG LOG --------*/
4532 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4534 std::string datadump;
4535 dump_memory(recvbuffer.data(), recvlen, datadump);
4536 boost::format formatter(
4537 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4538 "handle_realserver_recv() : before memcpy (data dump) : "
4539 "data begin = 0, data_size = %d, data = %s");
4540 formatter % recvlen % datadump;
4541 putLogDebug(100150, formatter.str(), __FILE__, __LINE__ );
4543 /*------DEBUG LOG END------*/
4544 memcpy(buffer1 + data_remain_size, recvbuffer.data(), recvlen);
4545 /*-------- DEBUG LOG --------*/
4546 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4548 std::string datadump;
4549 dump_memory(buffer1 + data_remain_size, recvlen, datadump);
4550 boost::format formatter(
4551 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4552 "handle_realserver_recv() : after memcpy (data dump) : "
4553 "data begin = %d, data_size = %d, data = %s");
4554 formatter % data_remain_size % recvlen % datadump;
4555 putLogDebug(100151, formatter.str(), __FILE__, __LINE__ );
4557 /*------DEBUG LOG END------*/
4558 //free old buffer1 and old buffer2
4559 if (recv_data.recive_buffer1 != NULL)
4561 /*-------- DEBUG LOG --------*/
4562 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4564 boost::format formatter("delete : address = &(%d).");
4565 formatter % static_cast<void*>(recv_data.recive_buffer1);
4566 putLogDebug(100152, formatter.str(), __FILE__,
4569 /*------DEBUG LOG END------*/
4570 delete[] recv_data.recive_buffer1;
4571 recv_data.recive_buffer1 = NULL;
4574 if (recv_data.recive_buffer2 != NULL)
4576 /*-------- DEBUG LOG --------*/
4577 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4579 boost::format formatter("delete : address = &(%d).");
4580 formatter % static_cast<void*>(recv_data.recive_buffer2);
4581 putLogDebug(100153, formatter.str(), __FILE__,
4584 /*------DEBUG LOG END------*/
4585 delete[] recv_data.recive_buffer2;
4586 recv_data.recive_buffer2 = NULL;
4589 //set new buffer pointer
4590 recv_data.recive_buffer1 = buffer1;
4591 recv_data.recive_buffer2 = buffer2;
4592 recv_data.recive_buffer = recv_data.recive_buffer1;
4593 //set new buffer's max size
4594 recv_data.recive_buffer_max_size = buffer_size;
4596 //buffer's max size >= remain data size + requst size
4597 //buffer isn't need reallocate, but switch
4600 //pointer valid check
4601 if (unlikely(recv_data.recive_buffer1 == NULL || recv_data.recive_buffer2 == NULL))
4603 boost::format formatter("Invalid pointer. thread id : %d.");
4604 formatter % boost::this_thread::get_id();
4605 putLogError(100084, formatter.str(), __FILE__, __LINE__ );
4608 //using buffer is buffer1
4609 if (recv_data.recive_buffer == recv_data.recive_buffer1)
4611 //buffer2 initialization
4612 memset(recv_data.recive_buffer2, 0, recv_data.recive_buffer_max_size);
4613 /*-------- DEBUG LOG --------*/
4614 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4616 std::string datadump;
4617 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
4618 boost::format formatter(
4619 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4620 "handle_realserver_recv() : before memcpy (data dump) : "
4621 "data begin = %d, data_size = %d, data = %s");
4622 formatter % data_remain_start % data_remain_size % datadump;
4623 putLogDebug(100154, formatter.str(), __FILE__, __LINE__ );
4625 /*------DEBUG LOG END------*/
4626 //copy data from buffer1 to buffer2
4627 memcpy(recv_data.recive_buffer2, recv_data.recive_buffer + data_remain_start, data_remain_size);
4628 /*-------- DEBUG LOG --------*/
4629 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4631 std::string datadump;
4632 dump_memory(recv_data.recive_buffer2, data_remain_size, datadump);
4633 boost::format formatter(
4634 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4635 "handle_realserver_recv() : after memcpy (data dump) : "
4636 "data begin = 0, data_size = %d, data = %s");
4637 formatter % data_remain_size % datadump;
4638 putLogDebug(100155, formatter.str(), __FILE__, __LINE__ );
4640 /*------DEBUG LOG END------*/
4641 /*-------- DEBUG LOG --------*/
4642 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4644 std::string datadump;
4645 dump_memory(recvbuffer.data(), recvlen, datadump);
4646 boost::format formatter(
4647 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4648 "handle_realserver_recv() : before memcpy (data dump) : "
4649 "data begin = 0, data_size = %d, data = %s");
4650 formatter % data_remain_size % datadump;
4651 putLogDebug(100156, formatter.str(), __FILE__, __LINE__ );
4653 /*------DEBUG LOG END------*/
4654 memcpy(recv_data.recive_buffer2 + data_remain_size, recvbuffer.data(), recvlen);
4655 /*-------- DEBUG LOG --------*/
4656 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4658 std::string datadump;
4659 dump_memory(recv_data.recive_buffer2 + data_remain_size, recvlen, datadump);
4661 boost::format formatter(
4662 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4663 "handle_realserver_recv() : after memcpy (data dump) : "
4664 "data begin = %d, data_size = %d, data = %s");
4665 formatter % data_remain_size % recvlen % datadump;
4666 putLogDebug(100157, formatter.str(), __FILE__, __LINE__ );
4668 /*------DEBUG LOG END------*/
4669 //set buffer2 as using buffer
4670 recv_data.recive_buffer = recv_data.recive_buffer2;
4672 //using buffer is buffer2
4675 //buffer1 initialization
4676 memset(recv_data.recive_buffer1, 0, recv_data.recive_buffer_max_size);
4677 /*-------- DEBUG LOG --------*/
4678 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4680 std::string datadump;
4681 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
4683 boost::format formatter(
4684 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4685 "handle_realserver_recv() : before memcpy (data dump) : "
4686 "data begin = %d, data_size = %d, data = %s");
4687 formatter % data_remain_start % data_remain_size % datadump;
4688 putLogDebug(100158, formatter.str(), __FILE__, __LINE__ );
4690 /*------DEBUG LOG END------*/
4691 //copy data from buffer2 to buffer1
4692 memcpy(recv_data.recive_buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
4693 /*-------- DEBUG LOG --------*/
4694 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4696 std::string datadump;
4697 dump_memory(recv_data.recive_buffer1, data_remain_size, datadump);
4699 boost::format formatter(
4700 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4701 "handle_realserver_recv() : after memcpy (data dump) : "
4702 "data begin = 0, data_size = %d, data = %s");
4703 formatter % data_remain_size % datadump;
4704 putLogDebug(100159, formatter.str(), __FILE__, __LINE__ );
4706 /*------DEBUG LOG END------*/
4707 /*-------- DEBUG LOG --------*/
4708 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4710 std::string datadump;
4711 dump_memory(recvbuffer.data(), recvlen, datadump);
4713 boost::format formatter(
4714 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4715 "handle_realserver_recv() : before memcpy (data dump) : "
4716 "data begin = 0, data_size = %d, data = %s");
4717 formatter % recvlen % datadump;
4718 putLogDebug(100160, formatter.str(), __FILE__, __LINE__ );
4720 /*------DEBUG LOG END------*/
4721 memcpy(recv_data.recive_buffer1 + data_remain_size, recvbuffer.data(), recvlen);
4722 /*-------- DEBUG LOG --------*/
4723 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4725 std::string datadump;
4726 dump_memory(recv_data.recive_buffer1 + data_remain_size, recvlen, datadump);
4728 boost::format formatter(
4729 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4730 "handle_realserver_recv() : after memcpy (data dump) : "
4731 "data begin = %d, data_size = %d, data = %s");
4732 formatter % data_remain_size % recvlen % datadump;
4733 putLogDebug(100161, formatter.str(), __FILE__, __LINE__ );
4735 /*------DEBUG LOG END------*/
4736 //set buffer1 as using buffer
4737 recv_data.recive_buffer = recv_data.recive_buffer1;
4741 //set buffer's rest size
4742 recv_data.recive_buffer_rest_size = recv_data.recive_buffer_max_size - data_remain_size - recvlen;
4744 //remain_size recalc
4745 data_remain_size += recvlen;
4747 send_status_it it_begin = recv_data.send_status_list.begin();
4748 send_status_it it_end = recv_data.send_status_list.end();
4750 for (; it_begin != it_end; ++it_begin)
4752 it_begin->send_offset -= data_remain_start;
4755 //buffer's rest size >= request size
4759 //pointer valid check
4760 if (unlikely(recv_data.recive_buffer == NULL))
4762 boost::format formatter("Invalid pointer. thread id : %d.");
4763 formatter % boost::this_thread::get_id();
4764 putLogError(100085, formatter.str(), __FILE__, __LINE__ );
4767 /*-------- DEBUG LOG --------*/
4768 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4770 std::string datadump;
4771 dump_memory(recvbuffer.data(), recvlen, datadump);
4772 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4773 "handle_realserver_recv() : before memcpy (data dump) : "
4774 "data begin = 0, data_size = %d, data = %s");
4775 formatter % recvlen % datadump;
4776 putLogDebug(100162, formatter.str(), __FILE__, __LINE__ );
4778 /*------DEBUG LOG END------*/
4780 //copy data from parameter to using buffer
4781 memcpy(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
4782 recvbuffer.data(), recvlen);
4783 /*-------- DEBUG LOG --------*/
4784 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4786 std::string datadump;
4787 dump_memory(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
4789 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4790 "handle_realserver_recv() : before memcpy (data dump) : "
4791 "data begin = %d, data_size = %d, data = %s");
4792 formatter % (recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size )
4793 % recvlen % datadump;
4794 putLogDebug(100163, formatter.str(), __FILE__, __LINE__ );
4796 /*------DEBUG LOG END------*/
4797 //buffer's rest size recalc
4798 recv_data.recive_buffer_rest_size -= recvlen;
4799 //remain data size recalc
4800 data_remain_size += recvlen;
4803 it = recv_data.send_status_list.begin();
4804 it_end = recv_data.send_status_list.end();
4805 //request rest size initialization
4806 request_data_remain_size = recvlen;
4807 //original status process
4808 for (; it != it_end; ++it)
4810 //status is SEND_CONTINUE
4811 if (it->status == SEND_CONTINUE)
4813 //send rest size > request size
4814 if (it->send_rest_size > request_data_remain_size)
4816 //send possible size recalc
4817 it->send_possible_size = request_data_remain_size;
4818 //send rest size recalc
4819 it->send_rest_size -= request_data_remain_size;
4820 //send end size recalc
4821 it->send_end_size = 0;
4822 //request size recalc
4823 request_data_remain_size = 0;
4825 //send rest size <= request size
4828 //send possible size recalc
4829 it->send_possible_size = it->send_rest_size;
4830 //send rest size recalc
4831 request_data_remain_size -= it->send_rest_size;
4832 //send end size recalc
4833 it->send_end_size = 0;
4834 //request size recalc
4835 it->send_rest_size = 0;
4837 //change status from SEND_CONTINUE to SEND_OK
4838 it->status = SEND_OK;
4841 else if (it->status == SEND_NG)
4844 check_result = check_status_code(recv_data.recive_buffer + it->send_offset, data_remain_size);
4845 /*-------- DEBUG LOG --------*/
4846 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4848 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4849 "handle_realserver_recv() : call check_http_method : "
4850 "return_value = %d. thread id : %d.");
4851 formatter % check_result % boost::this_thread::get_id();
4852 putLogDebug(100164, formatter.str(), __FILE__, __LINE__ );
4854 /*------DEBUG LOG END------*/
4855 //check http method result is OK
4856 if (check_result == CHECK_OK)
4858 //check http version
4859 check_result = check_http_version(recv_data.recive_buffer + it->send_offset, data_remain_size);
4860 /*-------- DEBUG LOG --------*/
4861 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4863 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4864 "handle_realserver_recv() : call check_http_version : "
4865 "return_value = %d. thread id : %d.");
4866 formatter % check_result % boost::this_thread::get_id();
4867 putLogDebug(100165, formatter.str(), __FILE__, __LINE__ );
4869 /*------DEBUG LOG END------*/
4871 //check method and version result is OK
4872 if (check_result == CHECK_OK)
4874 //search http header
4875 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size, http_header,
4876 header_offset, header_offset_len);
4877 /*-------- DEBUG LOG --------*/
4878 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4880 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4881 "handle_realserver_recv() : call find_http_header : "
4882 "return_value = %d. thread id : %d.");
4883 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
4884 putLogDebug(100166, formatter.str(), __FILE__, __LINE__ );
4886 /*------DEBUG LOG END------*/
4887 //search http header result is OK
4890 //search Content_Length header
4891 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size,
4892 content_header, content_length_header_offset, content_length_header_len);
4893 /*-------- DEBUG LOG --------*/
4894 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4896 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
4897 "handle_realserver_recv() : call find_http_header : "
4898 "return_value = %d. thread id : %d.");
4899 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
4900 putLogDebug(100167, formatter.str(), __FILE__, __LINE__ );
4902 /*------DEBUG LOG END------*/
4903 //search Content_Length result is OK
4906 //Get Content_Length header's numeric value
4907 for (pos = 0; recv_data.recive_buffer[it->send_offset + content_length_header_offset + pos] != ':' && pos
4908 < content_length_header_len; ++pos)
4910 if (pos == content_length_header_len)
4912 throw std::string("Content_Length field's value is invalid.");
4917 str_value.assign(recv_data.recive_buffer + it->send_offset + content_length_header_offset + pos,
4918 content_length_header_len - pos);
4920 size_t pos_end = str_value.find_last_of('\r');
4921 if (pos_end != std::string::npos)
4923 str_value = str_value.erase(pos_end);
4926 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos)
4929 str_value = str_value.substr(pos);
4933 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
4935 catch (const boost::bad_lexical_cast& ex)
4937 throw std::string("Content_Length field's value is invalid.");
4939 //send_rest_size recalc
4940 //set whole http header's length + Content_Length's value
4941 it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
4943 //search Content_Length result is NG
4946 //send_rest_size recalc
4947 //set whole http header's length
4948 it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
4951 //search http header result is NG
4954 it->unsend_size += request_data_remain_size;
4955 request_data_remain_size = 0;
4959 //check method and version result is NG
4960 else if (check_result == CHECK_NG)
4962 //send_rest_size recalc
4963 it->send_rest_size = it->unsend_size + request_data_remain_size;
4965 //check method and version result is CHECK_INPOSSIBLE
4968 it->unsend_size += request_data_remain_size;
4969 request_data_remain_size = 0;
4973 //recalc fields value according to send_rest_size and request rest size
4974 if (it->send_rest_size > it->unsend_size + request_data_remain_size)
4976 it->send_possible_size = it->unsend_size+ request_data_remain_size;
4977 it->send_rest_size -= (it->unsend_size + request_data_remain_size);
4978 it->send_end_size = 0;
4979 it->unsend_size = 0;
4980 request_data_remain_size = 0;
4984 it->send_possible_size = it->send_rest_size;
4985 request_data_remain_size = it->unsend_size + request_data_remain_size - it->send_rest_size;
4986 it->send_end_size = 0;
4987 it->unsend_size = 0;
4988 it->send_rest_size = 0;
4991 //change status from SEND_NG to SEND_OK
4992 it->status = SEND_OK;
4994 //no request rest data to process
4995 if (request_data_remain_size <= 0)
5001 /*-------- DEBUG LOG --------*/
5002 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5004 std::string datadump;
5005 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
5006 "send_rest_size = %d, send_possible_size = %d, "
5007 "send_offset = %d, unsend_size = %d, edit_division = %d.");
5009 for (it = recv_data.send_status_list.begin();
5010 it != recv_data.send_status_list.end();
5013 formatter % i % it->status % it->send_end_size
5014 % it->send_rest_size % it->send_possible_size
5015 % it->send_offset % it->unsend_size % it->edit_division;
5016 datadump += formatter.str();
5019 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5020 "handle_realserver_recv() : send status list dump : send status list size = %d.%s");
5022 formatter % recv_data.send_status_list.size() % datadump;
5023 putLogDebug(100168, formatter.str(), __FILE__, __LINE__ );
5025 /*------DEBUG LOG END------*/
5026 //there are still rest data need to process
5027 //new status created and add to status list
5028 while (request_data_remain_size > 0)
5030 //new status created
5031 send_status new_send_state;
5032 new_send_state.edit_division = EDIT_DIVISION_NO_EDIT;
5033 new_send_state.send_end_size = 0;
5034 new_send_state.send_offset = 0;
5035 new_send_state.send_possible_size = 0;
5036 new_send_state.unsend_size = 0;
5037 new_send_state.send_rest_size = 0;
5038 //status initialize to SEND_NG
5039 new_send_state.status = SEND_NG;
5040 //add new status to status_list
5041 recv_data.send_status_list.push_back(new_send_state);
5042 std::list<send_status>::reverse_iterator new_send_it = recv_data.send_status_list.rbegin();
5044 new_send_it->send_offset = recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size
5045 - request_data_remain_size;
5048 check_result = check_status_code(recv_data.recive_buffer + new_send_it->send_offset,
5049 request_data_remain_size);
5050 /*-------- DEBUG LOG --------*/
5051 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5053 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5054 "handle_realserver_recv() : call check_http_method : "
5055 "return_value = %d. thread id : %d.");
5056 formatter % check_result % boost::this_thread::get_id();
5057 putLogDebug(100169, formatter.str(), __FILE__, __LINE__ );
5059 /*------DEBUG LOG END------*/
5060 //check http method result is OK
5061 if (check_result == CHECK_OK)
5063 //check http version
5064 check_result = check_http_version(recv_data.recive_buffer + new_send_it->send_offset,
5065 request_data_remain_size);
5066 /*-------- DEBUG LOG --------*/
5067 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5069 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5070 "handle_realserver_recv() : call check_http_version : "
5071 "return_value = %d. thread id : %d.");
5072 formatter % check_result % boost::this_thread::get_id();
5073 putLogDebug(100170, formatter.str(), __FILE__, __LINE__ );
5075 /*------DEBUG LOG END------*/
5077 //check http method and version result is OK
5078 if (check_result == CHECK_OK)
5080 //search whole http header, get whole http header's offset and length
5081 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset, request_data_remain_size,
5082 http_header, header_offset, header_offset_len);
5083 /*-------- DEBUG LOG --------*/
5084 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5086 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5087 "handle_realserver_recv() : call find_http_header : "
5088 "return_value = %d. thread id : %d.");
5089 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
5090 putLogDebug(100171, formatter.str(), __FILE__, __LINE__ );
5092 /*------DEBUG LOG END------*/
5093 //searched whole http header
5096 //search ContentLength http header, get ContentLength header's offset and length
5097 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset,
5098 request_data_remain_size, content_header, content_length_header_offset, content_length_header_len);
5099 /*-------- DEBUG LOG --------*/
5100 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5102 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5103 "handle_realserver_recv() : call find_http_header : "
5104 "return_value = %d. thread id : %d.");
5105 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
5106 putLogDebug(100172, formatter.str(), __FILE__, __LINE__ );
5108 /*------DEBUG LOG END------*/
5110 //searched ContentLength http header
5113 //Get Content_Length header's numeric value
5114 for (pos = 0; recv_data.recive_buffer[new_send_it->send_offset + content_length_header_offset + pos] != ':'
5115 && pos < content_length_header_len; ++pos)
5117 if (pos == content_length_header_len)
5119 throw std::string("Content_Length field's value is invalid.");
5124 str_value.assign(recv_data.recive_buffer + new_send_it->send_offset + content_length_header_offset + pos,
5125 content_length_header_len - pos);
5127 size_t pos_end = str_value.find_last_of('\r');
5128 if (pos_end != std::string::npos)
5130 str_value = str_value.erase(pos_end);
5133 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos)
5136 str_value = str_value.substr(pos);
5139 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
5141 catch (const boost::bad_lexical_cast& ex)
5143 throw std::string("Content_Length field's value is invalid.");
5145 //send_rest_size recalc
5146 //set whole http header's + whole http header's length + Content_Length's value
5147 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
5149 //not searched ContentLength http header
5152 //send_rest_size recalc
5153 //set whole http header's + whole http header's length
5154 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
5157 //not searched whole http header
5160 new_send_it->unsend_size = request_data_remain_size;
5161 request_data_remain_size = 0;
5165 //check http method or version result is NG
5166 else if (check_result == CHECK_NG)
5168 new_send_it->send_rest_size = request_data_remain_size;
5170 //check http method or version result is impossible
5173 new_send_it->unsend_size = request_data_remain_size;
5174 request_data_remain_size = 0;
5178 //recalc fields value according to send_rest_size and request rest size
5179 if (new_send_it->send_rest_size > request_data_remain_size)
5181 new_send_it->send_possible_size = request_data_remain_size;
5182 new_send_it->send_rest_size -= request_data_remain_size;
5183 new_send_it->send_end_size = 0;
5184 new_send_it->send_end_size = 0;
5185 request_data_remain_size = 0;
5189 new_send_it->send_possible_size = new_send_it->send_rest_size;
5190 request_data_remain_size -= new_send_it->send_rest_size;
5191 new_send_it->send_end_size = 0;
5192 new_send_it->send_rest_size = 0;
5195 //change status from SEND_NG to SEND_OK
5196 new_send_it->status = SEND_OK;
5198 /*-------- DEBUG LOG --------*/
5199 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5201 std::string datadump;
5202 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
5203 "send_rest_size = %d, send_possible_size = %d, "
5204 "send_offset = %d, unsend_size = %d, edit_division = %d.");
5206 for (it = recv_data.send_status_list.begin();
5207 it != recv_data.send_status_list.end();
5210 formatter % i % it->status % it->send_end_size
5211 % it->send_rest_size % it->send_possible_size
5212 % it->send_offset % it->unsend_size % it->edit_division;
5213 datadump += formatter.str();
5216 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5217 "handle_realserver_recv() : send status list dump : send status list size = %d.%s");
5219 formatter % recv_data.send_status_list.size() % datadump;
5220 putLogDebug(100173, formatter.str(), __FILE__, __LINE__ );
5222 /*------DEBUG LOG END------*/
5224 //search for send_possible item in status list
5225 send_status_it it_find = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
5226 data_send_possible());
5227 //the data that can be sent possible is exist
5228 if (it_find != recv_data.send_status_list.end())
5230 status = CLIENT_CONNECTION_CHECK;
5232 //the data that can be sent possible is not exist
5235 status = REALSERVER_RECV;
5240 /*-------- DEBUG LOG --------*/
5241 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5243 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5244 "handle_realserver_recv() : catch exception e = %d. thread id : %d.");
5245 formatter % e % boost::this_thread::get_id();
5246 putLogDebug(100174, formatter.str(), __FILE__, __LINE__ );
5248 /*------DEBUG LOG END------*/
5251 catch (const std::string& ex)
5253 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : exception : " << ex << std::endl;
5254 boost::format formatter("protocol_module_sessionless::handle_realserver_recv() : exception : %s. thread id : %d.");
5255 formatter % ex.c_str() % boost::this_thread::get_id();
5256 putLogError(100086, formatter.str(), __FILE__, __LINE__ );
5259 catch (const std::bad_alloc&)
5261 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : exception : Could not allocate memory." << std::endl;
5262 boost::format formatter("Could not allocate memory. thread id : %d.");
5263 formatter % boost::this_thread::get_id();
5264 putLogError(100087, formatter.str(), __FILE__, __LINE__ );
5267 catch (const std::exception& ex)
5269 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : exception : error = " << ex.what() << "." << std::endl;
5270 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5271 "handle_realserver_recv() : exception : error = %s. thread id : %d.");
5272 formatter % ex.what() % boost::this_thread::get_id();
5273 putLogError(100088, formatter.str(), __FILE__, __LINE__ );
5279 std::cerr << "protocol_module_sessionless::handle_realserver_recv() : Unknown exception." << std::endl;
5280 boost::format formatter("function : protocol_module_base::EVENT_TAG "
5281 "protocol_module_sessionless::handle_realserver_recv() : "
5282 "Unknown exception. thread id : %d.");
5283 formatter % boost::this_thread::get_id();
5284 putLogError(100089, formatter.str(), __FILE__, __LINE__ );
5288 /*-------- DEBUG LOG --------*/
5289 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5291 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5292 "handle_realserver_recv(const boost::thread::id thread_id, "
5293 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
5294 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5295 "const size_t recvlen) : return_value = %d. thread id : %d.");
5296 formatter % status % boost::this_thread::get_id();
5297 putLogDebug(100175, formatter.str(), __FILE__, __LINE__ );
5299 /*------DEBUG LOG END------*/
5306 //! called from after sorryserver recive
5307 //! @param[in] downstream thread id
5308 //! @param[in] sorryserver endpoint reference
5309 //! @param[in] recive from realserver buffer reference.
5310 //! @param[in] recv data length
5311 //! @return session use EVENT mode
5312 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_recv(
5313 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint& sorry_endpoint, const boost::array<
5314 char, MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
5316 /*-------- DEBUG LOG --------*/
5317 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5319 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
5321 dump_memory(recvbuffer.data(), buffer_size, buffer);
5322 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5323 "handle_sorryserver_recv(const boost::thread::id thread_id, "
5324 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
5325 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5326 "const size_t recvlen) : thread_id = %d, sorry_endpoint = [%s]:%d, recvbuffer = %s, recvlen = %d.");
5327 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port()
5329 putLogDebug(100176, formatter.str(), __FILE__, __LINE__ );
5331 /*------DEBUG LOG END------*/
5333 EVENT_TAG status = FINALIZE;
5334 size_t data_remain_start = 0;
5335 size_t data_remain_size = 0;
5336 size_t request_data_remain_size = 0;
5337 size_t header_offset = 0;
5338 size_t header_offset_len = 0;
5339 size_t content_length_header_offset = 0;
5340 size_t content_length_header_len = 0;
5341 size_t content_len_value = 0;
5343 size_t buffer_size = 0;
5344 const size_t cr_lf_len = strlen("\r\n\r\n");
5345 std::string str_value;
5346 const std::string http_header = "";
5347 const std::string content_header = "Content-Length";
5348 thread_data_ptr session_data;
5349 char* buffer1 = NULL;
5350 char* buffer2 = NULL;
5352 CHECK_RESULT_TAG check_result;
5353 session_thread_data_map_it session_thread_it;
5354 recive_data_map_it recive_data_it;
5357 if (recvlen > recvbuffer.size())
5359 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : Data size bigger than buffer size." << std::endl;
5360 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
5361 formatter % boost::this_thread::get_id();
5362 putLogError(100090, formatter.str(), __FILE__,
5364 /*-------- DEBUG LOG --------*/
5365 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5367 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5368 "handle_sorryserver_recv(const boost::thread::id thread_id, "
5369 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
5370 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5371 "const size_t recvlen) : return_value = %d. thread id : %d.");
5372 formatter % FINALIZE % boost::this_thread::get_id();
5373 putLogDebug(100177, formatter.str(), __FILE__, __LINE__ );
5375 /*------DEBUG LOG END------*/
5382 boost::mutex::scoped_lock slock(session_thread_data_map_mutex );
5384 session_thread_it = session_thread_data_map.find(thread_id);
5385 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
5387 boost::format formatter("Invalid thread id. thread id : %d.");
5388 formatter % boost::this_thread::get_id();
5389 putLogError(100091, formatter.str(), __FILE__, __LINE__ );
5393 session_data = session_thread_it->second;
5396 recive_data_it = session_data->recive_data_map.find(sorry_endpoint);
5397 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
5399 recive_data recv_data;
5400 session_data->recive_data_map[sorry_endpoint] = recv_data;
5403 session_data->target_endpoint = sorry_endpoint;
5405 recive_data& recv_data = session_data->recive_data_map[sorry_endpoint];
5408 send_status_it it = recv_data.send_status_list.begin();
5409 send_status_it it_end = recv_data.send_status_list.end();
5410 it = std::find_if(it, it_end, data_send_ok());
5411 if (unlikely(it != it_end))
5413 boost::format formatter("Sending data is invalid. thread id : %d.");
5414 formatter % boost::this_thread::get_id();
5415 putLogError(100092, formatter.str(), __FILE__, __LINE__ );
5420 it = recv_data.send_status_list.begin();
5421 it = std::adjacent_find(it, it_end, data_send_repeated());
5422 if (unlikely(it != it_end))
5424 boost::format formatter("Sending data is invalid. thread id : %d.");
5425 formatter % boost::this_thread::get_id();
5426 putLogError(100093, formatter.str(), __FILE__, __LINE__ );
5430 /*-------- DEBUG LOG --------*/
5431 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5433 std::string datadump;
5434 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
5435 "send_rest_size = %d, send_possible_size = %d, "
5436 "send_offset = %d, unsend_size = %d, edit_division = %d.");
5438 for (it = recv_data.send_status_list.begin();
5439 it != recv_data.send_status_list.end();
5442 formatter % i % it->status % it->send_end_size
5443 % it->send_rest_size % it->send_possible_size
5444 % it->send_offset % it->unsend_size % it->edit_division;
5445 datadump += formatter.str();
5448 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5449 "handle_sorryserver_recv() : send status list dump : send status list size = %d.%s");
5451 formatter % recv_data.send_status_list.size() % datadump;
5452 putLogDebug(100178, formatter.str(), __FILE__, __LINE__ );
5454 /*------DEBUG LOG END------*/
5456 it = recv_data.send_status_list.begin();
5457 //get original status info
5458 while (it != it_end)
5460 //item status is SEND_END
5461 if (it->status == SEND_END)
5464 recv_data.send_status_list.erase(it++);
5467 //item status is SEND_CONTINUE
5468 else if (it->status == SEND_CONTINUE)
5470 it->send_offset += it->send_end_size;
5471 data_remain_start = it->send_offset;
5474 //item status is SEND_NG
5477 data_remain_start = it->send_offset;
5478 data_remain_size = it->unsend_size;
5484 /*-------- DEBUG LOG --------*/
5485 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5487 std::string datadump;
5488 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
5489 "send_rest_size = %d, send_possible_size = %d, "
5490 "send_offset = %d, unsend_size = %d, edit_division = %d.");
5492 for (it = recv_data.send_status_list.begin();
5493 it != recv_data.send_status_list.end();
5496 formatter % i % it->status % it->send_end_size
5497 % it->send_rest_size % it->send_possible_size
5498 % it->send_offset % it->unsend_size % it->edit_division;
5499 datadump += formatter.str();
5502 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5503 "handle_sorryserver_recv() : send status list dump : send status list size = %d.%s");
5505 formatter % recv_data.send_status_list.size() % datadump;
5506 putLogDebug(100179, formatter.str(), __FILE__, __LINE__ );
5508 /*------DEBUG LOG END------*/
5509 //recive buffer process
5510 //buffer rest size < request size
5511 if (recv_data.recive_buffer_rest_size < recvlen)
5513 //buffer max size < remain size + request size
5514 //buffer is need reallocate
5515 if (recv_data.recive_buffer_max_size < data_remain_size + recvlen)
5517 //the buffer's size that will be allocated is exceed the upper limit value
5518 if (MAX_SESSIONLESS_MODULE_BUFFER_SIZE < data_remain_size + recvlen)
5520 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : the buffer's size that will be allacted is exceed the upper limit value." << std::endl;
5521 boost::format formatter("The buffer's size that will be allocated is exceed the upper limit value. thread id : %d.");
5522 formatter % boost::this_thread::get_id();
5523 putLogError(100094, formatter.str(), __FILE__, __LINE__ );
5524 /*-------- DEBUG LOG --------*/
5525 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5527 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5528 "handle_sorryserver_recv(const boost::thread::id thread_id, "
5529 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
5530 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5531 "const size_t recvlen) : return_value = %d. thread id : %d.");
5532 formatter % FINALIZE % boost::this_thread::get_id();
5533 putLogDebug(100180, formatter.str(), __FILE__, __LINE__ );
5535 /*------DEBUG LOG END------*/
5538 //recive_buffer1's memory allocate and initialization
5539 buffer_size = (data_remain_size + recvlen) > MAX_BUFFER_SIZE ? (data_remain_size + recvlen) : MAX_BUFFER_SIZE;
5540 buffer1 = new char[buffer_size];
5541 /*-------- DEBUG LOG --------*/
5542 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5544 boost::format formatter("new : address = &(%d), size = %lu.");
5545 formatter % static_cast<void*>(buffer1) % buffer_size;
5546 putLogDebug(100181, formatter.str(), __FILE__, __LINE__ );
5548 /*-------- DEBUG LOG END--------*/
5549 memset(buffer1, 0, buffer_size);
5550 //recive_buffer2's memory allocate and initialization
5551 buffer2 = new char[buffer_size];
5552 /*-------- DEBUG LOG --------*/
5553 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5555 boost::format formatter("new : address = &(%d), size = %lu.");
5556 formatter % static_cast<void*>(buffer2) % buffer_size;
5557 putLogDebug(100182, formatter.str(), __FILE__, __LINE__ );
5559 /*-------- DEBUG LOG END--------*/
5560 memset(buffer2, 0, buffer_size);
5562 /*-------- DEBUG LOG --------*/
5563 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5565 std::string datadump;
5566 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
5567 boost::format formatter(
5568 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5569 "handle_sorryserver_recv() : before memcpy (data dump) : "
5570 "data begin = %d, data_size = %d, data = %s");
5571 formatter % data_remain_start % data_remain_size % datadump;
5572 putLogDebug(100183, formatter.str(), __FILE__, __LINE__ );
5574 /*------DEBUG LOG END------*/
5575 //copy data from old buffer to new buffer
5576 memcpy(buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
5577 /*-------- DEBUG LOG --------*/
5578 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5580 std::string datadump;
5581 dump_memory(buffer1, data_remain_size, datadump);
5582 boost::format formatter(
5583 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5584 "handle_sorryserver_recv() : after memcpy (data dump) : "
5585 "data begin = 0, data_size = %d, data = %s");
5586 formatter % data_remain_size % datadump;
5587 putLogDebug(100184, formatter.str(), __FILE__, __LINE__ );
5589 /*------DEBUG LOG END------*/
5591 /*-------- DEBUG LOG --------*/
5592 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5594 std::string datadump;
5595 dump_memory(recvbuffer.data(), recvlen, datadump);
5596 boost::format formatter(
5597 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5598 "handle_sorryserver_recv() : before memcpy (data dump) : "
5599 "data begin = 0, data_size = %d, data = %s");
5600 formatter % recvlen % datadump;
5601 putLogDebug(100185, formatter.str(), __FILE__, __LINE__ );
5603 /*------DEBUG LOG END------*/
5604 memcpy(buffer1 + data_remain_size, recvbuffer.data(), recvlen);
5605 /*-------- DEBUG LOG --------*/
5606 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5608 std::string datadump;
5609 dump_memory(buffer1 + data_remain_size, recvlen, datadump);
5610 boost::format formatter(
5611 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5612 "handle_sorryserver_recv() : after memcpy (data dump) : "
5613 "data begin = %d, data_size = %d, data = %s");
5614 formatter % data_remain_size % recvlen % datadump;
5615 putLogDebug(100186, formatter.str(), __FILE__, __LINE__ );
5617 /*------DEBUG LOG END------*/
5618 //free old buffer1 and old buffer2
5619 if (recv_data.recive_buffer1 != NULL)
5621 /*-------- DEBUG LOG --------*/
5622 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5624 boost::format formatter("delete : address = &(%d).");
5625 formatter % static_cast<void*>(recv_data.recive_buffer1);
5626 putLogDebug(100187, formatter.str(), __FILE__,
5629 /*------DEBUG LOG END------*/
5630 delete[] recv_data.recive_buffer1;
5631 recv_data.recive_buffer1 = NULL;
5634 if (recv_data.recive_buffer2 != NULL)
5636 /*-------- DEBUG LOG --------*/
5637 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5639 boost::format formatter("delete : address = &(%d).");
5640 formatter % static_cast<void*>(recv_data.recive_buffer2);
5641 putLogDebug(100188, formatter.str(), __FILE__,
5644 /*------DEBUG LOG END------*/
5645 delete[] recv_data.recive_buffer2;
5646 recv_data.recive_buffer2 = NULL;
5649 //set new buffer pointer
5650 recv_data.recive_buffer1 = buffer1;
5651 recv_data.recive_buffer2 = buffer2;
5652 recv_data.recive_buffer = recv_data.recive_buffer1;
5653 //set new buffer's max size
5654 recv_data.recive_buffer_max_size = buffer_size;
5656 //buffer's max size >= remain data size + requst size
5657 //buffer isn't need reallocate, but switch
5660 //pointer valid check
5661 if (unlikely(recv_data.recive_buffer1 == NULL || recv_data.recive_buffer2 == NULL))
5663 boost::format formatter("Invalid pointer. thread id : %d.");
5664 formatter % boost::this_thread::get_id();
5665 putLogError(100095, formatter.str(), __FILE__, __LINE__ );
5668 //using buffer is buffer1
5669 if (recv_data.recive_buffer == recv_data.recive_buffer1)
5671 //buffer2 initialization
5672 memset(recv_data.recive_buffer2, 0, recv_data.recive_buffer_max_size);
5673 /*-------- DEBUG LOG --------*/
5674 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5676 std::string datadump;
5677 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
5678 boost::format formatter(
5679 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5680 "handle_sorryserver_recv() : before memcpy (data dump) : "
5681 "data begin = %d, data_size = %d, data = %s");
5682 formatter % data_remain_start % data_remain_size % datadump;
5683 putLogDebug(100189, formatter.str(), __FILE__, __LINE__ );
5685 /*------DEBUG LOG END------*/
5686 //copy data from buffer1 to buffer2
5687 memcpy(recv_data.recive_buffer2, recv_data.recive_buffer + data_remain_start, data_remain_size);
5688 /*-------- DEBUG LOG --------*/
5689 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5691 std::string datadump;
5692 dump_memory(recv_data.recive_buffer2, data_remain_size, datadump);
5693 boost::format formatter(
5694 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5695 "handle_sorryserver_recv() : after memcpy (data dump) : "
5696 "data begin = 0, data_size = %d, data = %s");
5697 formatter % data_remain_size % datadump;
5698 putLogDebug(100190, formatter.str(), __FILE__, __LINE__ );
5700 /*------DEBUG LOG END------*/
5701 /*-------- DEBUG LOG --------*/
5702 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5704 std::string datadump;
5705 dump_memory(recvbuffer.data(), recvlen, datadump);
5706 boost::format formatter(
5707 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5708 "handle_sorryserver_recv() : before memcpy (data dump) : "
5709 "data begin = 0, data_size = %d, data = %s");
5710 formatter % recvlen % datadump;
5711 putLogDebug(100191, formatter.str(), __FILE__, __LINE__ );
5713 /*------DEBUG LOG END------*/
5714 memcpy(recv_data.recive_buffer2 + data_remain_size, recvbuffer.data(), recvlen);
5715 /*-------- DEBUG LOG --------*/
5716 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5718 std::string datadump;
5719 dump_memory(recv_data.recive_buffer2 + data_remain_size, recvlen, datadump);
5720 boost::format formatter(
5721 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5722 "handle_sorryserver_recv() : after memcpy (data dump) : "
5723 "data begin = %d, data_size = %d, data = %s");
5724 formatter % data_remain_size % recvlen % datadump;
5725 putLogDebug(100192, formatter.str(), __FILE__, __LINE__ );
5727 /*------DEBUG LOG END------*/
5728 //set buffer2 as using buffer
5729 recv_data.recive_buffer = recv_data.recive_buffer2;
5731 //using buffer is buffer2
5734 //buffer1 initializtion
5735 memset(recv_data.recive_buffer1, 0, recv_data.recive_buffer_max_size);
5736 /*-------- DEBUG LOG --------*/
5737 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5739 std::string datadump;
5740 dump_memory(recv_data.recive_buffer + data_remain_start, data_remain_size, datadump);
5741 boost::format formatter(
5742 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5743 "handle_sorryserver_recv() : before memcpy (data dump) : "
5744 "data begin = %d, data_size = %d, data = %s");
5745 formatter % data_remain_start % data_remain_size % datadump;
5746 putLogDebug(100193, formatter.str(), __FILE__, __LINE__ );
5748 /*------DEBUG LOG END------*/
5749 //copy data from buffer2 to buffer1
5750 memcpy(recv_data.recive_buffer1, recv_data.recive_buffer + data_remain_start, data_remain_size);
5751 /*-------- DEBUG LOG --------*/
5752 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5754 std::string datadump;
5755 dump_memory(recv_data.recive_buffer1, data_remain_size, datadump);
5756 boost::format formatter(
5757 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5758 "handle_sorryserver_recv() : after memcpy (data dump) : "
5759 "data begin = 0, data_size = %d, data = %s");
5760 formatter % data_remain_size % datadump;
5761 putLogDebug(100194, formatter.str(), __FILE__, __LINE__ );
5763 /*------DEBUG LOG END------*/
5765 /*-------- DEBUG LOG --------*/
5766 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5768 std::string datadump;
5769 dump_memory(recvbuffer.data(), recvlen, datadump);
5770 boost::format formatter(
5771 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5772 "handle_sorryserver_recv() : before memcpy (data dump) : "
5773 "data begin = 0, data_size = %d, data = %s");
5774 formatter % recvlen % datadump;
5775 putLogDebug(100195, formatter.str(), __FILE__, __LINE__ );
5777 /*------DEBUG LOG END------*/
5778 memcpy(recv_data.recive_buffer1 + data_remain_size, recvbuffer.data(), recvlen);
5779 /*-------- DEBUG LOG --------*/
5780 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5782 std::string datadump;
5783 dump_memory(recv_data.recive_buffer1 + data_remain_size, recvlen, datadump);
5784 boost::format formatter(
5785 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5786 "handle_sorryserver_recv() : after memcpy (data dump) : "
5787 "data begin = %d, data_size = %d, data = %s");
5788 formatter % data_remain_size % recvlen % datadump;
5789 putLogDebug(100196, formatter.str(), __FILE__, __LINE__ );
5791 /*------DEBUG LOG END------*/
5792 //set buffer1 as using buffer
5793 recv_data.recive_buffer = recv_data.recive_buffer1;
5797 //set buffer's rest size
5798 recv_data.recive_buffer_rest_size = recv_data.recive_buffer_max_size - data_remain_size - recvlen;
5800 //remain_size recalc
5801 data_remain_size += recvlen;
5803 send_status_it it_begin = recv_data.send_status_list.begin();
5804 send_status_it it_end = recv_data.send_status_list.end();
5806 for (; it_begin != it_end; ++it_begin)
5808 it_begin->send_offset -= data_remain_start;
5811 //buffer's rest size >= request size
5815 //pointer valid check
5816 if (unlikely(recv_data.recive_buffer == NULL))
5818 boost::format formatter("Invalid pointer. thread id : %d");
5819 formatter % boost::this_thread::get_id();
5820 putLogError(100096, formatter.str(), __FILE__, __LINE__ );
5823 /*-------- DEBUG LOG --------*/
5824 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5826 std::string datadump;
5827 dump_memory(recvbuffer.data(), recvlen, datadump);
5828 boost::format formatter(
5829 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5830 "handle_sorryserver_recv() : before memcpy (data dump) : "
5831 "data begin = 0, data_size = %d, data = %s");
5832 formatter % recvlen % datadump;
5833 putLogDebug(100197, formatter.str(), __FILE__, __LINE__ );
5835 /*------DEBUG LOG END------*/
5837 //copy data from parameter to using buffer
5838 memcpy(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size,
5839 recvbuffer.data(), recvlen);
5840 /*-------- DEBUG LOG --------*/
5841 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5843 std::string datadump;
5844 dump_memory(recv_data.recive_buffer + recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size, recvlen, datadump);
5845 boost::format formatter(
5846 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5847 "handle_sorryserver_recv() : after memcpy (data dump) : "
5848 "data begin = %d, data_size = %d, data = %s");
5849 formatter % (recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size) % recvlen % datadump;
5850 putLogDebug(100198, formatter.str(), __FILE__, __LINE__ );
5852 /*------DEBUG LOG END------*/
5853 //buffer's rest size recalc
5854 recv_data.recive_buffer_rest_size -= recvlen;
5855 //remain data size recalc
5856 data_remain_size += recvlen;
5859 it = recv_data.send_status_list.begin();
5860 it_end = recv_data.send_status_list.end();
5861 //request rest size initialization
5862 request_data_remain_size = recvlen;
5863 //original status process
5864 for (; it != it_end; ++it)
5866 //status is SEND_CONTINUE
5867 if (it->status == SEND_CONTINUE)
5870 if (it->send_rest_size > request_data_remain_size)
5872 it->send_possible_size = request_data_remain_size;
5873 it->send_rest_size -= request_data_remain_size;
5874 it->send_end_size = 0;
5875 request_data_remain_size = 0;
5879 it->send_possible_size = it->send_rest_size;
5880 request_data_remain_size -= it->send_rest_size;
5881 it->send_end_size = 0;
5882 it->send_rest_size = 0;
5885 //change status from SEND_CONTINUE to SEND_OK
5886 it->status = SEND_OK;
5889 else if (it->status == SEND_NG)
5892 check_result = check_status_code(recv_data.recive_buffer + it->send_offset, data_remain_size);
5893 /*-------- DEBUG LOG --------*/
5894 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5896 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5897 "handle_sorryserver_recv() : call check_status_code : "
5898 "return_value = %d. thread id : %d.");
5899 formatter % check_result % boost::this_thread::get_id();
5900 putLogDebug(100199, formatter.str(), __FILE__, __LINE__ );
5902 /*------DEBUG LOG END------*/
5903 //check http method result is OK
5904 if (check_result == CHECK_OK)
5906 //check http version
5907 check_result = check_http_version(recv_data.recive_buffer + it->send_offset, data_remain_size);
5908 /*-------- DEBUG LOG --------*/
5909 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5911 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5912 "handle_sorryserver_recv() : call check_http_version : "
5913 "return_value = %d. thread id : %d.");
5914 formatter % check_result % boost::this_thread::get_id();
5915 putLogDebug(100200, formatter.str(), __FILE__, __LINE__ );
5917 /*------DEBUG LOG END------*/
5919 //check method and version result is OK
5920 if (check_result == CHECK_OK)
5922 //search http header
5923 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size, http_header,
5924 header_offset, header_offset_len);
5925 /*-------- DEBUG LOG --------*/
5926 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5928 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5929 "handle_sorryserver_recv() : call find_http_header : "
5930 "return_value = %d. thread id : %d.");
5931 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
5932 putLogDebug(100201, formatter.str(), __FILE__, __LINE__ );
5934 /*------DEBUG LOG END------*/
5935 //search http header result is OK
5938 //search Content_Length header
5939 bret = find_http_header(recv_data.recive_buffer + it->send_offset, data_remain_size,
5940 content_header, content_length_header_offset, content_length_header_len);
5941 /*-------- DEBUG LOG --------*/
5942 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5944 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
5945 "handle_sorryserver_recv() : call find_http_header : "
5946 "return_value = %d. thread id : %d.");
5947 formatter % static_cast<int>(bret) %boost::this_thread::get_id();
5948 putLogDebug(100202, formatter.str(), __FILE__, __LINE__ );
5950 /*------DEBUG LOG END------*/
5951 //search Content_Length result is OK
5954 //Get Content_Length header's numeric value
5955 for (pos = 0; recv_data.recive_buffer[it->send_offset + content_length_header_offset + pos] != ':' && pos
5956 < content_length_header_len; ++pos)
5958 if (pos == content_length_header_len)
5960 throw std::string("Content_Length field's value is invalid.");
5965 str_value.assign(recv_data.recive_buffer + it->send_offset + content_length_header_offset + pos,
5966 content_length_header_len - pos);
5968 size_t pos_end = str_value.find_last_of('\r');
5969 if (pos_end != std::string::npos)
5971 str_value = str_value.erase(pos_end);
5974 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos)
5977 str_value = str_value.substr(pos);
5981 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
5983 catch (const boost::bad_lexical_cast& ex)
5985 throw std::string("Content_Length field's value is invalid.");
5987 //send_rest_size recalc
5988 //set whole http header's length + Content_Length's value
5989 it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
5991 //search Content_Length result is NG
5994 //send_rest_size recalc
5995 //set whole http header's length
5996 it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
5999 //search http header result is NG
6002 it->unsend_size += request_data_remain_size;
6003 request_data_remain_size = 0;
6007 //check method or version result is NG
6008 else if (check_result == CHECK_NG)
6010 it->send_rest_size = it->unsend_size+request_data_remain_size;
6012 //check method and version result is CHECK_INPOSSIBLE
6015 it->unsend_size += request_data_remain_size;
6016 request_data_remain_size = 0;
6020 //recalc fields value according to send_rest_size and request rest size
6021 if (it->send_rest_size > it->unsend_size + request_data_remain_size)
6023 it->send_possible_size = it->unsend_size + request_data_remain_size;
6024 it->send_rest_size -= (it->unsend_size + request_data_remain_size);
6025 it->send_end_size = 0;
6026 it->unsend_size = 0;
6027 request_data_remain_size = 0;
6031 it->send_possible_size = it->send_rest_size;
6032 request_data_remain_size = it->unsend_size + request_data_remain_size - it->send_rest_size;
6033 it->send_end_size = 0;
6034 it->unsend_size = 0;
6035 it->send_rest_size = 0;
6038 //change status from SEND_NG to SEND_OK
6039 it->status = SEND_OK;
6041 //no request rest data to process
6042 if (request_data_remain_size <= 0)
6047 /*-------- DEBUG LOG --------*/
6048 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6050 std::string datadump;
6051 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
6052 "send_rest_size = %d, send_possible_size = %d, "
6053 "send_offset = %d, unsend_size = %d, edit_division = %d.");
6055 for (it = recv_data.send_status_list.begin();
6056 it != recv_data.send_status_list.end();
6059 formatter % i % it->status % it->send_end_size
6060 % it->send_rest_size % it->send_possible_size
6061 % it->send_offset % it->unsend_size % it->edit_division;
6062 datadump += formatter.str();
6065 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6066 "handle_sorryserver_recv() : send status list dump : send status list size = %d.%s");
6068 formatter % recv_data.send_status_list.size() % datadump;
6069 putLogDebug(100203, formatter.str(), __FILE__, __LINE__ );
6071 /*------DEBUG LOG END------*/
6073 //there are still rest data need to process
6074 //new status created and add to status list
6075 while (request_data_remain_size > 0)
6077 //new status created
6078 send_status new_send_state;
6079 new_send_state.edit_division = EDIT_DIVISION_NO_EDIT;
6080 new_send_state.send_end_size = 0;
6081 new_send_state.send_offset = 0;
6082 new_send_state.send_possible_size = 0;
6083 new_send_state.unsend_size = 0;
6084 new_send_state.send_rest_size = 0;
6085 //status initialize to SEND_NG
6086 new_send_state.status = SEND_NG;
6087 //add new status to status_list
6088 recv_data.send_status_list.push_back(new_send_state);
6089 std::list<send_status>::reverse_iterator new_send_it = recv_data.send_status_list.rbegin();
6091 new_send_it->send_offset = recv_data.recive_buffer_max_size - recv_data.recive_buffer_rest_size
6092 - request_data_remain_size;
6095 check_result = check_status_code(recv_data.recive_buffer + new_send_it->send_offset,
6096 request_data_remain_size);
6097 /*-------- DEBUG LOG --------*/
6098 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6100 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6101 "handle_sorryserver_recv() : call check_status_code : "
6102 "return_value = %d. thread id : %d.");
6103 formatter % check_result % boost::this_thread::get_id();
6104 putLogDebug(100204, formatter.str(), __FILE__, __LINE__ );
6106 /*------DEBUG LOG END------*/
6107 //check http method result is OK
6108 if (check_result == CHECK_OK)
6110 //check http version
6111 check_result = check_http_version(recv_data.recive_buffer + new_send_it->send_offset,
6112 request_data_remain_size);
6113 /*-------- DEBUG LOG --------*/
6114 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6116 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6117 "handle_sorryserver_recv() : call check_http_version : "
6118 "return_value = %d. thread id : %d.");
6119 formatter % check_result % boost::this_thread::get_id();
6120 putLogDebug(100205, formatter.str(), __FILE__, __LINE__ );
6122 /*------DEBUG LOG END------*/
6124 //check http method and version result is OK
6125 if (check_result == CHECK_OK)
6127 //search whole http header, get whole http header's offset and length
6128 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset, request_data_remain_size,
6129 http_header, header_offset, header_offset_len);
6130 /*-------- DEBUG LOG --------*/
6131 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6133 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6134 "handle_sorryserver_recv() : call find_http_header : "
6135 "return_value = %d. thread id : %d.");
6136 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
6137 putLogDebug(100206, formatter.str(), __FILE__, __LINE__ );
6139 /*------DEBUG LOG END------*/
6140 //searched whole http header
6143 //search ContentLength http header, get ContentLength header's offset and length
6144 bret = find_http_header(recv_data.recive_buffer + new_send_it->send_offset,
6145 request_data_remain_size, content_header, content_length_header_offset, content_length_header_len);
6146 /*-------- DEBUG LOG --------*/
6147 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6149 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6150 "handle_sorryserver_recv() : call find_http_header : "
6151 "return_value = %d. thread id : %d.");
6152 formatter % static_cast<int>(bret) % boost::this_thread::get_id();
6153 putLogDebug(100207, formatter.str(), __FILE__, __LINE__ );
6155 /*------DEBUG LOG END------*/
6157 //searched ContentLength http header
6160 //Get Content_Length header's numeric value
6161 for (pos = 0; recv_data.recive_buffer[new_send_it->send_offset + content_length_header_offset + pos] != ':'
6162 && pos < content_length_header_len; ++pos)
6164 if (pos == content_length_header_len)
6166 throw std::string("Content_Length field's value is invalid.");
6170 str_value.assign(recv_data.recive_buffer + new_send_it->send_offset + content_length_header_offset + pos,
6171 content_length_header_len - pos);
6173 size_t pos_end = str_value.find_last_of('\r');
6174 if (pos_end != std::string::npos)
6176 str_value = str_value.erase(pos_end);
6179 for (pos = 0; !isgraph(str_value[pos]) && str_value[pos] != '\0'; ++pos)
6182 str_value = str_value.substr(pos);
6185 content_len_value = boost::lexical_cast<size_t>(str_value.c_str());
6187 catch (const boost::bad_lexical_cast& ex)
6189 throw std::string("Content_Length field's value is invalid.");
6191 //send_rest_size recalc
6192 //set whole http header's + whole http header's length + Content_Length's value
6193 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len + content_len_value;
6195 //not searched ContentLength http header
6198 //send_rest_size recalc
6199 //set whole http header's + whole http header's length
6200 new_send_it->send_rest_size = header_offset + header_offset_len + cr_lf_len;
6203 //not searched whole http header
6206 new_send_it->unsend_size = request_data_remain_size;
6207 request_data_remain_size = 0;
6211 //check http method or version result is NG
6212 else if (check_result == CHECK_NG)
6214 new_send_it->send_rest_size = request_data_remain_size;
6216 //check http method or version result is impossible
6219 new_send_it->unsend_size = request_data_remain_size;
6220 request_data_remain_size = 0;
6224 //recalc fields value according to send_rest_size and request rest size
6225 if (new_send_it->send_rest_size > request_data_remain_size)
6227 new_send_it->send_possible_size = request_data_remain_size;
6228 new_send_it->send_rest_size -= request_data_remain_size;
6229 new_send_it->send_end_size = 0;
6230 request_data_remain_size = 0;
6234 new_send_it->send_possible_size = new_send_it->send_rest_size;
6235 request_data_remain_size -= new_send_it->send_rest_size;
6236 new_send_it->send_end_size = 0;
6237 new_send_it->send_rest_size = 0;
6240 //change status from SEND_NG to SEND_OK
6241 new_send_it->status = SEND_OK;
6243 /*-------- DEBUG LOG --------*/
6244 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6246 std::string datadump;
6247 boost::format formatter("\nitem[%d] : status = %d, send_end_size = %d, "
6248 "send_rest_size = %d, send_possible_size = %d, "
6249 "send_offset = %d, unsend_size = %d, edit_division = %d.");
6251 for (it = recv_data.send_status_list.begin();
6252 it != recv_data.send_status_list.end();
6255 formatter % i % it->status % it->send_end_size
6256 % it->send_rest_size % it->send_possible_size
6257 % it->send_offset % it->unsend_size % it->edit_division;
6258 datadump += formatter.str();
6261 formatter.parse("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6262 "handle_sorryserver_recv() : send status list dump : send status list size = %d.%s");
6264 formatter % recv_data.send_status_list.size() % datadump;
6265 putLogDebug(100208, formatter.str(), __FILE__, __LINE__ );
6267 /*------DEBUG LOG END------*/
6269 //search for send_possible item in status list
6270 send_status_it it_find = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
6271 data_send_possible());
6272 //the data that can be sent possible is exist
6273 if (it_find != recv_data.send_status_list.end())
6275 status = CLIENT_CONNECTION_CHECK;
6277 //the data that can be sent possible is not exist
6280 status = SORRYSERVER_RECV;
6285 /*-------- DEBUG LOG --------*/
6286 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6288 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6289 "handle_sorryserver_recv() : catch exception e = %d. thread id : %d.");
6290 formatter % e % boost::this_thread::get_id();
6291 putLogDebug(100209, formatter.str(), __FILE__, __LINE__ );
6293 /*------DEBUG LOG END------*/
6296 catch (const std::string& ex)
6298 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : exception : " << ex << std::endl;
6299 boost::format formatter("protocol_module_sessionless::handle_sorryserver_recv() : exception : %s. thread id : %d.");
6300 formatter % ex.c_str() % boost::this_thread::get_id();
6301 putLogError(100097, formatter.str(), __FILE__, __LINE__ );
6304 catch (const std::bad_alloc&)
6306 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : exception : Could not allocate memory." << std::endl;
6307 boost::format formatter("Could not allocate memory. thread id : %d.");
6308 formatter % boost::this_thread::get_id();
6309 putLogError(100098, formatter.str(), __FILE__, __LINE__ );
6312 catch (const std::exception& ex)
6314 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : exception : error = " << ex.what() << "." << std::endl;
6315 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6316 "handle_sorryserver_recv() : exception : error = %s. thread id : %d.");
6317 formatter % ex.what() % boost::this_thread::get_id();
6318 putLogError(100099, formatter.str(), __FILE__, __LINE__ );
6324 std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : Unknown exception." << std::endl;
6325 boost::format formatter("function : protocol_module_base::EVENT_TAG "
6326 "protocol_module_sessionless::handle_sorryserver_recv() : "
6327 "Unknown exception. thread id : %d.");
6328 formatter % boost::this_thread::get_id();
6329 putLogError(100100, formatter.str(), __FILE__, __LINE__ );
6333 /*-------- DEBUG LOG --------*/
6334 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6336 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6337 "handle_sorryserver_recv(const boost::thread::id thread_id, "
6338 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
6339 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
6340 "const size_t recvlen) : return_value = %d. thread id : %d.");
6341 formatter % status % boost::this_thread::get_id();
6342 putLogDebug(100210, formatter.str(), __FILE__, __LINE__ );
6344 /*------DEBUG LOG END------*/
6349 //! called from UPSTEEARM thread. make module original message.
6350 //! @param[in] downstream thread id.
6351 //! @return session use EVENT mode
6352 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_response_send_inform(
6353 const boost::thread::id thread_id)
6355 /*-------- DEBUG LOG --------*/
6356 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6358 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6359 "handle_response_send_inform(const boost::thread::id thread_id) : "
6360 "return_value = %d. thread id : %d.");
6361 formatter % STOP % boost::this_thread::get_id();
6362 putLogDebug(100211, formatter.str(), __FILE__, __LINE__ );
6364 /*------DEBUG LOG END------*/
6368 //! called from after client connection check. use TCP/IP only. create client send message.
6369 //! @param[in] downstream thread id
6370 //! @param[out] send budffer reference
6371 //! @param[out] send data length
6372 //! @return session use EVENT mode
6373 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_connection_check(
6374 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
6377 /*-------- DEBUG LOG --------*/
6378 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6380 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6381 "handle_client_connection_check(const boost::thread::id thread_id, "
6382 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
6384 formatter % thread_id;
6385 putLogDebug(100212, formatter.str(), __FILE__, __LINE__ );
6387 /*------DEBUG LOG END------*/
6389 EVENT_TAG status = FINALIZE;
6390 size_t send_buffer_size = sendbuffer.max_size();
6391 thread_data_ptr session_data;
6392 session_thread_data_map_it session_thread_it;
6393 recive_data_map_it recive_data_it;
6398 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
6400 session_thread_it = session_thread_data_map.find(thread_id);
6401 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
6403 boost::format formatter("Invalid thread id. thread id : %d.");
6404 formatter % boost::this_thread::get_id();
6405 putLogError(100101, formatter.str(), __FILE__, __LINE__ );
6409 session_data = session_thread_it->second;
6412 recive_data_it = session_data->recive_data_map.find(session_data->target_endpoint);
6413 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
6415 boost::format formatter("Invalid endpoint. thread id : %d.");
6416 formatter % boost::this_thread::get_id();
6417 putLogError(100102, formatter.str(), __FILE__, __LINE__ );
6421 recive_data& recv_data = recive_data_it->second;
6423 //get the data that can be sent possible
6424 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
6425 data_send_possible());
6426 if (unlikely(it == recv_data.send_status_list.end()))
6428 boost::format formatter("Sending possible data is not existed. thread id : %d.");
6429 formatter % boost::this_thread::get_id();
6430 putLogError(100103, formatter.str(), __FILE__, __LINE__ );
6434 //buffer size >= sending_possible size
6435 if (send_buffer_size > it->send_possible_size)
6437 /*-------- DEBUG LOG --------*/
6438 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6440 std::string datadump;
6441 dump_memory(recv_data.recive_buffer + it->send_offset, it->send_possible_size, datadump);
6443 boost::format formatter(
6444 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6445 "handle_client_connection_check() : before memcpy (data dump) : "
6446 "data begin = %d, data_size = %d, data = %s");
6447 formatter % it->send_offset % (it->send_possible_size) % datadump;
6448 putLogDebug(100213, formatter.str(), __FILE__, __LINE__ );
6450 /*------DEBUG LOG END------*/
6451 //copy data from recive_buffer to sendbuffer by sending_possible size
6452 memcpy(sendbuffer.data(), recv_data.recive_buffer + it->send_offset, it->send_possible_size);
6453 /*-------- DEBUG LOG --------*/
6454 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6456 std::string datadump;
6457 dump_memory(sendbuffer.data(), it->send_possible_size, datadump);
6459 boost::format formatter(
6460 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6461 "handle_client_connection_check() : after memcpy (data dump) : "
6462 "data begin = 0, data_size = %d, data = %s");
6463 formatter % (it->send_possible_size) % datadump;
6464 putLogDebug(100214, formatter.str(), __FILE__, __LINE__ );
6466 /*------DEBUG LOG END------*/
6467 //send_end_size recalc
6468 it->send_end_size = it->send_possible_size;
6469 //set copyed data length
6470 datalen = it->send_possible_size;
6471 //sending_possible size recalc
6472 it->send_possible_size = 0;
6474 //buffer size < sending_possible size
6477 /*-------- DEBUG LOG --------*/
6478 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6480 std::string datadump;
6481 dump_memory(recv_data.recive_buffer + it->send_offset, send_buffer_size, datadump);
6483 boost::format formatter(
6484 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6485 "handle_client_connection_check() : before memcpy (data dump) : "
6486 "data begin = %d, data_size = %d, data = %s");
6487 formatter % it->send_offset % send_buffer_size % datadump;
6488 putLogDebug(100215, formatter.str(), __FILE__, __LINE__ );
6490 /*------DEBUG LOG END------*/
6491 //copy data from recive_buffer to sendbuffer by buffer size
6492 memcpy(sendbuffer.data(), recv_data.recive_buffer + it->send_offset, send_buffer_size);
6493 /*-------- DEBUG LOG --------*/
6494 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6496 std::string datadump;
6497 dump_memory(sendbuffer.data(), send_buffer_size, datadump);
6499 boost::format formatter(
6500 "function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6501 "handle_client_connection_check() : after memcpy (data dump) : "
6502 "data begin = 0, data_size = %d, data = %s");
6503 formatter % send_buffer_size % datadump;
6504 putLogDebug(100216, formatter.str(), __FILE__, __LINE__ );
6506 /*------DEBUG LOG END------*/
6507 //send_end_size recalc
6508 it->send_end_size = send_buffer_size;
6509 //sending_possible size recalc
6510 it->send_possible_size -= send_buffer_size;
6511 //set copyed data length
6512 datalen = send_buffer_size;
6515 status = CLIENT_SEND;
6519 /*-------- DEBUG LOG --------*/
6520 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6522 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6523 "handle_client_connection_check() : catch exception e = %d. thread id : %d.");
6524 formatter % e % boost::this_thread::get_id();
6525 putLogDebug(100217, formatter.str(), __FILE__, __LINE__ );
6527 /*------DEBUG LOG END------*/
6530 catch (const std::exception& ex)
6532 std::cerr << "protocol_module_sessionless::handle_client_connection_check() : exception : error = " << ex.what() << "." << std::endl;
6533 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6534 "handle_client_connection_check() : exception : error = %s. thread id : %d.");
6535 formatter % ex.what() % boost::this_thread::get_id();
6536 putLogError(100104, formatter.str(), __FILE__, __LINE__ );
6541 std::cerr << "protocol_module_sessionless::handle_client_connection_check() : Unknown exception." << std::endl;
6542 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6543 "handle_client_connection_check() : Unknown exception. thread id : %d.");
6544 formatter % boost::this_thread::get_id();
6545 putLogError(100105, formatter.str(), __FILE__, __LINE__ );
6549 /*-------- DEBUG LOG --------*/
6550 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6552 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6553 "handle_client_connection_check(const boost::thread::id thread_id, "
6554 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)"
6555 " : return_value = %d. thread id : %d.");
6556 formatter % status % boost::this_thread::get_id();
6557 putLogDebug(100218, formatter.str(), __FILE__, __LINE__ );
6559 /*------DEBUG LOG END------*/
6563 //! called from after client select. use UDP only
6564 //! @param[in] downstream thread id
6565 //! @param[in] client udp endpoint
6566 //! @param[out] send buffer reference
6567 //! @param[out] send data length
6568 //! @return session use EVENT mode
6569 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_select(
6570 const boost::thread::id thread_id, boost::asio::ip::udp::endpoint& cl_endpoint, boost::array<char,
6571 MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
6573 /*-------- DEBUG LOG --------*/
6574 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6576 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6577 "handle_client_select(const boost::thread::id thread_id, "
6578 "boost::asio::ip::udp::endpoint& cl_endpoint, "
6579 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
6580 "size_t& datalen) : "
6581 "return_value = %d. thread id : %d.");
6582 formatter % STOP % boost::this_thread::get_id();
6583 putLogDebug(100219, formatter.str(), __FILE__, __LINE__ );
6585 /*------DEBUG LOG END------*/
6589 //! called from after client send
6590 //! @param[in] downstream thread id
6591 //! @return session use EVENT mode
6592 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_send(
6593 const boost::thread::id thread_id)
6595 /*-------- DEBUG LOG --------*/
6596 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6598 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6599 "handle_client_send(const boost::thread::id thread_id) : "
6601 formatter % thread_id;
6602 putLogDebug(100220, formatter.str(), __FILE__, __LINE__ );
6604 /*------DEBUG LOG END------*/
6605 EVENT_TAG status = FINALIZE;
6606 thread_data_ptr session_data;
6607 session_thread_data_map_it session_thread_it;
6608 recive_data_map_it recive_data_it;
6613 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
6615 session_thread_it = session_thread_data_map.find(thread_id);
6616 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
6618 boost::format formatter("Invalid thread id. thread id : %d.");
6619 formatter % boost::this_thread::get_id();
6620 putLogError(100106, formatter.str(), __FILE__, __LINE__ );
6623 session_data = session_thread_it->second;
6626 recive_data_it = session_data->recive_data_map.find(session_data->target_endpoint);
6627 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
6629 boost::format formatter("Invalid endpoint. thread id : %d.");
6630 formatter % boost::this_thread::get_id();
6631 putLogError(100107, formatter.str(), __FILE__, __LINE__ );
6635 recive_data& recv_data = recive_data_it->second;
6637 send_status_it it = recv_data.send_status_list.begin();
6638 send_status_it it_end = recv_data.send_status_list.end();
6641 it = std::adjacent_find(it, it_end, data_send_list_incorrect());
6642 if (unlikely(it != it_end))
6644 boost::format formatter("Sending possible data is invalid. thread id : %d.");
6645 formatter % boost::this_thread::get_id();
6646 putLogError(100108, formatter.str(), __FILE__, __LINE__ );
6650 it = recv_data.send_status_list.begin();
6651 it = find_if(it, it_end, data_send_ok());
6652 if (unlikely(it == it_end))
6654 boost::format formatter("Sending possible data is not existed. thread id : %d.");
6655 formatter % boost::this_thread::get_id();
6656 putLogError(100109, formatter.str(), __FILE__, __LINE__ );
6660 //sending possible data is exist
6661 if (it->send_possible_size > 0)
6663 //status remain SEND_OK
6664 it->status = SEND_OK;
6666 it->send_offset += it->send_end_size;
6667 //send_end_size recalc
6668 it->send_end_size = 0;
6670 //sending possible data is not exist
6673 //can recive from clent continue
6674 if (it->send_rest_size > 0)
6676 //change status from SEND_OK to SEND_CONTINUE
6677 it->status = SEND_CONTINUE;
6679 //can not recive from clent continue
6682 //change status from SEND_OK to SEND_END
6683 it->status = SEND_END;
6687 it = recv_data.send_status_list.begin();
6688 it = find_if(it, it_end, data_send_ok());
6689 //send_ok item is exist
6692 status = CLIENT_CONNECTION_CHECK;
6694 //send_ok item is not exist
6698 if (session_data->end_flag == END_FLAG_ON)
6700 status = CLIENT_DISCONNECT;
6706 if (session_data->sorry_flag == SORRY_FLAG_ON)
6708 status = SORRYSERVER_RECV;
6713 status = REALSERVER_RECV;
6720 /*-------- DEBUG LOG --------*/
6721 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6723 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6724 "handle_client_send() : catch exception e = %d. thread id : %d.");
6725 formatter % e % boost::this_thread::get_id();
6726 putLogDebug(100221, formatter.str(), __FILE__, __LINE__ );
6728 /*------DEBUG LOG END------*/
6731 catch (const std::exception& ex)
6733 std::cerr << "protocol_module_sessionless::handle_client_send() : exception : error = " << ex.what() << "." << std::endl;
6734 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6735 "handle_client_send() : exception : error = %s. thread id : %d.");
6736 formatter % ex.what() % boost::this_thread::get_id();
6737 putLogError(100110, formatter.str(), __FILE__, __LINE__ );
6742 std::cerr << "protocol_module_sessionless::handle_client_send() : Unknown exception." << std::endl;
6743 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6744 "handle_client_send() : Unknown exception. thread id : %d.");
6745 formatter % boost::this_thread::get_id();
6746 putLogError(100111, formatter.str(), __FILE__, __LINE__ );
6750 /*-------- DEBUG LOG --------*/
6751 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6753 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6754 "handle_client_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
6755 formatter % status % boost::this_thread::get_id();
6756 putLogDebug(100222, formatter.str(), __FILE__, __LINE__ );
6758 /*------DEBUG LOG END------*/
6763 //! call from client disconnect event. use upstream thread and downstream thread.
6764 //! @param[in] upstream and downstream thread id( check! one thread one event! )
6765 //! @return session use EVENT mode
6766 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_disconnect(
6767 const boost::thread::id thread_id)
6769 /*-------- DEBUG LOG --------*/
6770 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6772 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6773 "handle_client_disconnect(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
6774 formatter % FINALIZE % boost::this_thread::get_id();
6775 putLogDebug(100223, formatter.str(), __FILE__, __LINE__ );
6777 /*------DEBUG LOG END------*/
6781 //! call from sorry mode event. use upstream thread and downstream thread
6782 //! @param[in] upstream and downstream thread id( check! one thread one event and first time call pattern )
6783 //! @return session use EVENT mode
6784 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorry_enable(
6785 const boost::thread::id thread_id)
6787 /*-------- DEBUG LOG --------*/
6788 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6790 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6791 "handle_sorry_enable(const boost::thread::id thread_id) : "
6793 formatter % thread_id;
6794 putLogDebug(100224, formatter.str(), __FILE__, __LINE__ );
6796 /*------DEBUG LOG END------*/
6798 EVENT_TAG status = FINALIZE;
6799 boost::asio::ip::tcp::endpoint endpoint;
6800 bool send_possible = false;
6801 bool send_continue = false;
6802 bool send_disable = false;
6803 thread_data_ptr session_data;
6804 session_thread_data_map_it session_thread_it;
6805 recive_data_map_it recive_data_it;
6810 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
6812 session_thread_it = session_thread_data_map.find(thread_id);
6813 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
6815 boost::format formatter("Invalid thread id. thread id : %d.");
6816 formatter % boost::this_thread::get_id();
6817 putLogError(100112, formatter.str(), __FILE__, __LINE__ );
6821 session_data = session_thread_it->second;
6824 endpoint = session_data->thread_division == THREAD_DIVISION_UP_STREAM ? session_data->client_endpoint_tcp
6825 : session_data->target_endpoint;
6826 recive_data_it = session_data->recive_data_map.find(endpoint);
6827 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
6829 //must be down thread
6830 if (unlikely(session_data->thread_division == THREAD_DIVISION_UP_STREAM))
6832 boost::format formatter("Invalid endpoint. thread id : %d.");
6833 formatter % boost::this_thread::get_id();
6834 putLogError(100113, formatter.str(), __FILE__, __LINE__ );
6837 session_data->sorry_flag = SORRY_FLAG_ON;
6838 /*-------- DEBUG LOG --------*/
6839 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6841 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6842 "handle_sorry_enable() : SORRY_FLAG_ON. thread id : %d.");
6843 formatter % boost::this_thread::get_id();
6844 putLogDebug(100225, formatter.str(), __FILE__, __LINE__ );
6846 /*------DEBUG LOG END------*/
6847 status = SORRYSERVER_RECV;
6851 recive_data& recv_data = recive_data_it->second;
6853 //get this thread sending possible data
6854 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
6855 data_send_possible());
6856 if (it != recv_data.send_status_list.end())
6858 send_possible = true;
6861 it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_continue());
6862 if (it != recv_data.send_status_list.end())
6864 send_continue = true;
6867 it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_disable());
6868 if (it != recv_data.send_status_list.end())
6870 send_disable = true;
6874 if (session_data->thread_division == THREAD_DIVISION_UP_STREAM)
6876 //accept_end_flag is off
6877 if (session_data->accept_end_flag == ACCEPT_END_FLAG_OFF)
6880 session_data->sorry_flag = SORRY_FLAG_ON;
6881 /*-------- DEBUG LOG --------*/
6882 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6884 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6885 "handle_sorry_enable() : SORRY_FLAG_ON. thread id : %d.");
6886 formatter % boost::this_thread::get_id();
6887 putLogDebug(100226, formatter.str(), __FILE__, __LINE__ );
6889 /*------DEBUG LOG END------*/
6892 //accept_end_flag is on
6896 if (session_data->sorry_flag == SORRY_FLAG_ON)
6900 status = SORRYSERVER_CONNECT;
6904 status = SORRYSERVER_SELECT;
6908 //set sorry flag off
6911 //the data that can be sent continue is exist
6915 session_data->end_flag = END_FLAG_ON;
6916 /*-------- DEBUG LOG --------*/
6917 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6919 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6920 "handle_sorry_enable() : END_FLAG_ON. thread id : %d.");
6921 formatter % boost::this_thread::get_id();
6922 putLogDebug(100227, formatter.str(), __FILE__, __LINE__ );
6924 /*------DEBUG LOG END------*/
6925 status = REALSERVER_DISCONNECT;
6927 //the data that can be sent continue is not exist
6930 //set sorryserver_switch_flag on
6931 session_data->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_ON;
6932 /*-------- DEBUG LOG --------*/
6933 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6935 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6936 "handle_sorry_enable() : SORRYSERVER_SWITCH_FLAG_ON. thread id : %d.");
6937 formatter % boost::this_thread::get_id();
6938 putLogDebug(100228, formatter.str(), __FILE__, __LINE__ );
6940 /*------DEBUG LOG END------*/
6942 session_data->sorry_flag = SORRY_FLAG_ON;
6943 /*-------- DEBUG LOG --------*/
6944 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6946 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6947 "handle_sorry_enable() : SORRY_FLAG_ON. thread id : %d.");
6948 formatter % boost::this_thread::get_id();
6949 putLogDebug(100229, formatter.str(), __FILE__, __LINE__ );
6951 /*------DEBUG LOG END------*/
6952 status = REALSERVER_DISCONNECT;
6961 if (session_data->sorry_flag == SORRY_FLAG_ON)
6963 //sending possible data is exist
6966 status = CLIENT_CONNECTION_CHECK;
6968 //sending possible data is not exist
6971 status = SORRYSERVER_RECV;
6978 session_data->sorry_flag = SORRY_FLAG_ON;
6979 /*-------- DEBUG LOG --------*/
6980 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6982 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6983 "handle_sorry_enable() : SORRY_FLAG_ON. thread id : %d.");
6984 formatter % boost::this_thread::get_id();
6985 putLogDebug(100230, formatter.str(), __FILE__, __LINE__ );
6987 /*------DEBUG LOG END------*/
6988 session_data->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_ON;
6989 /*-------- DEBUG LOG --------*/
6990 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6992 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
6993 "handle_sorry_enable() : SORRYSERVER_SWITCH_FLAG_ON. thread id : %d.");
6994 formatter % boost::this_thread::get_id();
6995 putLogDebug(100231, formatter.str(), __FILE__, __LINE__ );
6997 /*------DEBUG LOG END------*/
6999 //sending ng data is exist or send_rest_size > 0
7003 session_data->end_flag = END_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() : END_FLAG_ON. thread id : %d.");
7009 formatter % boost::this_thread::get_id();
7010 putLogDebug(100232, formatter.str(), __FILE__, __LINE__ );
7012 /*------DEBUG LOG END------*/
7013 status = REALSERVER_DISCONNECT;
7018 //sending possible data is exist
7021 status = CLIENT_CONNECTION_CHECK;
7023 //sending possible data is not exist
7026 status = SORRYSERVER_RECV;
7035 /*-------- DEBUG LOG --------*/
7036 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7038 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7039 "handle_sorry_enable() : catch exception e = %d. thread id : %d.");
7040 formatter % e % boost::this_thread::get_id();
7041 putLogDebug(100233, formatter.str(), __FILE__, __LINE__ );
7043 /*------DEBUG LOG END------*/
7046 catch (const std::exception& ex)
7048 std::cerr << "protocol_module_sessionless::handle_sorry_enable() : exception : error = " << ex.what() << "." << std::endl;
7049 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7050 "handle_sorry_enable() : exception : error = %s. thread id : %d.");
7051 formatter % ex.what() % boost::this_thread::get_id();
7052 putLogError(100114, formatter.str(), __FILE__, __LINE__ );
7057 std::cerr << "protocol_module_sessionless::handle_sorry_enable() : Unknown exception." << std::endl;
7058 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7059 "handle_sorry_enable() : Unknown exception. thread id : %d.");
7060 formatter % boost::this_thread::get_id();
7061 putLogError(100115, formatter.str(), __FILE__, __LINE__ );
7065 /*-------- DEBUG LOG --------*/
7066 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7068 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7069 "handle_sorry_enable(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
7070 formatter % status % boost::this_thread::get_id();
7071 putLogDebug(100234, formatter.str(), __FILE__, __LINE__ );
7073 /*------DEBUG LOG END------*/
7078 //! call from sorry mode disable. use upstream thread and downstream thread.
7079 //! @param[in] upstream and downstream thread id( check! one thread one event )
7080 //! @return session use EVENT mode
7081 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorry_disable(
7082 const boost::thread::id thread_id)
7084 /*-------- DEBUG LOG --------*/
7085 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7087 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7088 "handle_sorry_disable(const boost::thread::id thread_id) : "
7090 formatter % thread_id;
7091 putLogDebug(100235, formatter.str(), __FILE__, __LINE__ );
7093 /*------DEBUG LOG END------*/
7094 EVENT_TAG status = FINALIZE;
7095 boost::asio::ip::tcp::endpoint endpoint;
7096 bool send_possible = false;
7097 bool send_disable = false;
7098 bool send_continue = false;
7099 thread_data_ptr session_data;
7104 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
7106 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
7107 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
7109 boost::format formatter("Invalid thread id. thread id : %d.");
7110 formatter % boost::this_thread::get_id();
7111 putLogError(100116, formatter.str(), __FILE__, __LINE__ );
7115 session_data = session_thread_it->second;
7118 endpoint = session_data->thread_division == THREAD_DIVISION_UP_STREAM ? session_data->client_endpoint_tcp
7119 : session_data->target_endpoint;
7120 recive_data_map_it recive_data_it = session_data->recive_data_map.find(endpoint);
7121 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
7123 //must be down thread
7124 if (unlikely(session_data->thread_division == THREAD_DIVISION_UP_STREAM))
7126 boost::format formatter("Invalid endpoint. thread id : %d.");
7127 formatter % boost::this_thread::get_id();
7128 putLogError(100117, formatter.str(), __FILE__, __LINE__ );
7132 session_data->sorry_flag = SORRY_FLAG_OFF;
7133 /*-------- DEBUG LOG --------*/
7134 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7136 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7137 "handle_sorry_disable() : SORRY_FLAG_OFF. thread id : %d.");
7138 formatter % boost::this_thread::get_id();
7139 putLogDebug(100236, formatter.str(), __FILE__, __LINE__ );
7141 /*------DEBUG LOG END------*/
7142 status = REALSERVER_RECV;
7146 recive_data& recv_data = recive_data_it->second;
7148 //get this thread sending possible data
7149 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
7150 data_send_possible());
7151 if (it != recv_data.send_status_list.end())
7153 send_possible = true;
7156 //sending ng data is exist or send_rest_size > 0
7157 it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_disable());
7158 if (it != recv_data.send_status_list.end())
7160 send_disable = true;
7163 //the data that can be sent continue is exist
7164 it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_continue());
7165 if (it != recv_data.send_status_list.end())
7167 send_continue = true;
7171 if (session_data->thread_division == THREAD_DIVISION_UP_STREAM)
7173 //accept_end_flag is off
7174 if (session_data->accept_end_flag == ACCEPT_END_FLAG_OFF)
7176 //set sorry flag off
7177 session_data->sorry_flag = SORRY_FLAG_OFF;
7178 /*-------- DEBUG LOG --------*/
7179 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7181 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7182 "handle_sorry_disable() : SORRY_FLAG_OFF. thread id : %d.");
7183 formatter % boost::this_thread::get_id();
7184 putLogDebug(100237, formatter.str(), __FILE__, __LINE__ );
7186 /*------DEBUG LOG END------*/
7190 //accept_end_flag is on
7194 if (session_data->sorry_flag == SORRY_FLAG_ON)
7196 //the data that can be sent continue is exist
7200 session_data->end_flag = END_FLAG_ON;
7201 /*-------- DEBUG LOG --------*/
7202 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7204 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7205 "handle_sorry_disable() : END_FLAG_ON. thread id : %d.");
7206 formatter % boost::this_thread::get_id();
7207 putLogDebug(100238, formatter.str(), __FILE__, __LINE__ );
7209 /*------DEBUG LOG END------*/
7210 status = SORRYSERVER_DISCONNECT;
7212 //the data that can be sent continue is not exist
7215 //set realserver_switch_flag on
7216 session_data->realserver_switch_flag = REALSERVER_SWITCH_FLAG_ON;
7217 /*-------- DEBUG LOG --------*/
7218 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7220 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7221 "handle_sorry_disable() : REALSERVER_SWITCH_FLAG_ON. thread id : %d.");
7222 formatter % boost::this_thread::get_id();
7223 putLogDebug(100239, formatter.str(), __FILE__, __LINE__ );
7225 /*------DEBUG LOG END------*/
7226 //set sorry_flag off
7227 session_data->sorry_flag = SORRY_FLAG_OFF;
7228 /*-------- DEBUG LOG --------*/
7229 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7231 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7232 "handle_sorry_disable() : SORRY_FLAG_OFF. thread id : %d.");
7233 formatter % boost::this_thread::get_id();
7234 putLogDebug(100240, formatter.str(), __FILE__, __LINE__ );
7236 /*------DEBUG LOG END------*/
7237 status = SORRYSERVER_DISCONNECT;
7245 status = REALSERVER_CONNECT;
7249 status = REALSERVER_SELECT;
7258 if (session_data->sorry_flag == SORRY_FLAG_ON)
7260 //set sorry_flag off
7261 session_data->sorry_flag = SORRY_FLAG_OFF;
7262 /*-------- DEBUG LOG --------*/
7263 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7265 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7266 "handle_sorry_disable() : SORRY_FLAG_OFF. thread id : %d.");
7267 formatter % boost::this_thread::get_id();
7268 putLogDebug(100241, formatter.str(), __FILE__, __LINE__ );
7270 /*------DEBUG LOG END------*/
7271 session_data->realserver_switch_flag = REALSERVER_SWITCH_FLAG_ON;
7272 /*-------- DEBUG LOG --------*/
7273 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7275 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7276 "handle_sorry_disable() : REALSERVER_SWITCH_FLAG_ON. thread id : %d.");
7277 formatter % boost::this_thread::get_id();
7278 putLogDebug(100242, formatter.str(), __FILE__, __LINE__ );
7280 /*------DEBUG LOG END------*/
7281 //sending ng data is exist or send_rest_size > 0
7285 session_data->end_flag = END_FLAG_ON;
7286 /*-------- DEBUG LOG --------*/
7287 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7289 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7290 "handle_sorry_disable() : END_FLAG_ON. thread id : %d.");
7291 formatter % boost::this_thread::get_id();
7292 putLogDebug(100243, formatter.str(), __FILE__, __LINE__ );
7294 /*------DEBUG LOG END------*/
7295 status = SORRYSERVER_DISCONNECT;
7300 //sending possible data is exist
7303 status = CLIENT_CONNECTION_CHECK;
7305 //sending possible data is not exist
7308 status = REALSERVER_RECV;
7315 //sending possible data is exist
7318 status = CLIENT_CONNECTION_CHECK;
7320 //sending possible data is not exist
7323 status = REALSERVER_RECV;
7333 /*-------- DEBUG LOG --------*/
7334 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7336 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7337 "handle_sorry_disable() : catch exception e = %d. thread id : %d.");
7338 formatter % e % boost::this_thread::get_id();
7339 putLogDebug(100244, formatter.str(), __FILE__, __LINE__ );
7341 /*------DEBUG LOG END------*/
7344 catch (std::exception& ex)
7346 std::cerr << "protocol_module_sessionless::handle_sorry_disable() : exception : error = " << ex.what() << "." << std::endl;
7347 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7348 "handle_sorry_disable() : exception : error = %s. thread id : %d.");
7349 formatter % ex.what() % boost::this_thread::get_id();
7350 putLogError(100118, formatter.str(), __FILE__, __LINE__ );
7355 std::cerr << "protocol_module_sessionless::handle_sorry_disable() : Unknown exception." << std::endl;
7356 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7357 "handle_sorry_disable() : Unknown exception. thread id : %d.");
7358 formatter % boost::this_thread::get_id();
7359 putLogError(100119, formatter.str(), __FILE__, __LINE__ );
7363 /*-------- DEBUG LOG --------*/
7364 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7366 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7367 "handle_sorry_disable(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
7368 formatter % status % boost::this_thread::get_id();
7369 putLogDebug(100245, formatter.str(), __FILE__, __LINE__ );
7371 /*------DEBUG LOG END------*/
7376 //! call from realserver disconnect. use upstream thread and downstream thread
7377 //! @param[in] upstream and downstream thread id( check! one thread one event )
7378 //! @param[in] disconnected realserver endpoint.
7379 //! @return session use EVENT mode
7380 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_disconnect(
7381 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint)
7383 /*-------- DEBUG LOG --------*/
7384 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7386 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7387 "handle_realserver_disconnect(const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint) : "
7388 "thread_id = %d, rs_endpoint = [%s]:%d.");
7389 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
7390 putLogDebug(100246, formatter.str(), __FILE__, __LINE__ );
7392 /*------DEBUG LOG END------*/
7393 EVENT_TAG status = FINALIZE;
7394 bool possible_flag = false;
7395 thread_data_ptr session_data;
7396 boost::asio::ip::tcp::endpoint endpoint;
7401 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
7403 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
7404 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
7406 boost::format formatter("Invalid thread id. thread id : %d.");
7407 formatter % boost::this_thread::get_id();
7408 putLogError(100120, formatter.str(), __FILE__, __LINE__ );
7412 session_data = session_thread_it->second;
7415 endpoint = session_data->thread_division == THREAD_DIVISION_UP_STREAM ? session_data->client_endpoint_tcp
7416 : session_data->target_endpoint;
7417 recive_data_map_it recive_data_it = session_data->recive_data_map.find(endpoint);
7418 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
7420 boost::format formatter("Invalid endpoint. thread id : %d.");
7421 formatter % boost::this_thread::get_id();
7422 putLogError(100121, formatter.str(), __FILE__, __LINE__ );
7426 recive_data& recv_data = recive_data_it->second;
7428 //the data that can be sent possible is exist
7429 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
7430 data_send_possible());
7431 if (it != recv_data.send_status_list.end())
7433 possible_flag = true;
7437 if (session_data->thread_division == THREAD_DIVISION_UP_STREAM)
7440 if (session_data->end_flag == END_FLAG_ON)
7442 status = CLIENT_RECV;
7447 //sorryserver_switch_flag is on
7448 if (session_data->sorryserver_switch_flag == SORRYSERVER_SWITCH_FLAG_ON)
7450 session_data->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_OFF;
7451 /*-------- DEBUG LOG --------*/
7452 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7454 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7455 "handle_realserver_disconnect() : SORRYSERVER_SWITCH_FLAG_OFF. thread id : %d.");
7456 formatter % boost::this_thread::get_id();
7457 putLogDebug(100247, formatter.str(), __FILE__, __LINE__ );
7459 /*------DEBUG LOG END------*/
7461 status = SORRYSERVER_SELECT;
7464 //sorryserver_switch_flag is off
7468 session_data->end_flag = END_FLAG_ON;
7469 /*-------- DEBUG LOG --------*/
7470 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7472 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7473 "handle_realserver_disconnect() : END_FLAG_ON. thread id : %d.");
7474 formatter % boost::this_thread::get_id();
7475 putLogDebug(100248, formatter.str(), __FILE__, __LINE__ );
7477 /*------DEBUG LOG END------*/
7478 status = CLIENT_RECV;
7485 if (session_data->end_flag == END_FLAG_ON)
7487 status = CLIENT_DISCONNECT;
7491 if (session_data->sorryserver_switch_flag == SORRYSERVER_SWITCH_FLAG_ON)
7493 session_data->sorryserver_switch_flag = SORRYSERVER_SWITCH_FLAG_OFF;
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() : SORRYSERVER_SWITCH_FLAG_OFF. thread id : %d.");
7499 formatter % boost::this_thread::get_id();
7500 putLogDebug(100249, formatter.str(), __FILE__, __LINE__ );
7502 /*------DEBUG LOG END------*/
7503 status = SORRYSERVER_RECV;
7508 session_data->end_flag = END_FLAG_ON;
7509 /*-------- DEBUG LOG --------*/
7510 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7512 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7513 "handle_realserver_disconnect() : END_FLAG_ON. thread id : %d.");
7514 formatter % boost::this_thread::get_id();
7515 putLogDebug(100250, formatter.str(), __FILE__, __LINE__ );
7517 /*------DEBUG LOG END------*/
7518 status = CLIENT_DISCONNECT;
7522 //the data that can be sent possible is exist
7525 status = CLIENT_CONNECTION_CHECK;
7531 /*-------- DEBUG LOG --------*/
7532 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7534 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7535 "handle_realserver_disconnect() : catch exception e = %d. thread id : %d.");
7536 formatter % e % boost::this_thread::get_id();
7537 putLogDebug(100251, formatter.str(), __FILE__, __LINE__ );
7539 /*------DEBUG LOG END------*/
7542 catch (std::exception& ex)
7544 std::cerr << "protocol_module_sessionless::handle_realserver_disconnect() : exception: error = " << ex.what() << "." << std::endl;
7545 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7546 "handle_realserver_disconnect() : exception : error = %s. thread id : %d.");
7547 formatter % ex.what() % boost::this_thread::get_id();
7548 putLogError(100122, formatter.str(), __FILE__, __LINE__ );
7553 std::cerr << "protocol_module_sessionless::handle_realserver_disconnect() : Unknown exception." << std::endl;
7554 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7555 "handle_realserver_disconnect() : Unknown exception. thread id : %d.");
7556 formatter % boost::this_thread::get_id();
7557 putLogError(100123, formatter.str(), __FILE__, __LINE__ );
7561 /*-------- DEBUG LOG --------*/
7562 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7564 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7565 "handle_realserver_disconnect(const boost::thread::id thread_id, "
7566 "const boost::asio::ip::tcp::endpoint & rs_endpoint) : return_value = %d. thread id : %d.");
7567 formatter % status % boost::this_thread::get_id();
7568 putLogDebug(100252, formatter.str(), __FILE__, __LINE__ );
7570 /*------DEBUG LOG END------*/
7575 //! call from sorry server disconnect. use upstraem thread and downstream thread
7576 //! @param[in] upstream and downstream thread id( check! one thread one event )
7577 //! @param[in] disconnect sorryserver endpoint
7578 //! @return session use EVENT mode
7579 //! @return session use EVENT mode
7580 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_disconnect(
7581 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint)
7583 /*-------- DEBUG LOG --------*/
7584 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7588 "in_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7589 "handle_sorryserver_disconnect(const boost::thread::id thread_id, "
7590 "const boost::asio::ip::tcp::endpoint & sorry_endpoint) : "
7591 "thread_id = %d, sorry_endpoint = [%s]:%d.");
7592 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port() ;
7593 putLogDebug(100253, formatter.str(), __FILE__, __LINE__ );
7595 /*------DEBUG LOG END------*/
7596 EVENT_TAG status = FINALIZE;
7597 bool possible_flag = false;
7598 thread_data_ptr session_data;
7599 boost::asio::ip::tcp::endpoint endpoint;
7604 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
7606 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
7607 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
7609 boost::format formatter("Invalid thread id. thread id : %d.");
7610 formatter % boost::this_thread::get_id();
7611 putLogError(100124, formatter.str(), __FILE__, __LINE__ );
7615 session_data = session_thread_it->second;
7618 endpoint = session_data->thread_division == THREAD_DIVISION_UP_STREAM ? session_data->client_endpoint_tcp
7619 : session_data->target_endpoint;
7620 recive_data_map_it recive_data_it = session_data->recive_data_map.find(endpoint);
7621 if (unlikely(recive_data_it == session_data->recive_data_map.end()))
7623 boost::format formatter("Invalid endpoint. thread id : %d.");
7624 formatter % boost::this_thread::get_id();
7625 putLogError(100125, formatter.str(), __FILE__, __LINE__ );
7629 recive_data& recv_data = recive_data_it->second;
7631 //the data that can be sent possible is exist
7632 send_status_it it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(),
7633 data_send_possible());
7634 if (it != recv_data.send_status_list.end())
7636 possible_flag = true;
7640 if (session_data->thread_division == THREAD_DIVISION_UP_STREAM)
7643 if (session_data->end_flag == END_FLAG_ON)
7645 status = CLIENT_RECV;
7650 //realserver_switch_flag is on
7651 if (session_data->realserver_switch_flag == REALSERVER_SWITCH_FLAG_ON)
7653 session_data->realserver_switch_flag = REALSERVER_SWITCH_FLAG_OFF;
7654 /*-------- DEBUG LOG --------*/
7655 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7657 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7658 "handle_sorryserver_disconnect() : REALSERVER_SWITCH_FLAG_OFF. thread id : %d.");
7659 formatter % boost::this_thread::get_id();
7660 putLogDebug(100254, formatter.str(), __FILE__, __LINE__ );
7662 /*------DEBUG LOG END------*/
7663 status = REALSERVER_SELECT;
7665 //realserver_switch_flag is off
7669 session_data->end_flag = END_FLAG_ON;
7670 /*-------- DEBUG LOG --------*/
7671 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7673 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7674 "handle_sorryserver_disconnect() : END_FLAG_ON. thread id : %d.");
7675 formatter % boost::this_thread::get_id();
7676 putLogDebug(100255, formatter.str(), __FILE__, __LINE__ );
7678 /*------DEBUG LOG END------*/
7679 status = CLIENT_RECV;
7686 if (session_data->end_flag == END_FLAG_ON)
7688 status = CLIENT_DISCONNECT;
7692 if (session_data->realserver_switch_flag == REALSERVER_SWITCH_FLAG_ON)
7694 session_data->realserver_switch_flag = REALSERVER_SWITCH_FLAG_OFF;
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() : REALSERVER_SWITCH_FLAG_OFF. thread id : %d.");
7700 formatter % boost::this_thread::get_id();
7701 putLogDebug(100256, formatter.str(), __FILE__, __LINE__ );
7703 /*------DEBUG LOG END------*/
7704 status = REALSERVER_RECV;
7708 session_data->end_flag = END_FLAG_ON;
7709 /*-------- DEBUG LOG --------*/
7710 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7712 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7713 "handle_sorryserver_disconnect() : END_FLAG_ON. thread id : %d.");
7714 formatter % boost::this_thread::get_id();
7715 putLogDebug(100257, formatter.str(), __FILE__, __LINE__ );
7717 /*------DEBUG LOG END------*/
7718 status = CLIENT_DISCONNECT;
7722 //the data that can be sent possible is exist
7725 status = CLIENT_CONNECTION_CHECK;
7731 /*-------- DEBUG LOG --------*/
7732 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7734 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7735 "handle_sorryserver_disconnect() : catch exception e = %d. thread id : %d.");
7736 formatter % e % boost::this_thread::get_id();
7737 putLogDebug(100258, formatter.str(), __FILE__, __LINE__ );
7739 /*------DEBUG LOG END------*/
7742 catch (const std::exception& ex)
7744 std::cerr << "protocol_module_sessionless::handle_sorryserver_disconnect() : exception : error = " << ex.what() << "." << std::endl;
7745 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7746 "handle_sorryserver_disconnect() : exception : error = %s. thread id : %d.");
7747 formatter % ex.what() % boost::this_thread::get_id();
7748 putLogError(100126, formatter.str(), __FILE__, __LINE__ );
7753 std::cerr << "protocol_module_sessionless::handle_sorryserver_disconnect() : Unknown exception." << std::endl;
7754 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7755 "handle_sorryserver_disconnect() : Unknown exception. thread id : %d.");
7756 formatter % boost::this_thread::get_id();
7757 putLogError(100127, formatter.str(), __FILE__, __LINE__ );
7761 /*-------- DEBUG LOG --------*/
7762 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7766 "out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7767 "handle_sorryserver_disconnect(const boost::thread::id thread_id, "
7768 "const boost::asio::ip::tcp::endpoint& sorry_endpoint) : return_value = %d. thread id : %d.");
7769 formatter % status % boost::this_thread::get_id();
7770 putLogDebug(100259, formatter.str(), __FILE__, __LINE__ );
7772 /*------DEBUG LOG END------*/
7777 //! call from realserver disconnect. use upstream thread and downstream thread.
7778 //! @param[in] upstream and downstream thread id( check! one thread one event )
7779 //! @param[in] disconnect realserver endpoint
7780 //! @return session use EVENT mode.
7781 protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_realserver_close(
7782 const boost::thread::id thread_id, const boost::asio::ip::udp::endpoint & rs_endpoint)
7784 /*-------- DEBUG LOG --------*/
7785 if (unlikely(LOG_LV_DEBUG == getloglevel()))
7787 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_sessionless::"
7788 "handle_realserver_close(const boost::thread::id thread_id, "
7789 "const boost::asio::ip::udp::endpoint & rs_endpoint) : "
7790 "return_value = %d. thread id : %d.");
7791 formatter % STOP % boost::this_thread::get_id();
7792 putLogDebug(100260, formatter.str(), __FILE__, __LINE__ );
7794 /*------DEBUG LOG END------*/
7800 extern "C" l7vs::protocol_module_base*
7803 return dynamic_cast<l7vs::protocol_module_base*>(new l7vs::protocol_module_sessionless());
7807 destroy_module( l7vs::protocol_module_base* in )