• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

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

Commit MetaInfo

Revisãoeb3423115483df4c6344a9f367599a96f48ddbb3 (tree)
Hora2010-11-08 21:13:55
Autor0809216 <0809216@1ed6...>
Commiter0809216

Mensagem de Log

l7directord copyright

git-svn-id: http://10.144.169.20/repos/um/branches/l7vsd-3.x-ramiel-epoll-cond@10424 1ed66053-1c2d-0410-8867-f7571e6e31d3

Mudança Sumário

Diff

--- a/l7directord/l7directord
+++ b/l7directord/l7directord
@@ -78,7 +78,7 @@ use Socket6;
7878
7979 # current version
8080 our $VERSION = '3.0.0-0';
81-our $COPYRIGHT = 'Copyright (C) 2010 NTT COMWARE CORPORATION;
81+our $COPYRIGHT = 'Copyright (C) 2010 NTT COMWARE CORPORATION';
8282
8383 # default global config values
8484 our %GLOBAL = (
--- a/l7vsd/src/tcp_session.cpp
+++ b/l7vsd/src/tcp_session.cpp
@@ -1378,93 +1378,25 @@ void tcp_session::up_thread_client_receive(const TCP_PROCESS_TYPE_TAG process_ty
13781378 Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
13791379 }
13801380
1381- if (unlikely(0 < parent_service.get_wait_upstream())) {
1382- //----Debug log----------------------------------------------------------------------
1383- if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
1384- std::stringstream buf;
1385- buf << "Thread ID[" << boost::this_thread::get_id() << "] ";
1386- buf << "up_thread_client_receive qos wait active";
1387- Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 35, buf.str(), __FILE__, __LINE__);
1388- }
1389- //----Debug log----------------------------------------------------------------------
1390- return; // try again
1391- }
1392- up_thread_data_client_side.initialize();
1393- boost::array<char, MAX_BUFFER_SIZE>& data_buff = up_thread_data_client_side.get_data();
13941381 boost::system::error_code ec;
13951382 std::size_t recv_size;
1396- UP_THREAD_FUNC_TYPE_TAG func_tag;
1397-
1383+ UP_THREAD_FUNC_TYPE_TAG func_tag = UP_FUNC_CLIENT_RECEIVE;
13981384 struct epoll_event event;
1399- event.data.fd = !ssl_flag ? client_socket.get_socket().native()
1400- : client_ssl_socket.get_socket().lowest_layer().native();
1385+ int ret_fds;
14011386
1402- // epoll wait codes
1403- if (is_epoll_edge_trigger) {
1404- event.events = EPOLLIN | EPOLLHUP | EPOLLET;
1405- } else {
1406- event.events = EPOLLIN | EPOLLHUP;
1407- }
1408- bool add_flag = false;
1409- if (!up_client_epollfd_registered) {
1410- if (epoll_ctl(up_client_epollfd, EPOLL_CTL_ADD, event.data.fd, &event) < 0) {
1411- std::stringstream buf;
1412- buf << "up_thread_client_receive: epoll_ctl EPOLL_CTL_ADD error: ";
1413- buf << strerror(errno);
1414- Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
1415- boost::this_thread::yield();
1416- return;
1417- }
1418- up_client_epollfd_registered = true;
1419- add_flag = true;
1420- }
1387+ up_thread_data_client_side.initialize();
1388+ boost::array<char, MAX_BUFFER_SIZE>& data_buff = up_thread_data_client_side.get_data();
14211389
1422- if (is_epoll_edge_trigger && (!add_flag)) {
1423- if (epoll_ctl(up_client_epollfd, EPOLL_CTL_MOD, event.data.fd, &event) < 0) {
1424- std::stringstream buf;
1425- buf << "up_thread_client_receive: epoll_ctl EPOLL_CTL_MOD error: ";
1426- buf << strerror(errno);
1427- Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
1428- up_thread_next_call_function = up_thread_function_array[UP_FUNC_CLIENT_DISCONNECT];
1429- return;
1430- }
1431- }
1432- int ret_fds = epoll_wait(up_client_epollfd, up_client_events, EVENT_NUM, epoll_timeout);
1433- if (ret_fds == 0) {
1390+ if (unlikely(0 < parent_service.get_wait_upstream())) {
14341391 //----Debug log----------------------------------------------------------------------
14351392 if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
1436- boost::format formatter("up_thread_client_receive: epoll_wait timeout %d msec");
1437- formatter % epoll_timeout;
1438- Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
1393+ std::stringstream buf;
1394+ buf << "Thread ID[" << boost::this_thread::get_id() << "] ";
1395+ buf << "up_thread_client_receive qos wait active";
1396+ Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 35, buf.str(), __FILE__, __LINE__);
14391397 }
14401398 //----Debug log----------------------------------------------------------------------
1441- up_thread_next_call_function = up_thread_function_array[UP_FUNC_CLIENT_RECEIVE];
1442- return;
1443- } else if (ret_fds < 0) {
1444- boost::format formatter("up_thread_client_receive: epoll_wait error: %s");
1445- formatter % strerror(errno);
1446- Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
1447- up_thread_next_call_function = up_thread_function_array[UP_FUNC_CLIENT_DISCONNECT];
1448- return;
1449- }
1450-
1451- for (int i = 0; i < ret_fds; ++i) {
1452- if (up_client_events[i].data.fd == event.data.fd) {
1453- if (up_client_events[i].events & EPOLLIN) {
1454- break;
1455- }
1456- if (up_client_events[i].events & EPOLLHUP) {
1457- up_thread_next_call_function = up_thread_function_array[UP_FUNC_CLIENT_DISCONNECT];
1458- //----Debug log----------------------------------------------------------------------
1459- if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
1460- boost::format formatter("Thread ID[%d] FUNC OUT up_thread_client_receive EPOLLHUP: NEXT_FUNC[%s]");
1461- formatter % boost::this_thread::get_id() % func_tag_to_string(UP_FUNC_CLIENT_DISCONNECT);
1462- Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
1463- }
1464- //----Debug log----------------------------------------------------------------------
1465- return;
1466- }
1467- }
1399+ goto up_thread_client_receive_out;
14681400 }
14691401
14701402 recv_size = !ssl_flag ? client_socket.read_some(
@@ -1473,14 +1405,10 @@ void tcp_session::up_thread_client_receive(const TCP_PROCESS_TYPE_TAG process_ty
14731405 : client_ssl_socket.read_some(
14741406 boost::asio::buffer(data_buff, MAX_BUFFER_SIZE),
14751407 ec);
1476-
14771408 if (!ec) {
14781409 if (recv_size > 0) {
14791410 //----Debug log----------------------------------------------------------------------
14801411 if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
1481- endpoint client_endpoint; // XXX redefined???
1482- client_endpoint = !ssl_flag ? client_socket.get_socket().lowest_layer().remote_endpoint(ec)
1483- : client_ssl_socket.get_socket().lowest_layer().remote_endpoint(ec);
14841412 boost::format formatter("Thread ID[%d] up_thread_client_receive receive data size[%d] from [%d]");
14851413 formatter % boost::this_thread::get_id() % recv_size % client_endpoint;
14861414 Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 36, formatter.str(), __FILE__, __LINE__);
@@ -1496,20 +1424,70 @@ void tcp_session::up_thread_client_receive(const TCP_PROCESS_TYPE_TAG process_ty
14961424 formatter % boost::this_thread::get_id() % module_event;
14971425 Logger::putLogError(LOG_CAT_L7VSD_SESSION, 20, formatter.str(), __FILE__, __LINE__);
14981426 up_thread_exit(process_type);
1499- return;
1427+ func_tag = UP_FUNC_EXIT;
1428+ } else {
1429+ func_tag = func_type->second;
15001430 }
1501- func_tag = func_type->second;
1502- } else {
1431+ } else if (recv_size < 0) {
15031432 boost::format formatter("Thread ID[%d] client read error. recv_size: %d");
15041433 formatter % boost::this_thread::get_id() % recv_size;
15051434 Logger::putLogError(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
1506- func_tag = UP_FUNC_CLIENT_RECEIVE;
15071435 }
15081436 } else {
1509- if (ec == boost::asio::error::eof) {
1437+ if (ec == boost::asio::error::try_again) {
1438+ // epoll wait codes
1439+ event.data.fd = !ssl_flag ? client_socket.get_socket().native()
1440+ : client_ssl_socket.get_socket().lowest_layer().native();
1441+
1442+ if (!up_client_epollfd_registered) {
1443+ if (is_epoll_edge_trigger) {
1444+ event.events = EPOLLIN | EPOLLHUP | EPOLLET;
1445+ } else {
1446+ event.events = EPOLLIN | EPOLLHUP;
1447+ }
1448+ if ( (!ssl_flag && !client_socket.get_socket().is_open()) ||
1449+ (ssl_flag && !client_ssl_socket.get_socket().lowest_layer().is_open()) ) {
1450+ func_tag = UP_FUNC_CLIENT_DISCONNECT;
1451+ goto up_thread_client_receive_out;
1452+ }
1453+ if (epoll_ctl(up_client_epollfd, EPOLL_CTL_ADD, event.data.fd, &event) < 0) {
1454+ std::stringstream buf;
1455+ buf << "up_thread_client_receive: epoll_ctl EPOLL_CTL_ADD error: ";
1456+ buf << strerror(errno);
1457+ Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
1458+ func_tag = UP_FUNC_CLIENT_DISCONNECT;
1459+ goto up_thread_client_receive_out;
1460+ }
1461+ up_client_epollfd_registered = true;
1462+ }
1463+ ret_fds = epoll_wait(up_client_epollfd, up_client_events, EVENT_NUM, epoll_timeout);
1464+ if (ret_fds == 0) {
1465+ goto up_thread_client_receive_out; // epoll timeout
1466+ } else if (ret_fds < 0) {
1467+ boost::format formatter("up_thread_client_receive: epoll_wait error: %s");
1468+ formatter % strerror(errno);
1469+ Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
1470+ func_tag = UP_FUNC_CLIENT_DISCONNECT;
1471+ goto up_thread_client_receive_out;
1472+ }
1473+
1474+ for (int i = 0; i < ret_fds; ++i) {
1475+ if (up_client_events[i].data.fd == event.data.fd) {
1476+ if (up_client_events[i].events & EPOLLIN) {
1477+ goto up_thread_client_receive_out;
1478+ }
1479+ if (up_client_events[i].events & EPOLLHUP) {
1480+ func_tag = UP_FUNC_CLIENT_DISCONNECT;
1481+ goto up_thread_client_receive_out;
1482+ }
1483+ }
1484+ }
1485+ boost::format formatter("up_thread_client_receive: unknown file descriptor's event: %s");
1486+ formatter % strerror(errno);
1487+ Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
1488+ func_tag = UP_FUNC_CLIENT_DISCONNECT;
1489+ } else if (ec == boost::asio::error::eof) {
15101490 func_tag = UP_FUNC_CLIENT_DISCONNECT;
1511- } else if (ec == boost::asio::error::try_again) {
1512- func_tag = UP_FUNC_CLIENT_RECEIVE;
15131491 } else {
15141492 boost::format formatter("Thread ID[%d] client read error: %s");
15151493 formatter % boost::this_thread::get_id() % ec.message();
@@ -1517,6 +1495,8 @@ void tcp_session::up_thread_client_receive(const TCP_PROCESS_TYPE_TAG process_ty
15171495 func_tag = UP_FUNC_CLIENT_DISCONNECT;
15181496 }
15191497 }
1498+
1499+up_thread_client_receive_out:
15201500 up_thread_next_call_function = up_thread_function_array[func_tag];
15211501
15221502 if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
@@ -1651,82 +1631,10 @@ void tcp_session::up_thread_realserver_send(const TCP_PROCESS_TYPE_TAG process_t
16511631 std::size_t data_size = up_thread_data_dest_side.get_size();
16521632 std::size_t send_data_size = up_thread_data_dest_side.get_send_size();
16531633 std::size_t send_size;
1654- UP_THREAD_FUNC_TYPE_TAG func_tag;
1634+ UP_THREAD_FUNC_TYPE_TAG func_tag = UP_FUNC_REALSERVER_SEND;
1635+ int ret_fds;
16551636
16561637 struct epoll_event event;
1657- event.data.fd = send_socket->second->get_socket().native();
1658- if (is_epoll_edge_trigger) {
1659- event.events = EPOLLOUT | EPOLLHUP | EPOLLET;
1660- } else {
1661- event.events = EPOLLOUT | EPOLLHUP;
1662- }
1663- bool add_flag = false;
1664- if (!up_realserver_epollfd_registered) {
1665- if (epoll_ctl(up_realserver_epollfd, EPOLL_CTL_ADD, event.data.fd, &event) < 0) {
1666- std::stringstream buf;
1667- buf << "up_thread_realserver_send: epoll_ctl EPOLL_CTL_ADD error: ";
1668- buf << strerror(errno);
1669- Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
1670- boost::this_thread::yield();
1671- return;
1672- }
1673- up_realserver_epollfd_registered = true;
1674- add_flag = true;
1675- }
1676-
1677- {
1678- rd_scoped_lock scoped_lock(exit_flag_update_mutex);
1679- if (unlikely(exit_flag)) {
1680- up_thread_next_call_function = up_thread_function_array[UP_FUNC_EXIT];
1681- return;
1682- }
1683- }
1684-
1685- if (is_epoll_edge_trigger && (!add_flag)) {
1686- if (epoll_ctl(up_realserver_epollfd, EPOLL_CTL_MOD, event.data.fd, &event) < 0) {
1687- std::stringstream buf;
1688- buf << "up_thread_realserver_send: epoll_ctl EPOLL_CTL_MOD error: ";
1689- buf << strerror(errno);
1690- Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
1691- boost::this_thread::yield();
1692- return;
1693- }
1694- }
1695-
1696- int ret_fds = epoll_wait(up_realserver_epollfd, up_realserver_events, EVENT_NUM, epoll_timeout);
1697- if (ret_fds <= 0) {
1698- if (ret_fds == 0) {
1699- //----Debug log----------------------------------------------------------------------
1700- if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
1701- std::stringstream buf;
1702- buf << "up_thread_realserver_send: epoll_wait timeout " << epoll_timeout << " msec.";
1703- Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
1704- }
1705- //----Debug log----------------------------------------------------------------------
1706- } else {
1707- std::stringstream buf;
1708- buf << "up_thread_realserver_send: epoll_wait error: " << strerror(errno);
1709- Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
1710- }
1711- //XXX no need to retry???
1712- up_thread_next_call_function = up_thread_function_array[UP_FUNC_REALSERVER_DISCONNECT];
1713- return;
1714- }
1715-
1716- for (int i = 0; i < ret_fds; ++i) {
1717- if (up_realserver_events[i].data.fd == event.data.fd) {
1718- if (up_realserver_events[i].events & EPOLLOUT) {
1719- break;
1720- } else if (up_realserver_events[i].events & EPOLLHUP) {
1721- std::stringstream buf;
1722- buf << "up_thread_realserver_send: epoll hung up event";
1723- Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
1724- up_thread_next_call_function = up_thread_function_array[UP_FUNC_REALSERVER_DISCONNECT];
1725- return;
1726- }
1727- }
1728- }
1729-
17301638 send_size = send_socket->second->write_some(
17311639 boost::asio::buffer(
17321640 data_buff.data() + send_data_size,
@@ -1743,29 +1651,70 @@ void tcp_session::up_thread_realserver_send(const TCP_PROCESS_TYPE_TAG process_t
17431651 Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 37, formatter.str(), __FILE__, __LINE__);
17441652 }
17451653 //----Debug log----------------------------------------------------------------------
1746- if (data_size > send_data_size) {
1747- func_tag = UP_FUNC_REALSERVER_SEND;
1748- } else {
1654+ if (data_size <= send_data_size) {
17491655 protocol_module_base::EVENT_TAG module_event = protocol_module->handle_realserver_send(up_thread_id);
17501656 std::map<protocol_module_base::EVENT_TAG, UP_THREAD_FUNC_TYPE_TAG>::iterator func_type = up_thread_module_event_map.find(module_event);
17511657 func_tag = func_type->second;
17521658 }
17531659 } else {
17541660 if (ec == boost::asio::error::try_again) {
1755- func_tag = UP_FUNC_REALSERVER_SEND;
1661+ event.data.fd = send_socket->second->get_socket().native();
1662+ if (!up_realserver_epollfd_registered) {
1663+ if (is_epoll_edge_trigger) {
1664+ event.events = EPOLLOUT | EPOLLHUP | EPOLLET;
1665+ } else {
1666+ event.events = EPOLLOUT | EPOLLHUP;
1667+ }
1668+ if (epoll_ctl(up_realserver_epollfd, EPOLL_CTL_ADD, event.data.fd, &event) < 0) {
1669+ std::stringstream buf;
1670+ buf << "up_thread_realserver_send: epoll_ctl EPOLL_CTL_ADD error: ";
1671+ buf << strerror(errno);
1672+ Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
1673+ goto up_thread_realserver_send_out;
1674+ }
1675+ up_realserver_epollfd_registered = true;
1676+ }
1677+ ret_fds = epoll_wait(up_realserver_epollfd, up_realserver_events, EVENT_NUM, epoll_timeout);
1678+ if (ret_fds == 0) {
1679+ goto up_thread_realserver_send_out; // epoll timeout
1680+ } else if (ret_fds < 0) {
1681+ std::stringstream buf;
1682+ buf << "up_thread_realserver_send: epoll_wait error: " << strerror(errno);
1683+ Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
1684+ func_tag = UP_FUNC_REALSERVER_DISCONNECT;
1685+ goto up_thread_realserver_send_out;
1686+ }
1687+ for (int i = 0; i < ret_fds; ++i) {
1688+ if (up_realserver_events[i].data.fd == event.data.fd) {
1689+ if (up_realserver_events[i].events & EPOLLOUT) {
1690+ goto up_thread_realserver_send_out;
1691+ } else if (up_realserver_events[i].events & EPOLLHUP) {
1692+ func_tag = UP_FUNC_REALSERVER_DISCONNECT;
1693+ goto up_thread_realserver_send_out;
1694+ }
1695+ }
1696+ }
1697+ boost::format formatter("up_thread_realserver_send: unknown file descriptor's event: %s");
1698+ formatter % strerror(errno);
1699+ Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
1700+ func_tag = UP_FUNC_REALSERVER_DISCONNECT;
1701+ } else if (ec == boost::asio::error::eof) {
1702+ func_tag = UP_FUNC_REALSERVER_DISCONNECT;
17561703 } else {
1704+ boost::format formatter("Thread ID[%d] realserver write error: %s");
1705+ formatter % boost::this_thread::get_id() % ec.message();
1706+ Logger::putLogError(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
17571707 func_tag = UP_FUNC_REALSERVER_DISCONNECT;
17581708 }
17591709 }
17601710
1711+up_thread_realserver_send_out:
17611712 up_thread_next_call_function = up_thread_function_array[func_tag];
1762-
17631713 if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
17641714 boost::format formatter("Thread ID[%d] FUNC OUT up_thread_realserver_send: NEXT_FUNC[%s]");
17651715 formatter % boost::this_thread::get_id() % func_tag_to_string(func_tag);
17661716 Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
17671717 }
1768-
17691718 }
17701719
17711720 //! up thread raise module event of handle_realserver_select
@@ -2659,6 +2608,16 @@ void tcp_session::down_thread_realserver_receive(const TCP_PROCESS_TYPE_TAG proc
26592608 Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
26602609 }
26612610
2611+ down_thread_data_dest_side.initialize();
2612+ boost::array<char, MAX_BUFFER_SIZE>& data_buff = down_thread_data_dest_side.get_data();
2613+ boost::system::error_code ec;
2614+ size_t recv_size;
2615+ DOWN_THREAD_FUNC_TYPE_TAG func_tag = DOWN_FUNC_REALSERVER_RECEIVE;
2616+ struct epoll_event event;
2617+ int ret_fds;
2618+ endpoint server_endpoint;
2619+ std::list<socket_element>::iterator list_end;
2620+
26622621 if (down_thread_receive_realserver_socket_list.empty()) {
26632622 if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
26642623 boost::format formatter("Thread ID[%d] FUNC OUT down_thread_realserver_receive");
@@ -2669,10 +2628,8 @@ void tcp_session::down_thread_realserver_receive(const TCP_PROCESS_TYPE_TAG proc
26692628 if (!realserver_connect_status) {
26702629 to_time(LOCKTIMEOUT, xt);
26712630 realserver_connect_cond.timed_wait(lock, xt);
2672- //realserver_connect_cond.wait(lock);
26732631 }
2674- down_thread_next_call_function = down_thread_function_array[DOWN_FUNC_REALSERVER_RECEIVE];
2675- return;
2632+ goto down_thread_realserver_receive_no_socket_out;
26762633 }
26772634
26782635 if (unlikely(0 < parent_service.get_wait_downstream())) {
@@ -2684,81 +2641,10 @@ void tcp_session::down_thread_realserver_receive(const TCP_PROCESS_TYPE_TAG proc
26842641 Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 42, buf.str(), __FILE__, __LINE__);
26852642 }
26862643 //----Debug log----------------------------------------------------------------------
2687- return;
2688- }
2689- down_thread_data_dest_side.initialize();
2690- boost::array<char, MAX_BUFFER_SIZE>& data_buff = down_thread_data_dest_side.get_data();
2691- boost::system::error_code ec;
2692- size_t recv_size;
2693- DOWN_THREAD_FUNC_TYPE_TAG func_tag;
2694-
2695- struct epoll_event event;
2696- event.data.fd = down_thread_current_receive_realserver_socket->second->get_socket().native();
2697- if (is_epoll_edge_trigger) {
2698- event.events = EPOLLIN | EPOLLHUP | EPOLLET;
2699- } else {
2700- event.events = EPOLLIN | EPOLLHUP;
2701- }
2702- bool add_flag = false;
2703- if (!down_realserver_epollfd_registered) {
2704- if (epoll_ctl(down_realserver_epollfd, EPOLL_CTL_ADD, event.data.fd, &event) < 0) {
2705- std::stringstream buf;
2706- buf << "down_thread_realserver_receive: epoll_ctl EPOLL_CTL_ADD error: " << strerror(errno);
2707- Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
2708- boost::this_thread::yield();
2709- return;
2710- }
2711- down_realserver_epollfd_registered = true;
2712- add_flag = true;
2713- }
2714-
2715- if (is_epoll_edge_trigger && (!add_flag)) {
2716- if (epoll_ctl(down_realserver_epollfd, EPOLL_CTL_MOD, event.data.fd, &event) < 0) {
2717- std::stringstream buf;
2718- buf << "down_thread_realserver_receive: epoll_ctl EPOLL_CTL_MOD error: " << strerror(errno);
2719- Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
2720- boost::this_thread::yield();
2721- return;
2722- }
2723- }
2724-
2725- int ret_fds = epoll_wait(down_realserver_epollfd, down_realserver_events, EVENT_NUM, epoll_timeout);
2726- if (ret_fds <= 0) {
2727- if (ret_fds == 0) {
2728- //----Debug log----------------------------------------------------------------------
2729- if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
2730- boost::format formatter("down_thread_realserver_receive: epoll_wait timeout %d msec.");
2731- formatter % epoll_timeout;
2732- Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
2733- }
2734- //----Debug log----------------------------------------------------------------------
2735- down_thread_next_call_function = down_thread_function_array[DOWN_FUNC_REALSERVER_RECEIVE];
2736- return;
2737- } else {
2738- boost::format formatter("down_thread_realserver_receive: epoll_wait error: %d");
2739- formatter % strerror(errno);
2740- Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
2741- down_thread_next_call_function = down_thread_function_array[DOWN_FUNC_REALSERVER_DISCONNECT];
2742- return;
2743- }
2644+ goto down_thread_realserver_receive_out;
27442645 }
27452646
2746- for (int i = 0; i < ret_fds; ++i) {
2747- if (down_realserver_events[i].data.fd == event.data.fd) {
2748- if (down_realserver_events[i].events & EPOLLIN) {
2749- break;
2750- } else if (down_realserver_events[i].events & EPOLLHUP) {
2751- down_thread_next_call_function = down_thread_function_array[DOWN_FUNC_REALSERVER_DISCONNECT];
2752- if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
2753- boost::format formatter("Thread ID[%d] FUNC OUT down_thread_realserver_receive: EPOLL_HUP");
2754- formatter % boost::this_thread::get_id();
2755- }
2756- return;
2757- }
2758- }
2759- }
2760-
2761- endpoint server_endpoint = down_thread_current_receive_realserver_socket->first;
2647+ server_endpoint = down_thread_current_receive_realserver_socket->first;
27622648 down_thread_data_dest_side.set_endpoint(server_endpoint);
27632649
27642650 recv_size = down_thread_current_receive_realserver_socket->second->read_some(boost::asio::buffer(data_buff, MAX_BUFFER_SIZE), ec);
@@ -2779,25 +2665,68 @@ void tcp_session::down_thread_realserver_receive(const TCP_PROCESS_TYPE_TAG proc
27792665
27802666 std::map<protocol_module_base::EVENT_TAG, DOWN_THREAD_FUNC_TYPE_TAG>::iterator func_type = down_thread_module_event_map.find(module_event);
27812667 func_tag = func_type->second;
2782- } else {
2783- func_tag = DOWN_FUNC_REALSERVER_RECEIVE;
2784- //boost::this_thread::yield();
27852668 }
27862669 } else {
27872670 if (ec == boost::asio::error::try_again) {
2788- func_tag = DOWN_FUNC_REALSERVER_RECEIVE;
2789- //boost::this_thread::yield();
2671+ // epoll wait
2672+ event.data.fd = down_thread_current_receive_realserver_socket->second->get_socket().native();
2673+ if (!down_realserver_epollfd_registered) {
2674+ if (is_epoll_edge_trigger) {
2675+ event.events = EPOLLIN | EPOLLHUP | EPOLLET;
2676+ } else {
2677+ event.events = EPOLLIN | EPOLLHUP;
2678+ }
2679+ if (epoll_ctl(down_realserver_epollfd, EPOLL_CTL_ADD, event.data.fd, &event) < 0) {
2680+ std::stringstream buf;
2681+ buf << "down_thread_realserver_receive: epoll_ctl EPOLL_CTL_ADD error: " << strerror(errno);
2682+ Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
2683+ goto down_thread_realserver_receive_out;
2684+ }
2685+ down_realserver_epollfd_registered = true;
2686+ }
2687+ ret_fds = epoll_wait(down_realserver_epollfd, down_realserver_events, EVENT_NUM, epoll_timeout);
2688+ if (ret_fds == 0) {
2689+ goto down_thread_realserver_receive_out; // epoll timeout
2690+ } else if (ret_fds < 0) {
2691+ boost::format formatter("down_thread_realserver_receive: epoll_wait error: %d");
2692+ formatter % strerror(errno);
2693+ Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
2694+ func_tag = DOWN_FUNC_REALSERVER_DISCONNECT;
2695+ goto down_thread_realserver_receive_out;
2696+ }
2697+ for (int i = 0; i < ret_fds; ++i) {
2698+ if (down_realserver_events[i].data.fd == event.data.fd) {
2699+ if (down_realserver_events[i].events & EPOLLIN) {
2700+ goto down_thread_realserver_receive_out;
2701+ } else if (down_realserver_events[i].events & EPOLLHUP) {
2702+ func_tag = DOWN_FUNC_REALSERVER_DISCONNECT;
2703+ goto down_thread_realserver_receive_out;
2704+ }
2705+ }
2706+ }
2707+ boost::format formatter("down_thread_realserver_receive: unknown file descriptor's event: %s");
2708+ formatter % strerror(errno);
2709+ Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
2710+ func_tag = DOWN_FUNC_REALSERVER_DISCONNECT;
2711+ } else if (ec == boost::asio::error::eof) {
2712+ func_tag = DOWN_FUNC_REALSERVER_DISCONNECT;
27902713 } else {
2714+ boost::format formatter("Thread ID[%d] realserver read error: %s");
2715+ formatter % boost::this_thread::get_id() % ec.message();
2716+ Logger::putLogError(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
27912717 func_tag = DOWN_FUNC_REALSERVER_DISCONNECT;
27922718 }
27932719 }
27942720
2795- down_thread_function_pair func = down_thread_function_array[func_tag];
2721+down_thread_realserver_receive_out:
27962722 down_thread_current_receive_realserver_socket++;
2797- std::list<socket_element>::iterator list_end = down_thread_receive_realserver_socket_list.end();
2723+ list_end = down_thread_receive_realserver_socket_list.end();
27982724 if (down_thread_current_receive_realserver_socket == list_end) {
27992725 down_thread_current_receive_realserver_socket = down_thread_receive_realserver_socket_list.begin();
28002726 }
2727+
2728+down_thread_realserver_receive_no_socket_out:
2729+ down_thread_function_pair func = down_thread_function_array[func_tag];
28012730 down_thread_next_call_function = func;
28022731
28032732 if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
@@ -3004,124 +2933,91 @@ void tcp_session::down_thread_client_send(const TCP_PROCESS_TYPE_TAG process_typ
30042933 std::size_t data_size = down_thread_data_client_side.get_size();
30052934 std::size_t send_data_size = down_thread_data_client_side.get_send_size();
30062935 std::size_t send_size;
3007- DOWN_THREAD_FUNC_TYPE_TAG func_tag;
3008-
2936+ DOWN_THREAD_FUNC_TYPE_TAG func_tag = DOWN_FUNC_CLIENT_SEND;
30092937 struct epoll_event event;
3010- event.data.fd = !ssl_flag ? client_socket.get_socket().native()
3011- : client_ssl_socket.get_socket().lowest_layer().native();
2938+ int ret_fds;
30122939
3013- if (is_epoll_edge_trigger) {
3014- event.events = EPOLLOUT | EPOLLHUP | EPOLLET;
3015- } else {
3016- event.events = EPOLLOUT | EPOLLHUP;
3017- }
3018- bool add_flag = false;
3019- if (!down_client_epollfd_registered) {
3020- if (epoll_ctl(down_client_epollfd, EPOLL_CTL_ADD, event.data.fd, &event) < 0) {
3021- std::stringstream buf;
3022- buf << "down_thread_client_send: epoll_ctl EPOLL_CTL_ADD error: ";
3023- buf << strerror(errno);
3024- Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
3025- boost::this_thread::yield();
3026- return;
2940+ send_size = !ssl_flag ? client_socket.write_some(
2941+ boost::asio::buffer(
2942+ data_buff.data() + send_data_size,
2943+ data_size - send_data_size),
2944+ ec)
2945+ : client_ssl_socket.write_some(
2946+ boost::asio::buffer(
2947+ data_buff.data() + send_data_size,
2948+ data_size - send_data_size),
2949+ ec);
2950+ if (!ec) {
2951+ send_data_size += send_size;
2952+ down_thread_data_client_side.set_send_size(send_data_size);
2953+ parent_service.update_down_send_size(send_size);
2954+ //----Debug log----------------------------------------------------------------------
2955+ if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
2956+ boost::format formatter("Thread ID[%d] down_thread_client_send send data size[%d] for [%d]");
2957+ formatter % boost::this_thread::get_id() % send_size % client_endpoint;
2958+ Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 45, formatter.str(), __FILE__, __LINE__);
30272959 }
3028- down_client_epollfd_registered = true;
3029- add_flag = true;
3030- }
3031-
3032- while (true) {
3033- {
3034- rd_scoped_lock scoped_lock(exit_flag_update_mutex);
3035- if (unlikely(exit_flag)) {
3036- func_tag = DOWN_FUNC_EXIT;
3037- break;
3038- }
2960+ //----Debug log----------------------------------------------------------------------
2961+ if (data_size > send_data_size) {
2962+ goto down_thread_client_send_out;
2963+ } else {
2964+ protocol_module_base::EVENT_TAG module_event = protocol_module->handle_client_send(down_thread_id);
2965+ std::map<protocol_module_base::EVENT_TAG, DOWN_THREAD_FUNC_TYPE_TAG>::iterator func_type = down_thread_module_event_map.find(module_event);
2966+ func_tag = func_type->second;
2967+ goto down_thread_client_send_out;
30392968 }
3040-
3041- if (is_epoll_edge_trigger && (!add_flag)) {
3042- if (epoll_ctl(down_client_epollfd, EPOLL_CTL_MOD, event.data.fd, &event) < 0) {
3043- std::stringstream buf;
3044- buf << "down_thread_client_send: epoll_ctl EPOLL_CTL_MOD error: ";
3045- buf << strerror(errno);
3046- Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
3047- boost::this_thread::yield();
3048- return;
2969+ } else {
2970+ if (ec == boost::asio::error::try_again) {
2971+ event.data.fd = !ssl_flag ? client_socket.get_socket().native()
2972+ : client_ssl_socket.get_socket().lowest_layer().native();
2973+ if (!down_client_epollfd_registered) {
2974+ if (is_epoll_edge_trigger) {
2975+ event.events = EPOLLOUT | EPOLLHUP | EPOLLET;
2976+ } else {
2977+ event.events = EPOLLOUT | EPOLLHUP;
2978+ }
2979+ if (epoll_ctl(down_client_epollfd, EPOLL_CTL_ADD, event.data.fd, &event) < 0) {
2980+ std::stringstream buf;
2981+ buf << "down_thread_client_send: epoll_ctl EPOLL_CTL_ADD error: ";
2982+ buf << strerror(errno);
2983+ Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
2984+ func_tag = DOWN_FUNC_CLIENT_DISCONNECT;
2985+ goto down_thread_client_send_out;
2986+ }
2987+ down_client_epollfd_registered = true;
30492988 }
3050- }
3051-
3052- int ret_fds = epoll_wait(down_client_epollfd, down_client_events, EVENT_NUM, epoll_timeout);
3053- if (ret_fds <= 0) {
2989+ ret_fds = epoll_wait(down_client_epollfd, down_client_events, EVENT_NUM, epoll_timeout);
30542990 if (ret_fds == 0) {
3055- std::stringstream buf;
3056- buf << "down_thread_client_send: epoll_wait timeout ";
3057- buf << epoll_timeout;
3058- buf << "mS";
3059- Logger::putLogInfo(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
3060- } else {
3061- std::stringstream buf;
3062- buf << "down_thread_client_send: epoll_wait error: ";
3063- buf << strerror(errno);
3064- Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, buf.str(), __FILE__, __LINE__);
2991+ goto down_thread_client_send_out; // epoll timeout
2992+ } else if (ret_fds < 0) {
2993+ func_tag = DOWN_FUNC_CLIENT_DISCONNECT;
2994+ goto down_thread_client_send_out;
30652995 }
3066- down_thread_next_call_function = down_thread_function_array[DOWN_FUNC_CLIENT_DISCONNECT];
3067- return;
3068- }
3069-
3070- for (int i = 0; i < ret_fds; ++i) {
3071- if (down_client_events[i].data.fd == event.data.fd) {
3072- if (down_client_events[i].events & EPOLLOUT) {
3073- break;
3074- } else if (down_client_events[i].events & EPOLLHUP) {
3075- down_thread_next_call_function = down_thread_function_array[DOWN_FUNC_CLIENT_DISCONNECT];
3076- return;
2996+ for (int i = 0; i < ret_fds; ++i) {
2997+ if (down_client_events[i].data.fd == event.data.fd) {
2998+ if (down_client_events[i].events & EPOLLOUT) {
2999+ goto down_thread_client_send_out;
3000+ } else if (down_client_events[i].events & EPOLLHUP) {
3001+ func_tag = DOWN_FUNC_CLIENT_DISCONNECT;
3002+ goto down_thread_client_send_out;
3003+ }
30773004 }
30783005 }
3079- }
3080-
3081- send_size = !ssl_flag ? client_socket.write_some(
3082- boost::asio::buffer(
3083- data_buff.data() + send_data_size,
3084- data_size - send_data_size),
3085- ec)
3086- : client_ssl_socket.write_some(
3087- boost::asio::buffer(
3088- data_buff.data() + send_data_size,
3089- data_size - send_data_size),
3090- ec);
3091- if (!ec) {
3092- send_data_size += send_size;
3093- down_thread_data_client_side.set_send_size(send_data_size);
3094- parent_service.update_down_send_size(send_size);
3095- //----Debug log----------------------------------------------------------------------
3096- if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
3097- endpoint client_endpoint // XXX redefined???
3098- = !ssl_flag ? client_socket.get_socket().lowest_layer().remote_endpoint(ec)
3099- : client_ssl_socket.get_socket().lowest_layer().remote_endpoint(ec);
3100- boost::format formatter("Thread ID[%d] down_thread_client_send send data size[%d] for [%d]");
3101- formatter % boost::this_thread::get_id() % send_size % client_endpoint;
3102- Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 45, formatter.str(), __FILE__, __LINE__);
3103- }
3104- //----Debug log----------------------------------------------------------------------
3105- if (data_size > send_data_size) {
3106- func_tag = DOWN_FUNC_CLIENT_SEND;
3107- //down_send_wait.reset();
3108- } else {
3109- protocol_module_base::EVENT_TAG module_event = protocol_module->handle_client_send(down_thread_id);
3110- std::map<protocol_module_base::EVENT_TAG, DOWN_THREAD_FUNC_TYPE_TAG>::iterator func_type = down_thread_module_event_map.find(module_event);
3111- func_tag = func_type->second;
3112- }
3113- break;
3006+ boost::format formatter("down_thread_client_send: unknown file descriptor's event: %s");
3007+ formatter % strerror(errno);
3008+ Logger::putLogWarn(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
3009+ func_tag = DOWN_FUNC_CLIENT_DISCONNECT;
3010+ } else if (ec == boost::asio::error::eof) {
3011+ func_tag = DOWN_FUNC_CLIENT_DISCONNECT;
31143012 } else {
3115- if (ec == boost::asio::error::try_again) {
3116- //func_tag = DOWN_FUNC_CLIENT_SEND;
3117- //boost::this_thread::yield();
3118- } else {
3119- func_tag = DOWN_FUNC_CLIENT_DISCONNECT;
3120- break;
3121- }
3013+ boost::format formatter("Thread ID[%d] client write error: %s");
3014+ formatter % boost::this_thread::get_id() % ec.message();
3015+ Logger::putLogError(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__);
3016+ func_tag = DOWN_FUNC_CLIENT_DISCONNECT;
31223017 }
31233018 }
31243019
3020+down_thread_client_send_out:
31253021 down_thread_next_call_function = down_thread_function_array[func_tag];
31263022
31273023 if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) {
--- a/l7vsd/src/virtualservice_tcp.cpp
+++ b/l7vsd/src/virtualservice_tcp.cpp
@@ -1721,11 +1721,11 @@ void l7vs::virtualservice_tcp::release_session(const tcp_session *session_ptr)
17211721
17221722 session_thread_control *stc_ptr = active_sessions.find(session_ptr);
17231723 if (unlikely(NULL == stc_ptr)) {
1724+ boost::format fmt("session release fail: "
1725+ "active_sessions.find( const tcp_session* session_ptr = %d )");
1726+ fmt % session_ptr;
1727+ Logger::putLogError(LOG_CAT_L7VSD_VIRTUALSERVICE, /*XXX*/999, fmt.str(), __FILE__, __LINE__);
17241728 if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_VIRTUALSERVICE))) {
1725- boost::format fmt("session release fail: "
1726- "active_sessions.find( const tcp_session* session_ptr = %d )");
1727- fmt % session_ptr;
1728- Logger::putLogDebug(LOG_CAT_L7VSD_VIRTUALSERVICE, 87, fmt.str(), __FILE__, __LINE__);
17291729 Logger::putLogDebug(LOG_CAT_L7VSD_VIRTUALSERVICE, 88, "out_function: "
17301730 "void virtualservice_tcp::release_session( "
17311731 "const boost::thread::id thread_id )", __FILE__, __LINE__);