Skip to content

Commit

Permalink
Merge branch 'TarsCloud:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
edisenwangK authored Mar 20, 2024
2 parents 5f4b7ad + 37e4ec6 commit fce0ec6
Show file tree
Hide file tree
Showing 194 changed files with 7,245 additions and 5,062 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
servant/makefile/tars-tools.cmake
.idea
/cmake-build-debug-177
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ENDIF()
add_subdirectory(util)
add_subdirectory(tools)
add_subdirectory(servant)
add_subdirectory(mock)

IF (NOT ${ONLY_LIB})
add_subdirectory(examples)
Expand Down
38 changes: 38 additions & 0 deletions Changelist-3.x.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
# v3.0.19 20240202

## en
- fix: tars-tools.cmake in windows
- fix: tc_port fix forkExec bug
- fix: remote logger remove ServerConfig::Context
- fix: current not report one_way stat(useless)
- fix: StatReport interface, remove parameters not used
- fix: tc_option support parameter with ", like this: --test="abc"
- fix: When the server actively closes the connection, RPC may cause memory leak issues
- fix: push callback may crash
- fix: KeepAliveNodeFHelper no singleton
- fix: gzip compress coredump
- fix: PingCallback set servantPrx
- fix: remote config, when tarsconfig timeout not use local config file bug
- fix: tars-tools.cmake.in add: list(APPEND TARS_TOOL_FLAG "")
- fix: trace, no not depend ServerConfig
- fix: tars-tools.cmake set TARS_SSL/TARS_MYSQL/TARS_HTTP2 depends tarscpp compiler
- feat: modify xxx_fcontext name to avoid conflict with other co lib
- feat: rpc add time distr report
- feat: tc_port add getDiskInfo/getCpuLoad/getUPTime/getPidStartTime/getPidMemUsed/getCwd/kill and support mac/windows/linux
- feat: tc_port add closeAllFileDescriptors in linux/mac
- feat: tc_file add joinPaths/toAbsolute
- feat: Application first bind adminObj, then initialize, then bind other objs
- feat: EndpointInfo add toEndpointF
- feat: AdminF.tars add getPid
- feat: ServantHandle in servant use shared ptr
- feat: ClientConfig change to Communicator subclass, no global static object
- feat: ClientConfig add context, when call other core tars server with this context, node_name in context
- feat: add ApplicationCommunicator to support multi Appliations in one process
- feat: support master-slave mode in frameworkPro
- feat: Application add ServerBaseInfo in Application
- optimize: bind after initialize when Applicaion start
- optimize: RemoteConfig remove singleton
- optimize: loading local ip list cache
- optimize: AppCache only initialize once
- optimize: global rolllog only init once

# v3.0.18 20231106
### en
- fix: udp ipv6 bug
Expand Down
17 changes: 14 additions & 3 deletions cmake/Common.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


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

set(CMAKE_VERBOSE_MAKEFILE off)
Expand All @@ -11,6 +11,13 @@ IF (CMAKE_BUILD_TYPE STREQUAL "")
ENDIF()


# 设置一个选项,用于控制是否定义 TARS_STD_SHARED_PTR 宏
option(TARS_STD_SHARED_PTR "Use std::shared_ptr instead of tars::AutoPtr" OFF)
if(TARS_STD_SHARED_PTR)
add_definitions(-DTARS_STD_SHARED_PTR)
endif()


#编译的可执行程序输出目录
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand Down Expand Up @@ -83,8 +90,7 @@ IF (UNIX)

ELSEIF (WIN32)
set(PLATFORM "window")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /wd4101 /wd4244 /wd4996 /wd4091 /wd4503 /wd4819 /wd4200 /wd4800 /wd4267 /wd4251 /wd4275")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /wd4101 /wd4244 /wd4996 /wd4091 /wd4503 /wd4819 /wd4200 /wd4800 /wd4267 /wd4251 /wd4275 /bigobj")

SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
Expand All @@ -95,6 +101,10 @@ ELSEIF (WIN32)
SET(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /DEBUG")
SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /OPT:ICF /OPT:REF /DEBUG")

add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /ZI")

ELSE ()
MESSAGE(STATUS "================ ERROR: This platform is unsupported!!! ================")
ENDIF (UNIX)
Expand All @@ -119,5 +129,6 @@ message("BIN: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
message("TARS2CPP: ${TARS2CPP}")
#message("TARS_OPENTRACKING: ${TARS_OPENTRACKING}")
message("ONLY_LIB: ${ONLY_LIB}" )
message("TARS_STD_SHARED_PTR: ${TARS_STD_SHARED_PTR}" )
#-------------------------------------------------------------

4 changes: 2 additions & 2 deletions cmake/Thirdparty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ 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 -DBUILD_CONFIG=mysql_release
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
Expand All @@ -288,7 +288,7 @@ 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=utf8 -DDEFAULT_COLLATION=utf8_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 -DDISABLE_SHARED=1 -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
Expand Down
2 changes: 1 addition & 1 deletion examples/AuthDemo/Client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void asyncCall(int c)
//发起远程调用
for (int i = 0; i < c; ++i)
{
HelloPrxCallbackPtr p = new HelloCallback(t, i, c);
HelloPrxCallbackPtr p(new HelloCallback(t, i, c));

try
{
Expand Down
12 changes: 6 additions & 6 deletions examples/CoroutineDemo/BServer/BServantImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class AServantCoroCallback : public AServantCoroPrxCallback
int _iOut;
string _sOut;
};
typedef tars::TC_AutoPtr<AServantCoroCallback> AServantCoroCallbackPtr;
// typedef tars::TC_AutoPtr<AServantCoroCallback> AServantCoroCallbackPtr;

int BServantImp::test(tars::TarsCurrentPtr current) { return 0;}

Expand Down Expand Up @@ -111,21 +111,21 @@ tars::Int32 BServantImp::testCoroParallel(const std::string& sIn, std::string &s

int iIn = 5;

CoroParallelBasePtr sharedPtr = new CoroParallelBase(2);
CoroParallelBasePtr sharedPtr(new CoroParallelBase(2));

AServantCoroCallbackPtr cb1 = new AServantCoroCallback();
AServantCoroPrxCallbackPtr cb1(new AServantCoroCallback());
cb1->setCoroParallelBasePtr(sharedPtr);
_pPrx->coro_testInt(cb1, iIn);

AServantCoroCallbackPtr cb2 = new AServantCoroCallback();
AServantCoroPrxCallbackPtr cb2(new AServantCoroCallback());
cb2->setCoroParallelBasePtr(sharedPtr);
_pPrx->coro_testStr(cb2, sIn);

coroWhenAll(sharedPtr);

if(cb1->_iRet == 0 && cb2->_iRet == 0)
if(((AServantCoroCallback*)(cb1.get()))->_iRet == 0 && ((AServantCoroCallback*)(cb2.get()))->_iRet == 0)
{
sOut = cb2->_sOut;
sOut = ((AServantCoroCallback*)(cb2.get()))->_sOut;
iRet = 0;
}

Expand Down
8 changes: 4 additions & 4 deletions examples/CoroutineDemo/testParallelCoro/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class BServantCoroCallback : public BServantCoroPrxCallback
int _iOut;
string _sOut;
};
typedef tars::TC_AutoPtr<BServantCoroCallback> BServantCoroCallbackPtr;
// typedef tars::TC_AutoPtr<BServantCoroCallback> BServantCoroCallbackPtr;

////////////////////////////////////////////
//继承框架的协程类
Expand Down Expand Up @@ -93,19 +93,19 @@ void TestCoroutine::handle()
{
CoroParallelBasePtr sharedPtr = new CoroParallelBase(2);

BServantCoroCallbackPtr cb1 = new BServantCoroCallback();
BServantCoroPrxCallbackPtr cb1(new BServantCoroCallback());
cb1->setCoroParallelBasePtr(sharedPtr);
_prx->coro_testCoroSerial(cb1, sIn);

BServantCoroCallbackPtr cb2 = new BServantCoroCallback();
BServantCoroPrxCallbackPtr cb2(new BServantCoroCallback());
cb2->setCoroParallelBasePtr(sharedPtr);
_prx->coro_testCoroParallel(cb2, sIn);

coroWhenAll(sharedPtr);

// cout << "ret1:" << cb1->_sOut << "|ret2:" << cb2->_sOut << endl;

if(cb1->_iRet == 0 && cb2->_iRet == 0 && cb1->_iException == 0 && cb2->_iException == 0)
if(((BServantCoroCallback*)(cb1.get()))->_iRet == 0 && ((BServantCoroCallback*)(cb2.get()))->_iRet == 0 && ((BServantCoroCallback*)(cb1.get()))->_iException == 0 && ((BServantCoroCallback*)(cb2.get()))->_iException == 0)
{
++sum;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/CustomDemo/CustomClient/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void asyncCall(int c)
{
try
{
CustomCallBackPtr cb = new CustomCallBack();
ServantProxyCallbackPtr cb(new CustomCallBack());
param.servantPrx->rpc_call_async(param.servantPrx->tars_gen_requestid(), "doCustomFunc", buffer.c_str(), buffer.length(), cb);
}
catch(exception& e)
Expand Down
5 changes: 4 additions & 1 deletion examples/PushCallbackDemo/Client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ int main(int argc, char *argv[])
_comm->setProperty(conf);

HelloPrx pPrx = _comm->stringToProxy<HelloPrx>(helloObj);
pPrx->tars_set_push_callback(new PushCallbackImp());

ServantProxyCallbackPtr cbPush(new PushCallbackImp());

pPrx->tars_set_push_callback(cbPush);
pPrx->registerPush();

while(g_count < 10)
Expand Down
4 changes: 2 additions & 2 deletions examples/PushDemo/PushClient/TestRecvThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ RecvThread::RecvThread(int second):_second(second), _bTerminate(false)

void RecvThread::run(void)
{
TestPushCallBackPtr cbPush = new TestPushCallBack();
ServantProxyCallbackPtr cbPush(new TestPushCallBack());
_prx->tars_set_push_callback(cbPush);

string buf("heartbeat");
Expand All @@ -139,7 +139,7 @@ void RecvThread::run(void)
{
try
{
TestPushCallBackPtr cb = new TestPushCallBack();
ServantProxyCallbackPtr cb(new TestPushCallBack());
_prx->rpc_call_async(_prx->tars_gen_requestid(), "printResult", buf.c_str(), buf.length(), cb);
}
catch(TarsException& e)
Expand Down
7 changes: 4 additions & 3 deletions examples/QuickStartDemo/HelloServer/Client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void asyncCall(int c)
//发起远程调用
for (int i = 0; i < c; ++i)
{
HelloPrxCallbackPtr p = new HelloCallback(t, i, c);
HelloPrxCallbackPtr p(new HelloCallback(t, i, c));

try
{
Expand Down Expand Up @@ -172,9 +172,10 @@ void syncTupCall(int c)

rsp.decode(package.sBuffer.data(), package.sBuffer.size());

int ret = rsp.get<int>("");
int ret = rsp.get<int>("");
string sRsp = rsp.get<string>("sRsp");

cout << "ret:" << ret << ", rsp:" << sRsp << endl;
// assert(ret == 0);
// assert(sRsp == buffer);
}
Expand Down Expand Up @@ -262,7 +263,7 @@ void asyncTupCall(int c)
vector<char> buff;
req.encode(buff);

ServantProxyCallbackPtr p = new TupCallback(t, i, c);
ServantProxyCallbackPtr p(new TupCallback(t, i, c));

param.pPrx->rpc_call_async(req.getRequestId(), "testHello", buff.data(), buff.size(), p);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/QuickStartDemo/ProxyServer/Server/ProxyImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ tars::Int32 ProxyImp::testProxy(const std::string& sIn, std::string &sOut, tars:
{
current->setResponse(false);

TestApp::HelloPrxCallbackPtr cb = new HelloCallback(current);
TestApp::HelloPrxCallbackPtr cb(new HelloCallback(current));

_prx->tars_set_timeout(3000)->async_testHello(cb,sIn);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/UdpDemo/Client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void asyncCall(int c)
if(request_count - callback_count < 100) {
i++;
request_count++;
HelloPrxCallbackPtr p = new HelloCallback(t, i, c);
HelloPrxCallbackPtr p(new HelloCallback(t, i, c));
try {
param.pPrx->async_testHello(p, buffer);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/UtilDemo/demo-server/demo_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class MyServer : public TC_EpollServer

void initialize()
{
g_group.start(1);
g_group.start();

g_logger.init("./debug", 1024 * 1024, 10);
g_logger.modFlag(TC_RollLogger::HAS_LEVEL | TC_RollLogger::HAS_PID, true);
Expand Down
10 changes: 10 additions & 0 deletions mock/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

include_directories(../)
file(GLOB_RECURSE SRC_FILES *.cpp)
add_library(tarsmock ${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)

11 changes: 11 additions & 0 deletions mock/ConfigImp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

#include "ConfigImp.h"

map<string, string> ConfigImp::files;
std::mutex ConfigImp::_mutex;

void ConfigImp::setConfigFile(const string &name, const string &content)
{
std::lock_guard<std::mutex> lock(_mutex);
files[name] = content;
}
15 changes: 13 additions & 2 deletions unit-test/server/framework/ConfigImp.h → mock/ConfigImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ConfigImp : public Config
*/
virtual void initialize()
{
files["test.conf"] = "test-content";

};

/**
Expand All @@ -53,6 +53,8 @@ class ConfigImp : public Config
{
LOG_CONSOLE_DEBUG << app << ", " << server << ", " << filename << endl;

std::lock_guard<std::mutex> lock(_mutex);

map<string, string>::iterator it =files.find(filename);
if(it!=files.end()){
config = it->second;
Expand Down Expand Up @@ -144,8 +146,17 @@ class ConfigImp : public Config

return 0;
}

/**
*
* @param name
* @param content
*/
static void setConfigFile(const string &name, const string &content);

private:
map<string, string> files;
static std::mutex _mutex;
static map<string, string> files;
};

#endif /* TARS_TARS_TEST_TESTCODE_INCLUDE_STUB_CONFIGIMP_H_ */
Loading

0 comments on commit fce0ec6

Please sign in to comment.