diff --git a/cmake/Thirdparty.cmake b/cmake/Thirdparty.cmake
index 0bfb465..e6f1a0c 100755
--- a/cmake/Thirdparty.cmake
+++ b/cmake/Thirdparty.cmake
@@ -73,6 +73,7 @@ if (TARS_PROTOBUF)
ExternalProject_Add(ADD_${LIB_PROTOBUF}
URL http://cdn.tarsyun.com/src/protobuf-cpp-3.11.3.tar.gz
+ DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download
PREFIX ${CMAKE_BINARY_DIR}
INSTALL_DIR ${CMAKE_SOURCE_DIR}
CONFIGURE_COMMAND cmake cmake -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/protobuf -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
@@ -90,6 +91,7 @@ if (TARS_PROTOBUF)
ExternalProject_Add(ADD_${LIB_PROTOBUF}
URL http://cdn.tarsyun.com/src/protobuf-cpp-3.11.3.tar.gz
+ DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download
PREFIX ${CMAKE_BINARY_DIR}
INSTALL_DIR ${CMAKE_SOURCE_DIR}
CONFIGURE_COMMAND cmake cmake -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/protobuf -DBUILD_SHARED_LIBS=OFF
@@ -104,8 +106,8 @@ if (TARS_PROTOBUF)
endif ()
- INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/protobuf/lib DESTINATION .)
- INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/protobuf/include/google DESTINATION include)
+ INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/protobuf/lib DESTINATION thirdparty)
+ INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/protobuf/include/google DESTINATION thirdparty/include)
add_dependencies(thirdparty ADD_${LIB_PROTOBUF})
@@ -124,8 +126,8 @@ if (TARS_SSL)
set(LIB_CRYPTO "libcrypto")
ExternalProject_Add(ADD_${LIB_SSL}
- DEPENDS ${LIB_ZLIB}
URL http://cdn.tarsyun.com/src/openssl-1.1.1d.tar.gz
+ DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download
PREFIX ${CMAKE_BINARY_DIR}
INSTALL_DIR ${CMAKE_SOURCE_DIR}
CONFIGURE_COMMAND perl Configure --prefix=${CMAKE_BINARY_DIR}/src/openssl VC-WIN64A no-asm
@@ -142,8 +144,8 @@ if (TARS_SSL)
set(LIB_CRYPTO "crypto")
ExternalProject_Add(ADD_${LIB_SSL}
- DEPENDS ${LIB_ZLIB}
URL http://cdn.tarsyun.com/src/openssl-1.1.1d.tar.gz
+ DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download
PREFIX ${CMAKE_BINARY_DIR}
INSTALL_DIR ${CMAKE_SOURCE_DIR}
CONFIGURE_COMMAND ./config --prefix=${CMAKE_BINARY_DIR}/src/openssl no-shared
@@ -158,8 +160,8 @@ if (TARS_SSL)
endif ()
- INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/openssl/lib DESTINATION .)
- INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/openssl/include/openssl DESTINATION include)
+ INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/openssl/lib DESTINATION thirdparty)
+ INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/openssl/include/openssl DESTINATION thirdparty/include)
add_dependencies(thirdparty ADD_${LIB_SSL})
endif ()
@@ -175,6 +177,7 @@ if (TARS_MYSQL)
ExternalProject_Add(ADD_${LIB_MYSQL}
URL http://cdn.tarsyun.com/src/mysql-connector-c-6.1.11-src.zip
+ DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download
PREFIX ${CMAKE_BINARY_DIR}
INSTALL_DIR ${CMAKE_SOURCE_DIR}
CONFIGURE_COMMAND cmake . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/mysql -DBUILD_CONFIG=mysql_release
@@ -192,6 +195,7 @@ if (TARS_MYSQL)
ExternalProject_Add(ADD_${LIB_MYSQL}
URL http://cdn.tarsyun.com/src/mysql-connector-c-6.1.11-src.tar.gz
+ DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download
PREFIX ${CMAKE_BINARY_DIR}
INSTALL_DIR ${CMAKE_SOURCE_DIR}
CONFIGURE_COMMAND cmake . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DDISABLE_SHARED=1
@@ -206,9 +210,9 @@ if (TARS_MYSQL)
endif ()
- INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/mysql/lib DESTINATION .)
+ INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/mysql/lib DESTINATION thirdparty)
- INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/mysql/include/mysql DESTINATION include)
+ INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/mysql/include/mysql DESTINATION thirdparty/include)
add_dependencies(thirdparty ADD_${LIB_MYSQL})
endif ()
@@ -228,6 +232,7 @@ if (TARS_HTTP2)
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 . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/nghttp2 -DENABLE_LIB_ONLY=ON -DENABLE_STATIC_LIB=ON
@@ -243,6 +248,7 @@ if (TARS_HTTP2)
else ()
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 . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/nghttp2 -DENABLE_LIB_ONLY=ON -DENABLE_STATIC_LIB=ON
@@ -257,8 +263,8 @@ if (TARS_HTTP2)
endif ()
- INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/nghttp2/lib DESTINATION .)
- INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/nghttp2/include/nghttp2 DESTINATION include)
+ INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/nghttp2/lib DESTINATION thirdparty)
+ INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/nghttp2/include/nghttp2 DESTINATION thirdparty/include)
add_dependencies(thirdparty ADD_${LIB_HTTP2})
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index fdd737f..6c5fab3 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -12,6 +12,7 @@ endif()
add_subdirectory(PushDemo)
add_subdirectory(QuickStartDemo)
add_subdirectory(StressDemo)
+add_subdirectory(UdpDemo)
set(WORKING_DIRECTORY ${tars-cpp_SOURCE_DIR})
@@ -38,6 +39,13 @@ if(WIN32)
COMMAND examples/scripts/run-auth.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run auth")
+ add_custom_target(run-udp
+ WORKING_DIRECTORY ${WORKING_DIRECTORY}
+ DEPENDS UdpServer UdpClient
+ USES_TERMINAL
+ COMMAND examples/scripts/run-udp.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+ COMMENT "call run udp")
+
if(TARS_HTTP2)
add_custom_target(run-http2
WORKING_DIRECTORY ${WORKING_DIRECTORY}
@@ -117,10 +125,16 @@ else(WIN32)
COMMENT "call quick start")
add_custom_target(run-http
- WORKING_DIRECTORY ${WORKING_DIRECTORY}
- DEPENDS HttpServer HttpClient
- COMMAND sh examples/scripts/run-http.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
- COMMENT "call run http")
+ WORKING_DIRECTORY ${WORKING_DIRECTORY}
+ DEPENDS HttpServer HttpClient
+ COMMAND sh examples/scripts/run-http.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+ COMMENT "call run http")
+
+ add_custom_target(run-udp
+ WORKING_DIRECTORY ${WORKING_DIRECTORY}
+ DEPENDS UdpServer UdpClient
+ COMMAND sh examples/scripts/run-udp.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+ COMMENT "call run udp")
add_custom_target(run-auth
WORKING_DIRECTORY ${WORKING_DIRECTORY}
diff --git a/examples/UdpDemo/CMakeLists.txt b/examples/UdpDemo/CMakeLists.txt
new file mode 100644
index 0000000..6345c28
--- /dev/null
+++ b/examples/UdpDemo/CMakeLists.txt
@@ -0,0 +1,5 @@
+
+include_directories(Server)
+add_subdirectory(Server)
+add_subdirectory(Client)
+
diff --git a/examples/UdpDemo/Client/CMakeLists.txt b/examples/UdpDemo/Client/CMakeLists.txt
new file mode 100644
index 0000000..53d3c5c
--- /dev/null
+++ b/examples/UdpDemo/Client/CMakeLists.txt
@@ -0,0 +1 @@
+build_tars_server(UdpClient UdpServer)
diff --git a/examples/UdpDemo/Client/config.conf b/examples/UdpDemo/Client/config.conf
new file mode 100755
index 0000000..c2a9796
--- /dev/null
+++ b/examples/UdpDemo/Client/config.conf
@@ -0,0 +1,28 @@
+
+
+
+
+ #tarsregistry locator
+ locator = tars.tarsregistry.QueryObj@tcp -h 127.0.0.1 -p 17890
+ #max invoke timeout
+ sync-invoke-timeout = 5000
+ #refresh endpoint interval
+ refresh-endpoint-interval = 10000
+ #stat obj
+ stat = tars.tarsstat.StatObj
+ #max send queue length limit
+ sendqueuelimit = 100000
+ #async queue length limit
+ asyncqueuecap = 100000
+ #async callback thread num
+ asyncthread = 3
+ #net thread
+ netthread = 1
+ #merge net and sync thread
+ mergenetasync = 0
+ #module name
+ modulename = TestApp.UdpClient
+
+
+
+
diff --git a/examples/UdpDemo/Client/main.cpp b/examples/UdpDemo/Client/main.cpp
new file mode 100644
index 0000000..d91b236
--- /dev/null
+++ b/examples/UdpDemo/Client/main.cpp
@@ -0,0 +1,243 @@
+/**
+ * Tencent is pleased to support the open source community by making Tars available.
+ *
+ * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
+ *
+ * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed
+ * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+#include
+#include "servant/Communicator.h"
+#include "Hello.h"
+#include "util/tc_option.h"
+
+using namespace std;
+using namespace tars;
+using namespace TestApp;
+
+Communicator* _comm;
+
+static string helloObj = "TestApp.UdpServer.UdpObj@udp -h 127.0.0.1 -p 9016 -e 1";
+static string ipv6Obj = "TestApp.UdpServer.Ipv6Obj@udp -h ::1 -p 25460";
+
+struct Param
+{
+ int count;
+ string call;
+ int thread;
+ int buffersize;
+ int netthread;
+
+ HelloPrx pPrx;
+};
+
+Param param;
+std::atomic request_count(0);
+std::atomic callback_count(0);
+
+struct HelloCallback : public HelloPrxCallback
+{
+ HelloCallback(int64_t t, int i, int c) : start(t), cur(i), count(c)
+ {
+
+ }
+
+ //call back
+ virtual void callback_testHello(int ret, const string &r)
+ {
+ assert(ret == 0);
+ callback_count++;
+
+ if(cur == count-1)
+ {
+ int64_t cost = TC_Common::now2us() - start;
+ cout << "callback_testHello count:" << count << ", " << cost << " us, avg:" << 1.*cost/count << "us" << endl;
+ }
+ }
+
+ virtual void callback_testHello_exception(tars::Int32 ret)
+ {
+ cout << "callback exception:" << ret << endl;
+ }
+
+ int64_t start;
+ int cur;
+ int count;
+};
+
+
+void syncCall(int c)
+{
+ string buffer(param.buffersize, 'a');
+
+ int64_t t = TC_Common::now2us();
+ //发起远程调用
+ for (int i = 0; i < c; ++i)
+ {
+ string r;
+
+ try
+ {
+ param.pPrx->testHello(buffer, r);
+ }
+ catch(exception& e)
+ {
+ cout << "exception:" << e.what() << endl;
+ }
+ ++callback_count;
+ }
+
+ int64_t cost = TC_Common::now2us() - t;
+ cout << "syncCall total:" << cost << "us, avg:" << 1.*cost/c << "us" << endl;
+}
+
+void asyncCall(int c)
+{
+ int64_t t = TC_Common::now2us();
+
+ string buffer(param.buffersize, 'a');
+
+ //发起远程调用
+ for (int i = 0; i < c;)
+ {
+ if(request_count - callback_count < 100) {
+ i++;
+ request_count++;
+ HelloPrxCallbackPtr p = new HelloCallback(t, i, c);
+ try {
+ param.pPrx->async_testHello(p, buffer);
+ }
+ catch (exception & e) {
+ cout << "exception:" << e.what() << endl;
+ }
+ }
+ else
+ {
+ TC_Common::msleep(10);
+ }
+ }
+
+ int64_t cost = TC_Common::now2us() - t;
+ cout << "asyncCall send:" << cost << "us, avg:" << 1.*cost/c << "us" << endl;
+}
+
+int main(int argc, char *argv[])
+{
+ try
+ {
+ if (argc < 6)
+ {
+ cout << "Usage:" << argv[0] << "--config=conf --count=1000 --call=[sync|async|syncv6|asyncv6] --thread=1 --buffersize=1000 --netthread=1" << endl;
+
+ return 0;
+ }
+
+ TC_Option option;
+ option.decode(argc, argv);
+
+ param.count = TC_Common::strto(option.getValue("count"));
+ if(param.count <= 0) param.count = 1000;
+ param.buffersize = TC_Common::strto(option.getValue("buffersize"));
+ if(param.buffersize <= 0) param.buffersize = 1000;
+ param.call = option.getValue("call");
+ if(param.call.empty()) param.call = "sync";
+ param.thread = TC_Common::strto(option.getValue("thread"));
+ if(param.thread <= 0) param.thread = 1;
+ param.netthread = TC_Common::strto(option.getValue("netthread"));
+ if(param.netthread <= 0) param.netthread = 1;
+
+ _comm = new Communicator();
+
+ TC_Config conf;
+ conf.parseFile(option.getValue("config"));
+ _comm->setProperty(conf);
+
+// TafRollLogger::getInstance()->logger()->setLogLevel(6);
+
+ _comm->setProperty("sendqueuelimit", "1000000");
+ _comm->setProperty("asyncqueuecap", "1000000");
+
+ _comm->setProperty("netthread", TC_Common::tostr(param.netthread));
+
+
+ int64_t start = TC_Common::now2us();
+
+ std::function func;
+
+ if (param.call == "sync")
+ {
+ func = syncCall;
+ param.pPrx = _comm->stringToProxy(helloObj);
+
+ }
+ else if (param.call == "async")
+ {
+ func = asyncCall;
+ param.pPrx = _comm->stringToProxy(helloObj);
+
+ }
+ else if (param.call == "syncv6")
+ {
+ func = syncCall;
+ param.pPrx = _comm->stringToProxy(ipv6Obj);
+
+ }
+ else if (param.call == "asyncv6")
+ {
+ func = asyncCall;
+ param.pPrx = _comm->stringToProxy(ipv6Obj);
+ }
+ else
+ {
+ cout << "no func, exits" << endl;
+ exit(0);
+ }
+
+ param.pPrx->tars_connect_timeout(5000);
+ param.pPrx->tars_async_timeout(60*1000);
+ param.pPrx->tars_ping();
+
+ vector vt;
+ for(int i = 0 ; i< param.thread; i++)
+ {
+ vt.push_back(new std::thread(func, param.count));
+ }
+
+ std::thread print([&]{while(callback_count != param.count * param.thread) {
+ cout << "Auth:" << param.call << " : ----------finish count:" << callback_count << endl;
+ std::this_thread::sleep_for(std::chrono::seconds(1));
+ };});
+
+ for(size_t i = 0 ; i< vt.size(); i++)
+ {
+ vt[i]->join();
+ delete vt[i];
+ }
+
+ cout << "(pid:" << std::this_thread::get_id() << ")"
+ << "(count:" << param.count << ")"
+ << "(use ms:" << (TC_Common::now2us() - start)/1000 << ")"
+ << endl;
+
+ while(callback_count != param.count * param.thread) {
+ std::this_thread::sleep_for(std::chrono::seconds(1));
+ }
+ print.join();
+ cout << "Auth:" << param.call << " ----------finish count:" << callback_count << endl;
+ }
+ catch(exception &ex)
+ {
+ cout << ex.what() << endl;
+ }
+ cout << "main return." << endl;
+
+ return 0;
+}
diff --git a/examples/UdpDemo/Server/CMakeLists.txt b/examples/UdpDemo/Server/CMakeLists.txt
new file mode 100644
index 0000000..b7a6673
--- /dev/null
+++ b/examples/UdpDemo/Server/CMakeLists.txt
@@ -0,0 +1,2 @@
+build_tars_server("UdpServer" "")
+
diff --git a/examples/UdpDemo/Server/Hello.h b/examples/UdpDemo/Server/Hello.h
new file mode 100644
index 0000000..f85e089
--- /dev/null
+++ b/examples/UdpDemo/Server/Hello.h
@@ -0,0 +1,471 @@
+// **********************************************************************
+// This file was generated by a TARS parser!
+// TARS version 2.0.0.
+// **********************************************************************
+
+#ifndef __HELLO_H_
+#define __HELLO_H_
+
+#include