Skip to content

Commit

Permalink
Merge branch 'master' of gitee.com:edisenwang/TarsCpp
Browse files Browse the repository at this point in the history
  • Loading branch information
edisenwangK committed Nov 21, 2024
2 parents fce0ec6 + 26d99a8 commit 28754b5
Show file tree
Hide file tree
Showing 175 changed files with 4,349 additions and 2,795 deletions.
28 changes: 28 additions & 0 deletions Changelist-3.x.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
# v3.0.20 20240408
## en
- fix: tc_ex using namespace std outside tars
- fix: tc_port SigInfo use NoDestroyLifetime TC_Singleton
- fix: RemoteTimeLogger not init twice
- fix: free applicationCommunicator when application terminate
- fix: servantprx/adapterprx tars_set_push_callback nullptr protected
- fix: unit-test use tarsmock
- fix: fix remote log sync bug when log size too big
- fix: communicator _schedCommunicatorEpoll create use array
- fix: tc_port exec out buff size limit
- feat: tc_port add check pid alive
- feat: tc_option parseString use static
- feat: tc_port kill add return value
- feat: tc_port add freopen
- feat: epoll server destroyApp not call bug and destroyApp log
- feat: add tarsmock to simulate tars framework
- feat: tc_port add getCommandLine/getPidsByCmdline
- feat: tc_socket: getLocalHosts support withLoopIp
- feat: tars-tools.cmake add CMAKE_CXX_FLAGS_RELEASE&CMAKE_CXX_FLAGS_DEBUG
- feat: unit-test support TARS_SHARED_PTR
- feat: support build_with_std_shared_ptr for python
- feat: Application add getRemoteConfig
- feat: tc_mysql support mysql 8.0
- feat: EndpointInfo add vectorEndpointFToStr/strToVectorEndpointF/toNodeEndpointF to support multi network interfaces
- feat: fix tc_socket getLocalHosts support ipv4
- feat: EndpointInfo add toEndpointFs

# v3.0.19 20240202

## en
Expand Down
4 changes: 0 additions & 4 deletions cmake/BuildTarsCpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ macro(build_tars_server MODULE DEPS)
target_link_libraries(${MODULE} ${LIB_HTTP2} ${LIB_PROTOBUF})
endif()

# if(TARS_GPERF)
# target_link_libraries(${MODULE} ${LIB_GPERF})
# endif(TARS_GPERF)

SET(MODULE-TGZ "${CMAKE_BINARY_DIR}/${MODULE}.tgz")
SET(RUN_DEPLOY_COMMAND_FILE "${PROJECT_BINARY_DIR}/run-deploy-${MODULE}.cmake")
FILE(WRITE ${RUN_DEPLOY_COMMAND_FILE} "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/deploy/${MODULE})\n")
Expand Down
4 changes: 3 additions & 1 deletion cmake/Common.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


set(TARS_VERSION "3.0.19")
set(TARS_VERSION "3.0.20")
add_definitions(-DTARS_VERSION="${TARS_VERSION}")

set(CMAKE_VERBOSE_MAKEFILE off)
Expand Down Expand Up @@ -30,6 +30,7 @@ foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
endforeach()

option(ONLY_LIB "option for only lib" ON)
option(ENABLE_SHARED "option for enable shared library" OFF)

# option(TARS_OPENTRACKING "option for open tracking" OFF)

Expand Down Expand Up @@ -130,5 +131,6 @@ message("TARS2CPP: ${TARS2CPP}")
#message("TARS_OPENTRACKING: ${TARS_OPENTRACKING}")
message("ONLY_LIB: ${ONLY_LIB}" )
message("TARS_STD_SHARED_PTR: ${TARS_STD_SHARED_PTR}" )
message("ENABLE_SHARED: ${ENABLE_SHARED}" )
#-------------------------------------------------------------

98 changes: 23 additions & 75 deletions cmake/Thirdparty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,6 @@ endif(UNIX)
option(TARS_SSL "option for ssl" OFF)
option(TARS_HTTP2 "option for http2" OFF)
option(TARS_PROTOBUF "option for protocol" OFF)
#option(TARS_GPERF "option for gperf" OFF)

#IF(UNIX)
# FIND_PACKAGE(ZLIB)
# IF(NOT ZLIB_FOUND)
# SET(ERRORMSG "zlib library not found. Please install appropriate package, remove CMakeCache.txt and rerun cmake.")
# IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
# SET(ERRORMSG ${ERRORMSG} "On Debian/Ubuntu, package name is zlib1g-dev(apt-get install zlib1g-dev), on Redhat/Centos and derivates it is zlib-devel (yum install zlib-devel).")
# ENDIF()
# MESSAGE(FATAL_ERROR ${ERRORMSG})
# ENDIF()
#
#ENDIF(UNIX)

if (TARS_MYSQL)
add_definitions(-DTARS_MYSQL=1)
Expand All @@ -30,10 +17,6 @@ if (TARS_GZIP)
add_definitions(-DTARS_GZIP=1)
endif ()

#if (TARS_GPERF)
# add_definitions(-DTARS_GPERF=1)
#endif ()

if (TARS_SSL)
add_definitions(-DTARS_SSL=1)
endif ()
Expand All @@ -57,51 +40,12 @@ set(LIB_SSL)
set(LIB_CRYPTO)
set(LIB_PROTOBUF)
set(LIB_GTEST)
#set(LIB_GPERF)
#set(LIB_TCMALLOC_PROFILER)
#set(LIB_TCMALLOC_MINIMAL)

#-------------------------------------------------------------

add_custom_target(thirdparty)

include(ExternalProject)
#
#if (TARS_GPERF)
#
# set(GPERF_DIR_INC "${THIRDPARTY_PATH}/gperf/include")
# set(GRPEF_DIR_LIB "${THIRDPARTY_PATH}/gperf/lib")
# include_directories(${GPERF_DIR_INC})
# link_directories(${GRPEF_DIR_LIB})
#
# if (UNIX)
# set(LIB_GPERF "profiler")
# set(LIB_TCMALLOC_PROFILER "tcmalloc_and_profiler")
# set(LIB_TCMALLOC_MINIMAL "tcmalloc_and_minimal")
#
# ExternalProject_Add(ADD_${LIB_GPERF}
# URL https://tars-thirdpart-1300910346.cos.ap-guangzhou.myqcloud.com//src/gperftools-2.7.tar.gz
# DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download
# PREFIX ${CMAKE_BINARY_DIR}
# INSTALL_DIR ${CMAKE_SOURCE_DIR}
# CONFIGURE_COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/src/gperf --disable-shared --disable-debugalloc
# SOURCE_DIR ${CMAKE_BINARY_DIR}/src/gperf-lib
# BUILD_IN_SOURCE 1
# BUILD_COMMAND make
# URL_MD5 c6a852a817e9160c79bdb2d3101b4601
# )
#
# add_dependencies(thirdparty ADD_${LIB_GPERF})
#
# INSTALL(FILES ${CMAKE_BINARY_DIR}/src/gperf/bin/pprof
# PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ
# DESTINATION thirdparty/bin/)
# INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/gperf/lib DESTINATION thirdparty)
# INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/gperf/include/gperftools DESTINATION thirdparty/include)
#
# endif (UNIX)
#
#endif (TARS_GPERF)


if(WIN32)

Expand All @@ -113,7 +57,7 @@ if(WIN32)
CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/curl
SOURCE_DIR ${CMAKE_BINARY_DIR}/src/curl-lib
BUILD_IN_SOURCE 1
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config release
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config release -- /maxcpucount:4
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config release --target install
URL_MD5 b9bb5e11d579425154a9f97ed44be9b8
)
Expand All @@ -138,7 +82,7 @@ if (WIN32)
CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/gtest -A x64 -Dgtest_force_shared_crt=on -DBUILD_GMOCK=OFF
SOURCE_DIR ${CMAKE_BINARY_DIR}/src/gtest-lib
BUILD_IN_SOURCE 1
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE}
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} -- /maxcpucount:4
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} --target install
URL_MD5 82358affdd7ab94854c8ee73a180fc53
)
Expand All @@ -153,7 +97,7 @@ else()
CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/gtest -DBUILD_GMOCK=OFF -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
SOURCE_DIR ${CMAKE_BINARY_DIR}/src/gtest-lib
BUILD_IN_SOURCE 1
BUILD_COMMAND make
BUILD_COMMAND make -j4
URL_MD5 6f26d634fa9cac718263c2df20df21a4
)
endif()
Expand Down Expand Up @@ -182,7 +126,7 @@ if (TARS_PROTOBUF)
CONFIGURE_COMMAND ${CMAKE_COMMAND} cmake -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/protobuf -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
SOURCE_DIR ${CMAKE_BINARY_DIR}/src/protobuf-lib
BUILD_IN_SOURCE 1
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config release
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config release -- /maxcpucount:4
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config release --target install
URL_MD5 fb59398329002c98d4d92238324c4187
)
Expand All @@ -195,10 +139,10 @@ if (TARS_PROTOBUF)
DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download
PREFIX ${CMAKE_BINARY_DIR}
INSTALL_DIR ${CMAKE_SOURCE_DIR}
CONFIGURE_COMMAND ${CMAKE_COMMAND} cmake -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/protobuf -DBUILD_SHARED_LIBS=OFF -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
CONFIGURE_COMMAND ${CMAKE_COMMAND} cmake -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/protobuf -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
SOURCE_DIR ${CMAKE_BINARY_DIR}/src/protobuf-lib
BUILD_IN_SOURCE 1
BUILD_COMMAND make
BUILD_COMMAND make -j4
URL_MD5 fb59398329002c98d4d92238324c4187
)

Expand Down Expand Up @@ -243,11 +187,11 @@ if (TARS_SSL)
DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download
PREFIX ${CMAKE_BINARY_DIR}
INSTALL_DIR ${CMAKE_SOURCE_DIR}
CONFIGURE_COMMAND ./config --prefix=${CMAKE_BINARY_DIR}/src/openssl --openssldir=ssl no-shared
CONFIGURE_COMMAND ./config --prefix=${CMAKE_BINARY_DIR}/src/openssl --openssldir=ssl
SOURCE_DIR ${CMAKE_BINARY_DIR}/src/openssl-lib
BUILD_IN_SOURCE 1
BUILD_COMMAND make
INSTALL_COMMAND make install_sw
INSTALL_COMMAND make install_sw -j4
URL_MD5 ac0d4387f3ba0ad741b0580dd45f6ff3
)

Expand Down Expand Up @@ -275,7 +219,7 @@ if (TARS_MYSQL)
CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/mysql -DBUILD_CONFIG=mysql_release -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci
SOURCE_DIR ${CMAKE_BINARY_DIR}/src/mysql-lib
BUILD_IN_SOURCE 1
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config release
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config release -- /maxcpucount:4
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config release --target install
URL_MD5 bad636fe9bcc9bb62e3f5b784495a9b5
)
Expand All @@ -288,10 +232,10 @@ if (TARS_MYSQL)
DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download
PREFIX ${CMAKE_BINARY_DIR}
INSTALL_DIR ${CMAKE_SOURCE_DIR}
CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/mysql -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DDISABLE_SHARED=1 -DSTACK_DIRECTION=1 -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/mysql -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DSTACK_DIRECTION=1 -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
SOURCE_DIR ${CMAKE_BINARY_DIR}/src/mysql-lib
BUILD_IN_SOURCE 1
BUILD_COMMAND make mysqlclient
BUILD_COMMAND make mysqlclient -j4
URL_MD5 3578d736b9d493eae076a67e3ed473eb
)

Expand All @@ -311,7 +255,7 @@ if (TARS_GZIP)
link_directories(${GZIP_DIR_LIB})

if (WIN32)
set(LIB_GZIP "libz")
set(LIB_GZIP "zlib")

ExternalProject_Add(ADD_${LIB_GZIP}
URL http://cdn.tarsyun.com/src/zlib-1.2.11.tar.gz
Expand All @@ -321,7 +265,7 @@ if (TARS_GZIP)
CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/zlib
SOURCE_DIR ${CMAKE_BINARY_DIR}/src/zlib-lib
BUILD_IN_SOURCE 1
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config release
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config release -- /maxcpucount:4
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config release --target install
URL_MD5 1c9f62f0778697a09d36121ead88e08e
)
Expand All @@ -337,7 +281,7 @@ if (TARS_GZIP)
CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/zlib -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
SOURCE_DIR ${CMAKE_BINARY_DIR}/src/zlib-lib
BUILD_IN_SOURCE 1
BUILD_COMMAND make
BUILD_COMMAND make -j4
URL_MD5 1c9f62f0778697a09d36121ead88e08e
)

Expand All @@ -358,18 +302,22 @@ if (TARS_HTTP2)
link_directories(${NGHTTP2_DIR_LIB})
link_directories(${NGHTTP2_DIR_LIB64})

set(LIB_HTTP2 "nghttp2_static")
if(ENABLE_SHARED)
set(LIB_HTTP2 "nghttp2")
else()
set(LIB_HTTP2 "nghttp2_static")
endif()

if (WIN32)
ExternalProject_Add(ADD_${LIB_HTTP2}
URL http://cdn.tarsyun.com/src/nghttp2-1.40.0.tar.gz
DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download
PREFIX ${CMAKE_BINARY_DIR}
INSTALL_DIR ${CMAKE_SOURCE_DIR}
CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/nghttp2 -DENABLE_LIB_ONLY=ON -DENABLE_STATIC_LIB=ON
CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/nghttp2 -DENABLE_LIB_ONLY=ON
SOURCE_DIR ${CMAKE_BINARY_DIR}/src/nghttp2-lib
BUILD_IN_SOURCE 1
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config release
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config release -- /maxcpucount:4
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config release --target install
URL_MD5 5df375bbd532fcaa7cd4044b54b1188d
)
Expand All @@ -383,7 +331,7 @@ if (TARS_HTTP2)
CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/nghttp2 -DENABLE_LIB_ONLY=ON -DENABLE_STATIC_LIB=ON -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
SOURCE_DIR ${CMAKE_BINARY_DIR}/src/nghttp2-lib
BUILD_IN_SOURCE 1
BUILD_COMMAND make
BUILD_COMMAND make -j4
URL_MD5 5df375bbd532fcaa7cd4044b54b1188d
)

Expand Down
16 changes: 15 additions & 1 deletion mock/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@

include_directories(../)
file(GLOB_RECURSE SRC_FILES *.cpp)
add_library(tarsmock ${SRC_FILES})
add_library(tarsmock STATIC ${SRC_FILES})

add_dependencies(tarsmock tarsservant)

install(DIRECTORY . DESTINATION include/mock FILES_MATCHING PATTERN "*.h")

install(TARGETS tarsmock RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)

# if(ENABLE_SHARED)
# add_library(tarsmock_shared SHARED ${SRC_FILES})
# target_compile_definitions(tarsmock_shared PRIVATE SVT_USE_DLL UTIL_USE_DLL)
# target_link_libraries(tarsmock_shared tarsservant_shared tarsutil_shared)
# add_dependencies(tarsmock_shared tarsservant_shared)

# install(TARGETS tarsmock_shared RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)

# if (WIN32)
# install(FILES $<TARGET_PDB_FILE:tarsmock_shared> DESTINATION bin)
# endif()

# endif()
8 changes: 4 additions & 4 deletions mock/DbHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

static ObjectsCache _objectsCache;

CDbHandle::SetDivisionCache CDbHandle::_setDivisionCache;
std::map<int, CDbHandle::GroupPriorityEntry> CDbHandle::_mapGroupPriority;
std::mutex CDbHandle::_mutex;
static CDbHandle::SetDivisionCache _setDivisionCache;
static std::map<int, CDbHandle::GroupPriorityEntry> _mapGroupPriority;
static std::mutex _mutex;

//key-ip, value-组编号
map<string, int> CDbHandle::_groupIdMap;
map<string, int> _groupIdMap;
//key-group_name, value-组编号
//map<string, int> CDbHandle::_groupNameMap;

Expand Down
20 changes: 10 additions & 10 deletions mock/DbHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ typedef map<string, ObjectItem> ObjectsCache;
/**
* 数据库操作类
*/
class CDbHandle
class UTIL_DLL_API CDbHandle
{
private:
public:
struct GroupPriorityEntry
{
std::string sGroupID;
Expand Down Expand Up @@ -199,14 +199,14 @@ class CDbHandle

vector<EndpointF> getEpsByGroupId(const vector<EndpointF> & vecEps, const GroupUseSelect GroupSelect, const set<int> & setGroupID, ostringstream & os);

protected:
// protected:

static std::mutex _mutex;
//set划分缓存
static SetDivisionCache _setDivisionCache;
//优先级的序列
static std::map<int, GroupPriorityEntry> _mapGroupPriority;
//分组信息
static map<string,int> _groupIdMap;
// UTIL_DLL_API static std::mutex _mutex;
// //set划分缓存
// UTIL_DLL_API static SetDivisionCache _setDivisionCache;
// //优先级的序列
// UTIL_DLL_API static std::map<int, GroupPriorityEntry> _mapGroupPriority;
// //分组信息
// UTIL_DLL_API static map<string,int> _groupIdMap;
};

2 changes: 1 addition & 1 deletion mock/FrameworkServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using namespace tars;
extern vector<map<tars::StatMicMsgHead, tars::StatMicMsgBody>> _clientStatData;
extern vector<map<tars::StatMicMsgHead, tars::StatMicMsgBody>> _serverStatData;

class FrameworkServer : public Application, public TC_Thread
class UTIL_DLL_API FrameworkServer : public Application, public TC_Thread
{
public:
/**
Expand Down
2 changes: 0 additions & 2 deletions mock/LogImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,6 @@ void LogImp::logger(const string &app, const string &server, const string &file,

void LogImp::loggerbyInfo(const LogInfo & info,const vector<std::string> & buffer,tars::TarsCurrentPtr current)
{
LOG_CONSOLE_DEBUG << info.writeToJsonString() << endl;

TC_DayLogger &dl = g_globe.getLogger(info,current->getIp());

//记录日志
Expand Down
Loading

0 comments on commit 28754b5

Please sign in to comment.