From 7b0cc6f33ddb1700ed52512db8c8cac9c49113ff Mon Sep 17 00:00:00 2001 From: Apex Liu Date: Thu, 5 Dec 2019 09:36:59 +0800 Subject: [PATCH] .temp. --- common/libex/src/ex_thread.cpp | 2 +- server/tp_core/core/ts_http_rpc.cpp | 2 ++ server/tp_core/core/ts_session.cpp | 13 +++++++------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/common/libex/src/ex_thread.cpp b/common/libex/src/ex_thread.cpp index ff4fcf9..b40b38c 100644 --- a/common/libex/src/ex_thread.cpp +++ b/common/libex/src/ex_thread.cpp @@ -72,7 +72,7 @@ bool ExThreadBase::stop(void) { m_need_stop = true; _on_stop(); - EXLOGV("[thread] wait thread [%s] exit.\n", m_thread_name.c_str()); + EXLOGV("[thread] wait thread [%s] exit, thread-handle=0x%08x.\n", m_thread_name.c_str(), m_handle); #ifdef EX_OS_WIN32 if (m_handle) { diff --git a/server/tp_core/core/ts_http_rpc.cpp b/server/tp_core/core/ts_http_rpc.cpp index 4340e1d..e5feb0f 100644 --- a/server/tp_core/core/ts_http_rpc.cpp +++ b/server/tp_core/core/ts_http_rpc.cpp @@ -382,6 +382,7 @@ void TsHttpRpc::_rpc_func_request_session(const Json::Value& json_param, ex_astr if ((rv = ts_web_rpc_get_conn_info(conn_id, *info)) != TPE_OK) { _create_json_ret(buf, rv); + delete info; return; } @@ -392,6 +393,7 @@ void TsHttpRpc::_rpc_func_request_session(const Json::Value& json_param, ex_astr ex_astr sid; if (!g_session_mgr.request_session(sid, info)) { _create_json_ret(buf, TPE_FAILED); + delete info; return; } diff --git a/server/tp_core/core/ts_session.cpp b/server/tp_core/core/ts_session.cpp index deee94f..ae6ca97 100644 --- a/server/tp_core/core/ts_session.cpp +++ b/server/tp_core/core/ts_session.cpp @@ -1,4 +1,4 @@ -#include "ts_session.h" +#include "ts_session.h" #include "ts_env.h" #include @@ -13,6 +13,7 @@ TsSessionManager::TsSessionManager() : TsSessionManager::~TsSessionManager() { ts_connections::iterator it_conn = m_connections.begin(); for (; it_conn != m_connections.end(); ++it_conn) { + EXLOGD("[core] m_connections not clean: %s, %s\n", it_conn->first.c_str(), it_conn->second->acc_username.c_str()); delete it_conn->second; } m_connections.clear(); @@ -28,7 +29,7 @@ void TsSessionManager::_thread_loop(void) { } void TsSessionManager::_remove_expired_connect_info(void) { - // 15δӵconnect-infoᱻƳ + // 超过15秒未进行连接的connect-info会被移除 ExThreadSmartLock locker(m_lock); @@ -87,8 +88,8 @@ bool TsSessionManager::free_connect_info(const ex_astr &sid) { it->second->ref_count--; - // RDP˵ʱҪƳϢϵͳԴRDPͻڵһʱЭЭ̣ȻϻϿ֮һΣڶ֮ǰܻʾ֤Ϣûʱ䲻ܻᵼ³ʱ - // ˣǽüͣһʱ䣬öʱƳ + // 对于RDP来说,此时不要移除连接信息,系统自带RDP客户端在第一次连接时进行协议协商,然后马上会断开,之后立即重新连接一次(第二次连接之前可能会提示证书信息,如果用户长时间不操作,可能会导致超时)。 + // 因此,我们将其引用计数减低,并更新一下最后访问时间,让定时器来移除它。 if (it->second->protocol_type != TP_PROTOCOL_TYPE_RDP) { if (it->second->ref_count <= 0) { EXLOGD("[core] remove connection info, because all connections closed: %s\n", it->first.c_str()); @@ -99,7 +100,7 @@ bool TsSessionManager::free_connect_info(const ex_astr &sid) { } else { if (it->second->ref_count == 1) it->second->ref_count = 0; - it->second->ticket_start = ex_get_tick_count() + 45000; // ǽʱƶ45룬ûзRDPĵڶӣϢͻһӺ + it->second->ticket_start = ex_get_tick_count() + 45000; // 我们将时间向后移动45秒,这样如果没有发生RDP的第二次连接,这个连接信息就会在一分钟后被清除。 } @@ -133,7 +134,7 @@ bool TsSessionManager::request_session(ex_astr &sid, TS_CONNECT_INFO *info) { sid = _sid; if (info->protocol_type == TP_PROTOCOL_TYPE_RDP) { - info->ref_count = 1; // ΪRDP֮ǰܻкܳʱȷǷӡǷ֤飬Ժ׳ʱΪü+1ֹʱ + info->ref_count = 1; // 因为RDP连接之前可能会有很长时间用于确认是否连接、是否信任证书,所以很容易超时,我们认为将引用计数+1,防止因超时被清除。 char szTmp[8] = {0}; snprintf(szTmp, 8, "%02X", (unsigned char) (info->acc_username.length() + info->acc_secret.length())); sid += szTmp;