├── .github └── workflows │ ├── ccpp-linux.yml │ ├── ccpp-mac.yml │ ├── ccpp-win.yml │ └── gitee-sync.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── Changelist-2.x.md ├── Changelist-3.x.md ├── Contributing.md ├── LICENSE ├── README.md ├── README.zh.md ├── cmake ├── BuildTarsCpp.cmake ├── Common.cmake ├── GenVersion.cmake ├── ParseAsm.cmake └── Thirdparty.cmake ├── cross-compiler.cmake ├── docs-en └── README.md ├── docs └── README.md ├── examples ├── AuthDemo │ ├── CMakeLists.txt │ ├── Client │ │ ├── CMakeLists.txt │ │ ├── config.conf │ │ └── main.cpp │ └── Server │ │ ├── CMakeLists.txt │ │ ├── Hello.tars │ │ ├── HelloImp.cpp │ │ ├── HelloImp.h │ │ ├── HelloServer.cpp │ │ ├── HelloServer.h │ │ └── config.conf ├── CMakeLists.txt ├── ClientDemo │ ├── CMakeLists.txt │ └── main.cpp ├── CoroutineDemo │ ├── AServer │ │ ├── AServant.tars │ │ ├── AServantImp.cpp │ │ ├── AServantImp.h │ │ ├── AServer.cpp │ │ ├── AServer.h │ │ ├── CMakeLists.txt │ │ └── config.conf │ ├── BServer │ │ ├── BServant.tars │ │ ├── BServantImp.cpp │ │ ├── BServantImp.h │ │ ├── BServer.cpp │ │ ├── BServer.h │ │ ├── CMakeLists.txt │ │ └── config.conf │ ├── CMakeLists.txt │ ├── README.md │ ├── client │ │ ├── CMakeLists.txt │ │ └── main.cpp │ ├── testCoro │ │ ├── CMakeLists.txt │ │ └── main.cpp │ └── testParallelCoro │ │ ├── CMakeLists.txt │ │ └── main.cpp ├── CustomDemo │ ├── CMakeLists.txt │ ├── CustomClient │ │ ├── CMakeLists.txt │ │ └── main.cpp │ ├── CustomServer │ │ ├── CMakeLists.txt │ │ ├── CustomServantImp.cpp │ │ ├── CustomServantImp.h │ │ ├── CustomServer.cpp │ │ ├── CustomServer.h │ │ └── config.conf │ └── README.md ├── GrpcDemo │ ├── CMakeLists.txt │ ├── GrpcClient │ │ ├── CMakeLists.txt │ │ ├── helloworld.proto │ │ └── main.cpp │ └── GrpcServer │ │ ├── CMakeLists.txt │ │ ├── GrpcImp.cpp │ │ ├── GrpcImp.h │ │ ├── GrpcServer.cpp │ │ ├── GrpcServer.h │ │ ├── config.conf │ │ └── helloworld.proto ├── HttpDemo │ ├── CMakeLists.txt │ ├── Http2Client │ │ ├── CMakeLists.txt │ │ └── main.cpp │ ├── Http2Server │ │ ├── CMakeLists.txt │ │ ├── Http2Imp.cpp │ │ ├── Http2Imp.h │ │ ├── HttpServer.cpp │ │ ├── HttpServer.h │ │ └── config.conf │ ├── HttpClient │ │ ├── CMakeLists.txt │ │ └── main.cpp │ └── HttpServer │ │ ├── CMakeLists.txt │ │ ├── HttpImp.cpp │ │ ├── HttpImp.h │ │ ├── HttpServer.cpp │ │ ├── HttpServer.h │ │ └── config.conf ├── PromiseDemo │ ├── AServer │ │ ├── AServant.tars │ │ ├── AServantImp.cpp │ │ ├── AServantImp.h │ │ ├── AServer.cpp │ │ ├── AServer.h │ │ ├── BServant.tars │ │ ├── CServant.tars │ │ └── makefile │ ├── BServer │ │ ├── BServant.tars │ │ ├── BServantImp.cpp │ │ ├── BServantImp.h │ │ ├── BServer.cpp │ │ ├── BServer.h │ │ └── makefile │ ├── CServer │ │ ├── CServant.tars │ │ ├── CServantImp.cpp │ │ ├── CServantImp.h │ │ ├── CServer.cpp │ │ ├── CServer.h │ │ └── makefile │ ├── Client │ │ ├── main.cpp │ │ └── makefile │ └── README.md ├── PushCallbackDemo │ ├── CMakeLists.txt │ ├── Client │ │ ├── CMakeLists.txt │ │ ├── config.conf │ │ └── main.cpp │ └── Server │ │ ├── CMakeLists.txt │ │ ├── Hello.tars │ │ ├── HelloImp.cpp │ │ ├── HelloImp.h │ │ ├── HelloServer.cpp │ │ ├── HelloServer.h │ │ ├── Push.tars │ │ ├── PushThread.cpp │ │ ├── PushThread.h │ │ └── config.conf ├── PushDemo │ ├── CMakeLists.txt │ ├── PushClient │ │ ├── CMakeLists.txt │ │ ├── TestRecvThread.cpp │ │ ├── TestRecvThread.h │ │ └── main.cpp │ ├── PushServer │ │ ├── CMakeLists.txt │ │ ├── TestPushServantImp.cpp │ │ ├── TestPushServantImp.h │ │ ├── TestPushServer.cpp │ │ ├── TestPushServer.h │ │ ├── TestPushThread.cpp │ │ ├── TestPushThread.h │ │ └── config.conf │ └── README.md ├── QuickStartDemo │ ├── CMakeLists.txt │ ├── HelloServer │ │ ├── CMakeLists.txt │ │ ├── Client │ │ │ ├── CMakeLists.txt │ │ │ └── main.cpp │ │ └── Server │ │ │ ├── CMakeLists.txt │ │ │ ├── Hello.tars │ │ │ ├── HelloImp.cpp │ │ │ ├── HelloImp.h │ │ │ ├── HelloServer.cpp │ │ │ ├── HelloServer.h │ │ │ ├── config-1.conf │ │ │ ├── config-2.conf │ │ │ └── config.conf │ ├── ProxyServer │ │ ├── CMakeLists.txt │ │ ├── Client │ │ │ ├── CMakeLists.txt │ │ │ └── main.cpp │ │ └── Server │ │ │ ├── CMakeLists.txt │ │ │ ├── Proxy.tars │ │ │ ├── ProxyImp.cpp │ │ │ ├── ProxyImp.h │ │ │ ├── ProxyServer.cpp │ │ │ ├── ProxyServer.h │ │ │ └── config.conf │ └── README.md ├── README.md ├── SSLDemo │ ├── CMakeLists.txt │ ├── Client │ │ ├── CMakeLists.txt │ │ ├── config.conf │ │ └── main.cpp │ ├── Server │ │ ├── CMakeLists.txt │ │ ├── SSLImp.cpp │ │ ├── SSLImp.h │ │ ├── SSLServer.cpp │ │ ├── SSLServer.h │ │ ├── config.conf │ │ └── ssl.tars │ └── certs │ │ ├── ca.crt │ │ ├── ca.key │ │ ├── ca.srl │ │ ├── client.crt │ │ ├── client.csr │ │ ├── client.key │ │ ├── client1.crt │ │ ├── client1.csr │ │ ├── client1.key │ │ ├── create.sh │ │ ├── server.crt │ │ ├── server.csr │ │ ├── server.key │ │ ├── server1.crt │ │ ├── server1.csr │ │ └── server1.key ├── StressDemo │ ├── CMakeLists.txt │ ├── README.md │ ├── TarsStressClient │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ └── teststress.sh │ └── TarsStressServer │ │ ├── CMakeLists.txt │ │ ├── Stress.tars │ │ ├── StressImp.cpp │ │ ├── StressImp.h │ │ ├── TarsStressServer.cpp │ │ └── TarsStressServer.h ├── UdpDemo │ ├── CMakeLists.txt │ ├── Client │ │ ├── CMakeLists.txt │ │ ├── config.conf │ │ └── main.cpp │ └── Server │ │ ├── CMakeLists.txt │ │ ├── Hello.tars │ │ ├── HelloImp.cpp │ │ ├── HelloImp.h │ │ ├── HelloServer.cpp │ │ ├── HelloServer.h │ │ └── config.conf ├── UtilDemo │ ├── CMakeLists.txt │ ├── demo-server │ │ ├── CMakeLists.txt │ │ └── demo_server.cpp │ └── demo-util │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ ├── test_tc_encoder.cpp │ │ ├── test_tc_file.cpp │ │ └── test_tc_http.cpp └── scripts │ ├── run-auth.bat │ ├── run-auth.sh │ ├── run-co.bat │ ├── run-co.sh │ ├── run-custom.bat │ ├── run-custom.sh │ ├── run-http.bat │ ├── run-http.sh │ ├── run-http2.bat │ ├── run-http2.sh │ ├── run-kill.bat │ ├── run-kill.sh │ ├── run-push-callback.bat │ ├── run-push-callback.sh │ ├── run-push.bat │ ├── run-push.sh │ ├── run-quick-start.bat │ ├── run-quick-start.sh │ ├── run-ssl.bat │ ├── run-ssl.sh │ ├── run-udp.bat │ └── run-udp.sh ├── mock ├── CMakeLists.txt ├── ConfigImp.cpp ├── ConfigImp.h ├── DbHandle.cpp ├── DbHandle.h ├── FrameworkServer.cpp ├── FrameworkServer.h ├── LogImp.cpp ├── LogImp.h ├── QueryImp.cpp ├── QueryImp.h ├── StatImp.cpp ├── StatImp.h ├── TarsMockUtil.cpp ├── TarsMockUtil.h └── framework.h ├── servant ├── CMakeLists.txt ├── README.md ├── README.zh.md ├── jmem │ ├── jmem_hashmap.h │ ├── jmem_hashmap_compact.h │ ├── jmem_multi_hashmap.h │ ├── jmem_policy.h │ ├── jmem_queue.h │ └── jmem_rbtree.h ├── libservant │ ├── AdapterProxy.cpp │ ├── AdminServant.cpp │ ├── AppCache.cpp │ ├── AppProtocol.cpp │ ├── Application.cpp │ ├── AsyncProcThread.cpp │ ├── AuthLogic.cpp │ ├── BaseNotify.cpp │ ├── CMakeLists.txt │ ├── Communicator.cpp │ ├── CommunicatorEpoll.cpp │ ├── Current.cpp │ ├── EndpointInfo.cpp │ ├── EndpointManager.cpp │ ├── Global.cpp │ ├── KeepAliveNodeF.cpp │ ├── Message.cpp │ ├── NotifyObserver.cpp │ ├── ObjectProxy.cpp │ ├── PropertyReport.cpp │ ├── RemoteConfig.cpp │ ├── RemoteLogger.cpp │ ├── RemoteNotify.cpp │ ├── Servant.cpp │ ├── ServantHandle.cpp │ ├── ServantHelper.cpp │ ├── ServantProxy.cpp │ ├── ServantProxyFactory.cpp │ └── StatReport.cpp ├── makefile │ ├── makefile.tars │ └── tars-tools.cmake.in ├── promise │ ├── bind.h │ ├── bind_internal.h │ ├── callback.h │ ├── exception.h │ ├── function.h │ ├── promise.h │ ├── template_helper.h │ ├── type_list.h │ └── when_all.h ├── script │ ├── busybox.exe │ ├── cmake_demo │ │ ├── CMakeLists.txt │ │ └── src │ │ │ ├── CMakeLists.txt │ │ │ ├── DemoServant.tars │ │ │ ├── DemoServantImp.cpp │ │ │ ├── DemoServantImp.h │ │ │ ├── DemoServer.cpp │ │ │ └── DemoServer.h │ ├── cmake_http_demo │ │ ├── CMakeLists.txt │ │ └── src │ │ │ ├── CMakeLists.txt │ │ │ ├── DemoServantImp.cpp │ │ │ ├── DemoServantImp.h │ │ │ ├── DemoServer.cpp │ │ │ └── DemoServer.h │ ├── cmake_http_server.bat │ ├── cmake_http_server.sh │ ├── cmake_tars_server.bat │ ├── cmake_tars_server.sh │ ├── create_http_server.sh │ ├── create_tars_server.sh │ ├── demo │ │ ├── DemoServant.tars │ │ ├── DemoServantImp.cpp │ │ ├── DemoServantImp.h │ │ ├── DemoServer.cpp │ │ ├── DemoServer.h │ │ └── makefile │ └── http_demo │ │ ├── DemoServantImp.cpp │ │ ├── DemoServantImp.h │ │ ├── DemoServer.cpp │ │ ├── DemoServer.h │ │ └── makefile ├── servant │ ├── AdapterProxy.h │ ├── AdminServant.h │ ├── AppCache.h │ ├── AppProtocol.h │ ├── Application.h │ ├── AsyncProcThread.h │ ├── AuthLogic.h │ ├── BaseNotify.h │ ├── Communicator.h │ ├── CommunicatorEpoll.h │ ├── CommunicatorFactory.h │ ├── Cookie.h │ ├── Current.h │ ├── EndpointInfo.h │ ├── EndpointManager.h │ ├── Global.h │ ├── KeepAliveNodeF.h │ ├── Message.h │ ├── NotifyObserver.h │ ├── ObjectProxy.h │ ├── ObjectProxyFactory.h │ ├── PropertyReport.h │ ├── RemoteConfig.h │ ├── RemoteLogger.h │ ├── RemoteNotify.h │ ├── ReqTime.h │ ├── Servant.h │ ├── ServantHandle.h │ ├── ServantHelper.h │ ├── ServantProxy.h │ ├── ServantProxyFactory.h │ ├── StatReport.h │ └── TarsLogger.h └── tup │ ├── CMakeLists.txt │ ├── RequestF.tars │ ├── Tars.h │ ├── TarsDisplayer.h │ ├── TarsJson.h │ ├── TarsType.h │ ├── TarsXml.h │ └── tup.h ├── tools ├── CMakeLists.txt ├── README.md ├── README.zh.md ├── pb2tarscpp │ ├── CMakeLists.txt │ ├── CppGenCallback.cpp │ ├── CppGenCallback.h │ ├── CppGenProxy.cpp │ ├── CppGenProxy.h │ ├── CppGenServant.cpp │ ├── CppGenServant.h │ ├── CppPbUtils.cpp │ ├── CppPbUtils.h │ ├── CppPlugin.cpp │ └── CppPlugin.h ├── tars2android │ ├── CMakeLists.txt │ ├── interface_analysis.cpp │ ├── interface_analysis.h │ ├── main.cpp │ ├── tars2android.cpp │ ├── tars2android.h │ ├── tars_filter.cpp │ └── tars_filter.h ├── tars2c │ ├── CMakeLists.txt │ ├── main.cpp │ ├── tars2c.cpp │ └── tars2c.h ├── tars2case │ ├── CMakeLists.txt │ ├── main.cpp │ ├── tars2case.cpp │ └── tars2case.h ├── tars2cpp │ ├── CMakeLists.txt │ ├── main.cpp │ ├── tars2cpp.cpp │ └── tars2cpp.h ├── tars2cs │ ├── CMakeLists.txt │ ├── main.cpp │ ├── tars2cs.cpp │ └── tars2cs.h ├── tars2node │ ├── CMakeLists.txt │ ├── code_generator.cpp │ ├── code_generator.h │ ├── file_util.cpp │ ├── gen_js.cpp │ ├── gen_js_dts.cpp │ ├── gen_proxy.cpp │ ├── gen_proxy_dts.cpp │ ├── gen_proxy_ts.cpp │ ├── gen_server.cpp │ ├── gen_server_dts.cpp │ ├── gen_server_imp.cpp │ ├── gen_server_ts.cpp │ ├── gen_server_ts_imp.cpp │ ├── gen_ts.cpp │ ├── idl_scan.cpp │ ├── idl_util.cpp │ └── main.cpp ├── tars2oc │ ├── CMakeLists.txt │ ├── main.cpp │ ├── tars2oc.cpp │ └── tars2oc.h ├── tars2php │ ├── CMakeLists.txt │ ├── main.cpp │ ├── tars2php.cpp │ └── tars2php.h ├── tars2python │ ├── CMakeLists.txt │ ├── main.cpp │ ├── tars2python.cpp │ └── tars2python.h ├── tarsgrammar │ ├── CMakeLists.txt │ ├── tars.l │ ├── tars.tab.cpp │ └── tars.y ├── tarsmerge │ ├── CMakeLists.txt │ └── main.cpp └── tarsparse │ ├── CMakeLists.txt │ ├── element.cpp │ ├── element.h │ ├── parse.cpp │ ├── parse.h │ ├── tars.lex.cpp │ ├── tars.tab.cpp │ └── tars.tab.hpp ├── unit-test ├── CMakeLists.txt ├── certs.h ├── certs │ ├── ca.crt │ ├── ca.key │ ├── ca.srl │ ├── client.crt │ ├── client.csr │ ├── client.key │ ├── client1.crt │ ├── client1.csr │ ├── client1.key │ ├── create.sh │ ├── server.crt │ ├── server.csr │ ├── server.key │ ├── server1.crt │ ├── server1.csr │ └── server1.key ├── hello_test.cpp ├── hello_test.h ├── main.cpp ├── rpc │ ├── test_admin.cpp │ ├── test_async_rpc.cpp │ ├── test_auth.cpp │ ├── test_close.cpp │ ├── test_communicator.cpp │ ├── test_custom.cpp │ ├── test_dyeing.cpp │ ├── test_http.cpp │ ├── test_proxy_timeout.cpp │ ├── test_prx_update.cpp │ ├── test_push.cpp │ ├── test_registry.cpp │ ├── test_rpc.cpp │ ├── test_ssl.cpp │ ├── test_stat.cpp │ ├── test_trans.cpp │ ├── test_udp.cpp │ ├── test_win_server.cpp │ ├── test_wup.cpp │ └── test_wup_trans.cpp ├── server │ ├── CustomImp.cpp │ ├── CustomImp.h │ ├── Hello.tars │ ├── HelloImp.cpp │ ├── HelloImp.h │ ├── HelloServer.cpp │ ├── HelloServer.h │ ├── HttpImp.cpp │ ├── HttpImp.h │ ├── Push.tars │ ├── PushImp.cpp │ ├── PushImp.h │ ├── PushThread.cpp │ ├── PushThread.h │ ├── RpcServer.cpp │ ├── RpcServer.h │ ├── TranImp.cpp │ ├── TranImp.h │ ├── WinServer.cpp │ ├── WinServer.h │ ├── client.conf │ ├── hello.conf │ ├── rpc1.conf │ ├── rpc2.conf │ ├── rpc3.conf │ └── windows.conf └── util │ ├── test_server.h │ ├── test_tc_cas.cpp │ ├── test_tc_clientsocket.cpp │ ├── test_tc_config.cpp │ ├── test_tc_coroutine.cpp │ ├── test_tc_docker.cpp │ ├── test_tc_encoder.cpp │ ├── test_tc_endpoint.cpp │ ├── test_tc_epoller.cpp │ ├── test_tc_epoller_server.cpp │ ├── test_tc_file.cpp │ ├── test_tc_http.cpp │ ├── test_tc_http_async.cpp │ ├── test_tc_json.cpp │ ├── test_tc_logger.cpp │ ├── test_tc_mysql.cpp │ ├── test_tc_network_buffer.cpp │ ├── test_tc_option.cpp │ ├── test_tc_port.cpp │ ├── test_tc_serialport.cpp │ ├── test_tc_socket.cpp │ ├── test_tc_thread_pool.cpp │ ├── test_tc_timeout_queue_map.cpp │ └── test_tc_timer.cpp └── util ├── CMakeLists.txt ├── README.md ├── include ├── CMakeLists.txt └── util │ ├── sys │ └── epoll.h │ ├── tc_autoptr.h │ ├── tc_base64.h │ ├── tc_bitmap.h │ ├── tc_cas_queue.h │ ├── tc_cgi.h │ ├── tc_clientsocket.h │ ├── tc_common.h │ ├── tc_config.h │ ├── tc_consistent_hash.h │ ├── tc_consistent_hash_new.h │ ├── tc_coroutine.h │ ├── tc_coroutine_mutex.h │ ├── tc_coroutine_queue.h │ ├── tc_cron.h │ ├── tc_custom_protocol.h │ ├── tc_des.h │ ├── tc_docker.h │ ├── tc_dyn_object.h │ ├── tc_encoder.h │ ├── tc_epoll_server.h │ ├── tc_epoller.h │ ├── tc_ex.h │ ├── tc_fcontext.h │ ├── tc_fifo.h │ ├── tc_file.h │ ├── tc_file_mutex.h │ ├── tc_grpc.h │ ├── tc_gzip.h │ ├── tc_hash_fun.h │ ├── tc_hashmap.h │ ├── tc_hashmap_compact.h │ ├── tc_http.h │ ├── tc_http2.h │ ├── tc_http_async.h │ ├── tc_json.h │ ├── tc_lock.h │ ├── tc_logger.h │ ├── tc_loop_queue.h │ ├── tc_malloc_chunk.h │ ├── tc_md5.h │ ├── tc_mem_chunk.h │ ├── tc_mem_queue.h │ ├── tc_mem_vector.h │ ├── tc_mmap.h │ ├── tc_monitor.h │ ├── tc_multi_hashmap.h │ ├── tc_mysql.h │ ├── tc_network_buffer.h │ ├── tc_openssl.h │ ├── tc_option.h │ ├── tc_pack.h │ ├── tc_parsepara.h │ ├── tc_platform.h │ ├── tc_port.h │ ├── tc_progress_timer.h │ ├── tc_proxy_info.h │ ├── tc_rbtree.h │ ├── tc_readers_writer_data.h │ ├── tc_reflection.h │ ├── tc_sem_mutex.h │ ├── tc_serialport.h │ ├── tc_sha.h │ ├── tc_shm.h │ ├── tc_singleton.h │ ├── tc_socket.h │ ├── tc_socket_async.h │ ├── tc_spin_lock.h │ ├── tc_split.h │ ├── tc_squeue.h │ ├── tc_strptime.h │ ├── tc_tea.h │ ├── tc_thread.h │ ├── tc_thread_cond.h │ ├── tc_thread_mutex.h │ ├── tc_thread_pool.h │ ├── tc_thread_queue.h │ ├── tc_thread_rwlock.h │ ├── tc_timeout_queue.h │ ├── tc_timeout_queue_map.h │ ├── tc_timeout_queue_new.h │ ├── tc_timeout_queue_noid.h │ ├── tc_timeprovider.h │ ├── tc_timer.h │ ├── tc_transceiver.h │ ├── tc_uuid_generator.h │ └── tc_xml.h └── src ├── CMakeLists.txt ├── asm ├── Jamfile.v2 ├── jump_arm64_aapcs_elf_gas.S ├── jump_arm64_aapcs_macho_gas.S ├── jump_arm_aapcs_elf_gas.S ├── jump_arm_aapcs_macho_gas.S ├── jump_arm_aapcs_pe_armasm.asm ├── jump_combined_sysv_macho_gas.S ├── jump_i386_ms_pe_gas.asm ├── jump_i386_ms_pe_masm.asm ├── jump_i386_sysv_elf_gas.S ├── jump_i386_sysv_macho_gas.S ├── jump_i386_x86_64_sysv_macho_gas.S ├── jump_mips32_o32_elf_gas.S ├── jump_ppc32_ppc64_sysv_macho_gas.S ├── jump_ppc32_sysv_elf_gas.S ├── jump_ppc32_sysv_macho_gas.S ├── jump_ppc32_sysv_xcoff_gas.S ├── jump_ppc64_sysv_elf_gas.S ├── jump_ppc64_sysv_macho_gas.S ├── jump_ppc64_sysv_xcoff_gas.S ├── jump_x86_64_ms_pe_gas.asm ├── jump_x86_64_ms_pe_masm.asm ├── jump_x86_64_sysv_elf_gas.S ├── jump_x86_64_sysv_macho_gas.S ├── make_arm64_aapcs_elf_gas.S ├── make_arm64_aapcs_macho_gas.S ├── make_arm_aapcs_elf_gas.S ├── make_arm_aapcs_macho_gas.S ├── make_arm_aapcs_pe_armasm.asm ├── make_combined_sysv_macho_gas.S ├── make_i386_ms_pe_gas.asm ├── make_i386_ms_pe_masm.asm ├── make_i386_sysv_elf_gas.S ├── make_i386_sysv_macho_gas.S ├── make_i386_x86_64_sysv_macho_gas.S ├── make_mips32_o32_elf_gas.S ├── make_ppc32_ppc64_sysv_macho_gas.S ├── make_ppc32_sysv_elf_gas.S ├── make_ppc32_sysv_macho_gas.S ├── make_ppc32_sysv_xcoff_gas.S ├── make_ppc64_sysv_elf_gas.S ├── make_ppc64_sysv_macho_gas.S ├── make_ppc64_sysv_xcoff_gas.S ├── make_x86_64_ms_pe_gas.asm ├── make_x86_64_ms_pe_masm.asm ├── make_x86_64_sysv_elf_gas.S ├── make_x86_64_sysv_macho_gas.S ├── ontop_arm64_aapcs_elf_gas.S ├── ontop_arm64_aapcs_macho_gas.S ├── ontop_arm_aapcs_elf_gas.S ├── ontop_arm_aapcs_macho_gas.S ├── ontop_arm_aapcs_pe_armasm.asm ├── ontop_combined_sysv_macho_gas.S ├── ontop_i386_ms_pe_gas.asm ├── ontop_i386_ms_pe_masm.asm ├── ontop_i386_sysv_elf_gas.S ├── ontop_i386_sysv_macho_gas.S ├── ontop_i386_x86_64_sysv_macho_gas.S ├── ontop_mips32_o32_elf_gas.S ├── ontop_ppc32_ppc64_sysv_macho_gas.S ├── ontop_ppc32_sysv_elf_gas.S ├── ontop_ppc32_sysv_macho_gas.S ├── ontop_ppc32_sysv_xcoff_gas.S ├── ontop_ppc64_sysv_elf_gas.S ├── ontop_ppc64_sysv_macho_gas.S ├── ontop_ppc64_sysv_xcoff_gas.S ├── ontop_x86_64_ms_pe_gas.asm ├── ontop_x86_64_ms_pe_masm.asm ├── ontop_x86_64_sysv_elf_gas.S └── ontop_x86_64_sysv_macho_gas.S ├── epoll_windows └── src │ ├── epoll.cpp │ ├── msafd.h │ └── ntapi.h ├── tc_base64.cpp ├── tc_bitmap.cpp ├── tc_cgi.cpp ├── tc_clientsocket.cpp ├── tc_common.cpp ├── tc_config.cpp ├── tc_consistent_hash_new.cpp ├── tc_coroutine.cpp ├── tc_coroutine_mutex.cpp ├── tc_cron.cpp ├── tc_des.cpp ├── tc_docker.cpp ├── tc_dyn_object.cpp ├── tc_encoder.cpp ├── tc_epoll_server.cpp ├── tc_epoller.cpp ├── tc_ex.cpp ├── tc_fifo.cpp ├── tc_file.cpp ├── tc_file_mutex.cpp ├── tc_grpc.cpp ├── tc_gzip.cpp ├── tc_hashmap.cpp ├── tc_hashmap_compact.cpp ├── tc_http.cpp ├── tc_http2.cpp ├── tc_http_async.cpp ├── tc_json.cpp ├── tc_logger.cpp ├── tc_malloc_chunk.cpp ├── tc_md5.cpp ├── tc_mem_chunk.cpp ├── tc_mem_queue.cpp ├── tc_mmap.cpp ├── tc_multi_hashmap.cpp ├── tc_mysql.cpp ├── tc_network_buffer.cpp ├── tc_openssl.cpp ├── tc_option.cpp ├── tc_pack.cpp ├── tc_parsepara.cpp ├── tc_port.cpp ├── tc_progress_timer.cpp ├── tc_proxy_info.cpp ├── tc_rbtree.cpp ├── tc_sem_mutex.cpp ├── tc_serialport.cpp ├── tc_sha.cpp ├── tc_shm.cpp ├── tc_socket.cpp ├── tc_socket_async.cpp ├── tc_spin_lock.cpp ├── tc_split.cpp ├── tc_strptime.cpp ├── tc_tea.cpp ├── tc_thread.cpp ├── tc_thread_cond.cpp ├── tc_thread_mutex.cpp ├── tc_thread_pool.cpp ├── tc_thread_rwlock.cpp ├── tc_timeprovider.cpp ├── tc_timer.cpp ├── tc_transceiver.cpp └── tc_xml.cpp /.github/workflows/ccpp-linux.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ linux 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | - name: install 16 | run: sudo apt-get install -y bison flex cmake psmisc libncurses5-dev zlib1g-dev; cmake --version 17 | - name: git 18 | run: git submodule update --init --recursive 19 | - name: configure 20 | run: mkdir build;cd build;cmake .. -DTARS_MYSQL=ON -DTARS_SSL=ON -DTARS_HTTP2=ON -DTARS_PROTOBUF=ON 21 | - name: make 22 | run: cd build; make -j4 23 | 24 | -------------------------------------------------------------------------------- /.github/workflows/ccpp-mac.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ mac 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: macos-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | - name: install 16 | run: brew install bison flex cmake; cmake --version 17 | - name: git 18 | run: git submodule update --init --recursive 19 | - name: configure 20 | run: mkdir build;cd build;cmake .. -DTARS_MYSQL=ON -DTARS_SSL=ON -DTARS_HTTP2=ON -DTARS_PROTOBUF=ON 21 | - name: make 22 | run: cd build; make -j4 23 | 24 | -------------------------------------------------------------------------------- /.github/workflows/ccpp-win.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ win 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: windows-2019 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | - uses: shogo82148/actions-setup-perl@v1 16 | with: 17 | perl-version: '5.32' 18 | distribution: strawberry 19 | - run: perl -V 20 | - name: git 21 | run: git submodule update --init --recursive 22 | - name: configure 23 | run: mkdir build;cd build; cmake --version; cmake .. -A X64 -DTARS_MYSQL=ON -DTARS_PROTOBUF=ON -DTARS_SSL=ON 24 | - name: make 25 | run: cd build; cmake --build . --config release 26 | -------------------------------------------------------------------------------- /.github/workflows/gitee-sync.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - master 5 | tags: 6 | - "*" 7 | 8 | name: Sync to Gitee 9 | jobs: 10 | run: 11 | name: Run 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout source code 15 | uses: actions/checkout@v1 16 | - name: Mirror Github to Gitee 17 | uses: Yikun/hub-mirror-action@v1.2 18 | with: 19 | src: github/TarsCloud 20 | dst: gitee/TarsCloud 21 | dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} 22 | dst_token: ${{ secrets.GITEE_TOKEN }} 23 | account_type: org 24 | timeout: 600 25 | debug: true 26 | force_update: true 27 | static_list: "TarsCpp" -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | servant/makefile/tars-tools.cmake 2 | .idea 3 | /cmake-build-debug-177 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "servant/protocol"] 2 | path = servant/protocol 3 | url = https://github.com/TarsCloud/TarsProtocol.git 4 | -------------------------------------------------------------------------------- /Contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | If you contributed but cannot find your ID here, please submit PR and add your GitHub ID to both [Tars repo](https://github.com/TarsCloud/Tars/pulls) and [here](https://github.com/TarsCloud/TarsCpp/pulls). 4 | 5 | ## TarsCpp 6 | 7 | - Abioy 8 | - jerrylucky 9 | - langio 10 | - ruanshudong 11 | - shevqko 12 | - Spacebody 13 | - TCZWJ 14 | - viest 15 | - YMChenLiye 16 | - zhanleewo 17 | - BeyondWUXF 18 | - 19 | -------------------------------------------------------------------------------- /README.zh.md: -------------------------------------------------------------------------------- 1 | Tars整体介绍文档请阅读: https://tarscloud.gitbook.io/ 2 | 3 | 该工程是Tars RPC框架C++语言的源代码 4 | 5 | 目录名称 |功能 6 | ------------------|---------------- 7 | [servant](https://github.com/TarsCloud/TarsCpp/tree/master/servant) |C++语言框架rpc的源码实现 8 | [tools](https://github.com/TarsCloud/TarsCpp/tree/master/tools) |C++语言框架IDL工具的源码实现 9 | [util](https://github.com/TarsCloud/TarsCpp/tree/master/util) |C++语言框架基础工具库的源码实现 10 | [examples](https://github.com/TarsCloud/TarsCpp/tree/master/examples) |C++语言框架的示例代码,包括:快速入门示例、promise编程入门示例、压测程序示例 11 | [unittest](https://github.com/TarsCloud/tars-unittest/tree/master) |tars cpp rpc框架的单元测试用例,基于GoogleTest开发;可以使用命令'git submodule init unittest;git submodule update'作为git子模块下载 12 | [test_deprecated](https://github.com/TarsCloud/TarsCpp/tree/master/test) |C++语言框架各个部分的测试程序,已弃用 13 | [docs](https://github.com/TarsCloud/TarsCpp/tree/master/docs) |文档说明 14 | [docs-en](https://github.com/TarsCloud/TarsCpp/tree/master/docs-en) |英文文档说明 15 | 16 | 依赖环境 17 | 18 | 软件 |软件要求 19 | ------|-------- 20 | linux内核版本: | 2.6.18及以上版本 21 | gcc版本: | 4.1.2及以上版本、glibc-devel 22 | bison工具版本: | 2.5及以上版本 23 | flex工具版本: | 2.5及以上版本 24 | cmake版本: | 3.2及以上版本 25 | mysql版本: | 4.1.17及以上版本 26 | 27 | 编译和安装 28 | ``` 29 | git clone https://github.com/TarsCloud/TarsCpp.git --recursive 30 | cd TarsCpp 31 | cmake . 32 | make 33 | make install 34 | ``` 35 | 36 | 详细安装参见[案例文档](https://tarscloud.github.io/TarsDocs/) 37 | -------------------------------------------------------------------------------- /cross-compiler.cmake: -------------------------------------------------------------------------------- 1 | # configure cross compilation 2 | set(CMAKE_SYSTEM_NAME Linux) 3 | set(CMAKE_SYSTEM_PROCESSOR aarch) 4 | 5 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 6 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 7 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 8 | 9 | SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb") 10 | SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -Wall") 11 | 12 | # you need to set the path to the cross compiler 13 | set(TOOLCHAIN_DIR /root/boat/gcc-linaro-5.4.1-2017.01-x86_64_arm-linux-gnueabi) 14 | set(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/bin/arm-linux-gnueabi-gcc) 15 | set(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/arm-linux-gnueabi-g++) 16 | 17 | -------------------------------------------------------------------------------- /docs-en/README.md: -------------------------------------------------------------------------------- 1 | [Tars C++ usage documentation](https://tarscloud.github.io/TarsDocs_en/SUMMARY.html) 2 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | [Tars C++语言使用文档](https://tarscloud.github.io/TarsDocs/SUMMARY.html) 2 | 3 | -------------------------------------------------------------------------------- /examples/AuthDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(Server) 3 | add_subdirectory(Server) 4 | add_subdirectory(Client) 5 | 6 | -------------------------------------------------------------------------------- /examples/AuthDemo/Client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("AuthClient" "AuthServer") -------------------------------------------------------------------------------- /examples/AuthDemo/Client/config.conf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #tarsregistry locator 6 | locator = tars.tarsregistry.QueryObj@tcp -h 127.0.0.1 -p 17890 7 | #max invoke timeout 8 | sync-invoke-timeout = 5000 9 | #refresh endpoint interval 10 | refresh-endpoint-interval = 10000 11 | #stat obj 12 | stat = tars.tarsstat.StatObj 13 | #max send queue length limit 14 | sendqueuelimit = 100000 15 | #async queue length limit 16 | asyncqueuecap = 100000 17 | #async callback thread num 18 | asyncthread = 3 19 | #net thread 20 | netthread = 1 21 | #merge net and sync thread 22 | mergenetasync = 0 23 | #module name 24 | modulename = TestApp.AuthClient 25 | 26 | 27 | #auth access key 28 | accesskey = tars-test-user 29 | #auth secret key 30 | secretkey = 123456 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /examples/AuthDemo/Server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("AuthServer" "") 2 | -------------------------------------------------------------------------------- /examples/AuthDemo/Server/Hello.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | module TestApp 18 | { 19 | 20 | interface Hello 21 | { 22 | int test(); 23 | int testHello(string sReq, out string sRsp); 24 | }; 25 | 26 | }; 27 | -------------------------------------------------------------------------------- /examples/AuthDemo/Server/HelloImp.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #include "HelloImp.h" 18 | #include "servant/Application.h" 19 | 20 | using namespace std; 21 | 22 | ////////////////////////////////////////////////////// 23 | void HelloImp::initialize() 24 | { 25 | //initialize servant here: 26 | //... 27 | } 28 | 29 | ////////////////////////////////////////////////////// 30 | void HelloImp::destroy() 31 | { 32 | //destroy servant here: 33 | //... 34 | } 35 | 36 | int HelloImp::testHello(const std::string &sReq, std::string &sRsp, tars::TarsCurrentPtr current) 37 | { 38 | // TLOGDEBUG("HelloImp::testHellosReq:"< 21 | #include "servant/Application.h" 22 | 23 | using namespace tars; 24 | 25 | /** 26 | * 27 | **/ 28 | class HelloServer : public Application 29 | { 30 | public: 31 | /** 32 | * 33 | **/ 34 | virtual ~HelloServer() {}; 35 | 36 | /** 37 | * 38 | **/ 39 | virtual void initialize(); 40 | 41 | /** 42 | * 43 | **/ 44 | virtual void destroyApp(); 45 | }; 46 | 47 | extern HelloServer g_app; 48 | 49 | //////////////////////////////////////////// 50 | #endif 51 | -------------------------------------------------------------------------------- /examples/ClientDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | build_tars_server("ClientDemo" "") 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/CoroutineDemo/AServer/AServant.tars: -------------------------------------------------------------------------------- 1 | 2 | module Test 3 | { 4 | 5 | interface AServant 6 | { 7 | int test(); 8 | 9 | int testInt(int iIn,out int iOut); 10 | 11 | int testStr(string sIn, out string sOut); 12 | }; 13 | 14 | }; 15 | -------------------------------------------------------------------------------- /examples/CoroutineDemo/AServer/AServer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _AServer_H_ 18 | #define _AServer_H_ 19 | 20 | #include 21 | #include "servant/Application.h" 22 | 23 | using namespace tars; 24 | 25 | /** 26 | * 27 | **/ 28 | class AServer : public Application 29 | { 30 | public: 31 | /** 32 | * 33 | **/ 34 | virtual ~AServer() {}; 35 | 36 | /** 37 | * 38 | **/ 39 | virtual void initialize(); 40 | 41 | /** 42 | * 43 | **/ 44 | virtual void destroyApp(); 45 | 46 | }; 47 | 48 | extern AServer g_app; 49 | 50 | //////////////////////////////////////////// 51 | #endif 52 | -------------------------------------------------------------------------------- /examples/CoroutineDemo/AServer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("CoroutineDemoAServer" "") 2 | -------------------------------------------------------------------------------- /examples/CoroutineDemo/BServer/BServant.tars: -------------------------------------------------------------------------------- 1 | 2 | module Test 3 | { 4 | 5 | interface BServant 6 | { 7 | int test(); 8 | 9 | int testCoroSerial(string sIn, out string sOut); 10 | 11 | int testCoroParallel(string sIn, out string sOut); 12 | 13 | }; 14 | 15 | }; 16 | -------------------------------------------------------------------------------- /examples/CoroutineDemo/BServer/BServer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _BServer_H_ 18 | #define _BServer_H_ 19 | 20 | #include 21 | #include "servant/Application.h" 22 | 23 | using namespace tars; 24 | 25 | /** 26 | * 27 | **/ 28 | class BServer : public Application 29 | { 30 | public: 31 | /** 32 | * 33 | **/ 34 | virtual ~BServer() {}; 35 | 36 | /** 37 | * 38 | **/ 39 | virtual void initialize(); 40 | 41 | /** 42 | * 43 | **/ 44 | virtual void destroyApp(); 45 | 46 | }; 47 | 48 | extern BServer g_app; 49 | 50 | //////////////////////////////////////////// 51 | #endif 52 | -------------------------------------------------------------------------------- /examples/CoroutineDemo/BServer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("CoroutineDemoBServer" "CoroutineDemoAServer") -------------------------------------------------------------------------------- /examples/CoroutineDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(AServer) 3 | add_subdirectory(AServer) 4 | 5 | include_directories(BServer) 6 | add_subdirectory(BServer) 7 | 8 | add_subdirectory(client) 9 | add_subdirectory(testCoro) 10 | add_subdirectory(testParallelCoro) 11 | 12 | -------------------------------------------------------------------------------- /examples/CoroutineDemo/README.md: -------------------------------------------------------------------------------- 1 | 该工程是Tars 协程编程示例的代码 2 | 3 | 4 | 目录名称 |功能 5 | -----------------|---------------- 6 | client/BServer/AServer | 协程编程的示例程序,client访问BServer,BServer用协程方式去并行和串行访问AServer 7 | testCoro/testParallelCoro | 协程编程的示例程序,自定义或者继承框架的协程类 8 | -------------------------------------------------------------------------------- /examples/CoroutineDemo/client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("CoroutineDemoClient" "CoroutineDemoAServer CoroutineDemoBServer") -------------------------------------------------------------------------------- /examples/CoroutineDemo/testCoro/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("testCoro" "CoroutineDemoAServer CoroutineDemoBServer") -------------------------------------------------------------------------------- /examples/CoroutineDemo/testParallelCoro/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("testParallelCoro" "CoroutineDemoAServer CoroutineDemoBServer") -------------------------------------------------------------------------------- /examples/CustomDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_subdirectory(CustomClient) 3 | add_subdirectory(CustomServer) 4 | 5 | -------------------------------------------------------------------------------- /examples/CustomDemo/CustomClient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("CustomClient" "CustomServer") -------------------------------------------------------------------------------- /examples/CustomDemo/CustomServer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("CustomServer" "") -------------------------------------------------------------------------------- /examples/CustomDemo/CustomServer/CustomServantImp.cpp: -------------------------------------------------------------------------------- 1 | #include "CustomServantImp.h" 2 | #include "servant/Application.h" 3 | 4 | using namespace std; 5 | 6 | ////////////////////////////////////////////////////// 7 | void CustomServantImp::initialize() 8 | { 9 | //initialize servant here: 10 | //... 11 | } 12 | 13 | ////////////////////////////////////////////////////// 14 | void CustomServantImp::destroy() 15 | { 16 | //destroy servant here: 17 | //... 18 | } 19 | 20 | 21 | int CustomServantImp::doRequest(tars::TarsCurrentPtr current, vector& response) 22 | { 23 | //Return to the data package requested by the client itself, that is, the original package return (4-byte length + 4-byte request + buffer) 24 | const vector& request = current->getRequestBuffer(); 25 | response = request; 26 | 27 | // cout << "doRequest: requestId:" << current->getRequestId() << ", funcName:" << current->getFuncName() << endl; 28 | return 0; 29 | } 30 | 31 | int CustomServantImp::doClose(TarsCurrentPtr current) 32 | { 33 | LOG->debug() << "close ip: " << current->getIp() << endl; 34 | 35 | return 0; 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /examples/CustomDemo/CustomServer/CustomServantImp.h: -------------------------------------------------------------------------------- 1 | #ifndef _CustomServantImp_H_ 2 | #define _CustomServantImp_H_ 3 | 4 | #include "servant/Application.h" 5 | //#include "CustomServant.h" 6 | 7 | /** 8 | * 9 | * 10 | */ 11 | class CustomServantImp : public tars::Servant 12 | { 13 | public: 14 | /** 15 | * 16 | */ 17 | virtual ~CustomServantImp() {} 18 | 19 | /** 20 | * 21 | */ 22 | virtual void initialize(); 23 | 24 | /** 25 | * 26 | */ 27 | virtual void destroy(); 28 | 29 | //overloading method of Servant::doRequest 30 | int doRequest(tars::TarsCurrentPtr current, vector& response); 31 | 32 | //overloading method of Servant::doClose 33 | int doClose(tars::TarsCurrentPtr current); 34 | 35 | }; 36 | ///////////////////////////////////////////////////// 37 | #endif 38 | -------------------------------------------------------------------------------- /examples/CustomDemo/CustomServer/CustomServer.h: -------------------------------------------------------------------------------- 1 | #ifndef _CustomServer_H_ 2 | #define _CustomServer_H_ 3 | 4 | #include 5 | #include "servant/Application.h" 6 | 7 | using namespace tars; 8 | 9 | /** 10 | * 11 | **/ 12 | class CustomServer : public Application 13 | { 14 | public: 15 | /** 16 | * 17 | **/ 18 | virtual ~CustomServer() {}; 19 | 20 | /** 21 | * 22 | **/ 23 | virtual void initialize(); 24 | 25 | /** 26 | * 27 | **/ 28 | virtual void destroyApp(); 29 | 30 | }; 31 | 32 | extern CustomServer g_app; 33 | 34 | //////////////////////////////////////////// 35 | #endif 36 | -------------------------------------------------------------------------------- /examples/CustomDemo/README.md: -------------------------------------------------------------------------------- 1 | 该工程是Tars快速入门示例的代码 2 | 3 | 4 | 目录名称 |功能 5 | -----------------|---------------- 6 | HelloServer | 开发快速入门的示例 7 | ProxyServer | 中转代理服务示例,作为HelloServer的代理服务 -------------------------------------------------------------------------------- /examples/GrpcDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(GrpcClient) 2 | add_subdirectory(GrpcServer) 3 | -------------------------------------------------------------------------------- /examples/GrpcDemo/GrpcClient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("GrpcClient" "GrpcServer") 2 | -------------------------------------------------------------------------------- /examples/GrpcDemo/GrpcClient/helloworld.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2015 gRPC authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | option java_multiple_files = true; 18 | option java_package = "io.grpc.examples.helloworld"; 19 | option java_outer_classname = "HelloWorldProto"; 20 | option objc_class_prefix = "HLW"; 21 | 22 | package helloworld; 23 | 24 | // The greeting service definition. 25 | service Greeter { 26 | // Sends a greeting 27 | rpc SayHello (HelloRequest) returns (HelloReply) {} 28 | } 29 | 30 | // The request message containing the user's name. 31 | message HelloRequest { 32 | string name = 1; 33 | } 34 | 35 | // The response message containing the greetings 36 | message HelloReply { 37 | string message = 1; 38 | } 39 | -------------------------------------------------------------------------------- /examples/GrpcDemo/GrpcServer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("GrpcServer" "") 2 | -------------------------------------------------------------------------------- /examples/GrpcDemo/GrpcServer/GrpcServer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _GrpcServer_H_ 18 | #define _GrpcServer_H_ 19 | 20 | #include 21 | #include "servant/Application.h" 22 | #include "util/tc_grpc.h" 23 | 24 | using namespace tars; 25 | 26 | /** 27 | * 28 | **/ 29 | class GrpcServer : public Application 30 | { 31 | public: 32 | /** 33 | * 34 | **/ 35 | virtual ~GrpcServer() {}; 36 | 37 | /** 38 | * 39 | **/ 40 | virtual void initialize(); 41 | 42 | /** 43 | * 44 | **/ 45 | virtual void destroyApp(); 46 | }; 47 | 48 | extern GrpcServer g_app; 49 | 50 | //////////////////////////////////////////// 51 | #endif 52 | -------------------------------------------------------------------------------- /examples/GrpcDemo/GrpcServer/helloworld.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2015 gRPC authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | option java_multiple_files = true; 18 | option java_package = "io.grpc.examples.helloworld"; 19 | option java_outer_classname = "HelloWorldProto"; 20 | option objc_class_prefix = "HLW"; 21 | 22 | package helloworld; 23 | 24 | // The greeting service definition. 25 | service Greeter { 26 | // Sends a greeting 27 | rpc SayHello (HelloRequest) returns (HelloReply) {} 28 | } 29 | 30 | // The request message containing the user's name. 31 | message HelloRequest { 32 | string name = 1; 33 | } 34 | 35 | // The response message containing the greetings 36 | message HelloReply { 37 | string message = 1; 38 | } 39 | -------------------------------------------------------------------------------- /examples/HttpDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_subdirectory(HttpClient) 3 | add_subdirectory(HttpServer) 4 | 5 | if(TARS_HTTP2) 6 | add_subdirectory(Http2Client) 7 | add_subdirectory(Http2Server) 8 | endif() -------------------------------------------------------------------------------- /examples/HttpDemo/Http2Client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("Http2Client" "Http2Server") 2 | -------------------------------------------------------------------------------- /examples/HttpDemo/Http2Server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("Http2Server" "") 2 | -------------------------------------------------------------------------------- /examples/HttpDemo/Http2Server/HttpServer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _HttpServer_H_ 18 | #define _HttpServer_H_ 19 | 20 | #include 21 | #include "servant/Application.h" 22 | 23 | using namespace tars; 24 | 25 | /** 26 | * 27 | **/ 28 | class HttpServer : public Application 29 | { 30 | public: 31 | /** 32 | * 33 | **/ 34 | virtual ~HttpServer() {}; 35 | 36 | /** 37 | * 38 | **/ 39 | virtual void initialize(); 40 | 41 | /** 42 | * 43 | **/ 44 | virtual void destroyApp(); 45 | }; 46 | 47 | extern HttpServer g_app; 48 | 49 | //////////////////////////////////////////// 50 | #endif 51 | -------------------------------------------------------------------------------- /examples/HttpDemo/HttpClient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #build_tars_server("HttpClient" "HttpServer") 2 | build_tars_server("HttpClient" "") -------------------------------------------------------------------------------- /examples/HttpDemo/HttpServer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("HttpServer" "") -------------------------------------------------------------------------------- /examples/HttpDemo/HttpServer/HttpImp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _HttpImp_H_ 18 | #define _HttpImp_H_ 19 | 20 | #include "servant/Application.h" 21 | 22 | /** 23 | * 24 | * 25 | */ 26 | class HttpImp : public Servant 27 | { 28 | public: 29 | /** 30 | * 31 | */ 32 | virtual ~HttpImp() {} 33 | 34 | /** 35 | * 36 | */ 37 | virtual void initialize(); 38 | 39 | /** 40 | * 41 | */ 42 | virtual void destroy(); 43 | 44 | /** 45 | * 46 | */ 47 | int doRequest(TarsCurrentPtr current, vector &buffer); 48 | 49 | }; 50 | ///////////////////////////////////////////////////// 51 | #endif 52 | -------------------------------------------------------------------------------- /examples/HttpDemo/HttpServer/HttpServer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _HttpServer_H_ 18 | #define _HttpServer_H_ 19 | 20 | #include 21 | #include "servant/Application.h" 22 | 23 | using namespace tars; 24 | 25 | /** 26 | * 27 | **/ 28 | class HttpServer : public Application 29 | { 30 | public: 31 | /** 32 | * 33 | **/ 34 | virtual ~HttpServer() {}; 35 | 36 | /** 37 | * 38 | **/ 39 | virtual void initialize(); 40 | 41 | /** 42 | * 43 | **/ 44 | virtual void destroyApp(); 45 | 46 | private: 47 | void onNewClient(TC_EpollServer::Connection*); 48 | }; 49 | 50 | extern HttpServer g_app; 51 | 52 | //////////////////////////////////////////// 53 | #endif 54 | -------------------------------------------------------------------------------- /examples/PromiseDemo/AServer/AServant.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | module Test 18 | { 19 | 20 | interface AServant 21 | { 22 | int queryResultSerial(string sIn, out string sOut); 23 | 24 | int queryResultParallel(string sIn, out string sOut); 25 | }; 26 | 27 | }; 28 | -------------------------------------------------------------------------------- /examples/PromiseDemo/AServer/AServer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _BServer_H_ 18 | #define _BServer_H_ 19 | 20 | #include 21 | #include "servant/Application.h" 22 | 23 | using namespace tars; 24 | 25 | /** 26 | * 27 | **/ 28 | class AServer : public Application 29 | { 30 | public: 31 | /** 32 | * 33 | **/ 34 | virtual ~AServer() {}; 35 | 36 | /** 37 | * 38 | **/ 39 | virtual void initialize(); 40 | 41 | /** 42 | * 43 | **/ 44 | virtual void destroyApp(); 45 | protected: 46 | bool cmdprofile(const string& command, const string& params, string& result); 47 | }; 48 | 49 | extern AServer g_app; 50 | 51 | //////////////////////////////////////////// 52 | #endif 53 | -------------------------------------------------------------------------------- /examples/PromiseDemo/AServer/BServant.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | module Test 18 | { 19 | 20 | interface BServant 21 | { 22 | int queryResult(string sIn, out string sOut); 23 | }; 24 | 25 | }; 26 | -------------------------------------------------------------------------------- /examples/PromiseDemo/AServer/CServant.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | module Test 18 | { 19 | 20 | interface CServant 21 | { 22 | int queryResult(string sIn, out string sOut); 23 | }; 24 | 25 | }; 26 | -------------------------------------------------------------------------------- /examples/PromiseDemo/AServer/makefile: -------------------------------------------------------------------------------- 1 | 2 | #----------------------------------------------------------------------- 3 | APP := Test 4 | TARGET := AServer 5 | CONFIG := 6 | STRIP_FLAG:= N 7 | 8 | INCLUDE += 9 | 10 | #----------------------------------------------------------------------- 11 | include /usr/local/tars/cpp/makefile/makefile.tars 12 | #----------------------------------------------------------------------- 13 | -------------------------------------------------------------------------------- /examples/PromiseDemo/BServer/BServant.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | module Test 18 | { 19 | 20 | interface BServant 21 | { 22 | int queryResult(string sIn, out string sOut); 23 | }; 24 | 25 | }; 26 | -------------------------------------------------------------------------------- /examples/PromiseDemo/BServer/BServantImp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _BServantImp_H_ 18 | #define _BServantImp_H_ 19 | 20 | #include "servant/Application.h" 21 | #include "BServant.h" 22 | #include "promise/promise.h" 23 | 24 | using namespace Test; 25 | 26 | class BServantImp : public Test::BServant 27 | { 28 | public: 29 | 30 | virtual ~BServantImp() {} 31 | 32 | virtual void initialize(); 33 | 34 | virtual void destroy(); 35 | 36 | tars::Int32 queryResult(const std::string& sIn, std::string &sOut, tars::TarsCurrentPtr current); 37 | 38 | }; 39 | ///////////////////////////////////////////////////// 40 | #endif 41 | -------------------------------------------------------------------------------- /examples/PromiseDemo/BServer/BServer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _BServer_H_ 18 | #define _BServer_H_ 19 | 20 | #include 21 | #include "servant/Application.h" 22 | 23 | using namespace tars; 24 | 25 | /** 26 | * 27 | **/ 28 | class BServer : public Application 29 | { 30 | public: 31 | /** 32 | * 33 | **/ 34 | virtual ~BServer() {}; 35 | 36 | /** 37 | * 38 | **/ 39 | virtual void initialize(); 40 | 41 | /** 42 | * 43 | **/ 44 | virtual void destroyApp(); 45 | protected: 46 | bool cmdprofile(const string& command, const string& params, string& result); 47 | }; 48 | 49 | extern BServer g_app; 50 | 51 | //////////////////////////////////////////// 52 | #endif 53 | -------------------------------------------------------------------------------- /examples/PromiseDemo/BServer/makefile: -------------------------------------------------------------------------------- 1 | #----------------------------------------------------------------------- 2 | 3 | APP := Test 4 | TARGET := BServer 5 | CONFIG := 6 | STRIP_FLAG:= N 7 | INCLUDE += 8 | 9 | #----------------------------------------------------------------------- 10 | include /usr/local/tars/cpp/makefile/makefile.tars 11 | #----------------------------------------------------------------------- 12 | -------------------------------------------------------------------------------- /examples/PromiseDemo/CServer/CServant.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | module Test 18 | { 19 | 20 | interface CServant 21 | { 22 | int queryResult(string sIn, out string sOut); 23 | }; 24 | 25 | }; 26 | -------------------------------------------------------------------------------- /examples/PromiseDemo/CServer/CServantImp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _BServantImp_H_ 18 | #define _BServantImp_H_ 19 | 20 | #include "servant/Application.h" 21 | #include "CServant.h" 22 | #include "promise/promise.h" 23 | 24 | using namespace Test; 25 | 26 | class CServantImp : public Test::CServant 27 | { 28 | public: 29 | 30 | virtual ~CServantImp() {} 31 | 32 | virtual void initialize(); 33 | 34 | virtual void destroy(); 35 | 36 | tars::Int32 queryResult(const std::string& sIn, std::string &sOut, tars::TarsCurrentPtr current); 37 | 38 | }; 39 | ///////////////////////////////////////////////////// 40 | #endif 41 | -------------------------------------------------------------------------------- /examples/PromiseDemo/CServer/CServer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _BServer_H_ 18 | #define _BServer_H_ 19 | 20 | #include 21 | #include "servant/Application.h" 22 | 23 | using namespace tars; 24 | 25 | /** 26 | * * 27 | * **/ 28 | class CServer : public Application 29 | { 30 | public: 31 | /** 32 | * 33 | **/ 34 | virtual ~CServer() {}; 35 | 36 | /** 37 | * 38 | **/ 39 | virtual void initialize(); 40 | 41 | /** 42 | * 43 | **/ 44 | virtual void destroyApp(); 45 | protected: 46 | bool cmdprofile(const string& command, const string& params, string& result); 47 | }; 48 | 49 | extern CServer g_app; 50 | 51 | //////////////////////////////////////////// 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /examples/PromiseDemo/CServer/makefile: -------------------------------------------------------------------------------- 1 | #----------------------------------------------------------------------- 2 | APP := Test 3 | TARGET := CServer 4 | CONFIG := 5 | STRIP_FLAG:= N 6 | 7 | INCLUDE += 8 | 9 | #----------------------------------------------------------------------- 10 | include /usr/local/tars/cpp/makefile/makefile.tars 11 | #----------------------------------------------------------------------- 12 | -------------------------------------------------------------------------------- /examples/PromiseDemo/Client/makefile: -------------------------------------------------------------------------------- 1 | 2 | #----------------------------------------------------------------------- 3 | APP := Test 4 | TARGET := myClientPromise 5 | CONFIG := 6 | STRIP_FLAG:= N 7 | 8 | INCLUDE += 9 | 10 | #----------------------------------------------------------------------- 11 | include /home/tarsproto/Test/AServer/AServer.mk 12 | include /usr/local/tars/cpp/makefile/makefile.tars 13 | #----------------------------------------------------------------------- 14 | -------------------------------------------------------------------------------- /examples/PromiseDemo/README.md: -------------------------------------------------------------------------------- 1 | 该工程是Tars promise编程示例的代码 2 | 3 | 4 | 目录名称 |功能 5 | -----------------|---------------- 6 | AServer | promise编程的示例程序,用promsie方式去并行和串行访问BServer和CServer 7 | -------------------------------------------------------------------------------- /examples/PushCallbackDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(Server) 3 | add_subdirectory(Server) 4 | add_subdirectory(Client) 5 | 6 | -------------------------------------------------------------------------------- /examples/PushCallbackDemo/Client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("PushCallbackClient" "PushCallbackServer") -------------------------------------------------------------------------------- /examples/PushCallbackDemo/Client/config.conf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #tarsregistry locator 6 | locator = tars.tarsregistry.QueryObj@tcp -h 127.0.0.1 -p 17890 7 | #max invoke timeout 8 | sync-invoke-timeout = 5000 9 | #refresh endpoint interval 10 | refresh-endpoint-interval = 10000 11 | #stat obj 12 | stat = tars.tarsstat.StatObj 13 | #max send queue length limit 14 | sendqueuelimit = 100000 15 | #async queue length limit 16 | asyncqueuecap = 100000 17 | #async callback thread num 18 | asyncthread = 3 19 | #net thread 20 | netthread = 1 21 | #merge net and sync thread 22 | mergenetasync = 0 23 | #module name 24 | modulename = TestApp.AuthClient 25 | 26 | 27 | #auth access key 28 | accesskey = tars-test-user 29 | #auth secret key 30 | secretkey = 123456 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /examples/PushCallbackDemo/Server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("PushCallbackServer" "") 2 | -------------------------------------------------------------------------------- /examples/PushCallbackDemo/Server/Hello.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | module TestApp 18 | { 19 | 20 | interface Hello 21 | { 22 | int registerPush(); 23 | }; 24 | 25 | }; 26 | -------------------------------------------------------------------------------- /examples/PushCallbackDemo/Server/HelloImp.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #include "HelloImp.h" 18 | #include "servant/Application.h" 19 | #include "HelloServer.h" 20 | 21 | using namespace std; 22 | 23 | ////////////////////////////////////////////////////// 24 | void HelloImp::initialize() 25 | { 26 | //initialize servant here: 27 | //... 28 | } 29 | 30 | ////////////////////////////////////////////////////// 31 | void HelloImp::destroy() 32 | { 33 | //destroy servant here: 34 | //... 35 | } 36 | 37 | int HelloImp::doClose(tars::TarsCurrentPtr current) 38 | { 39 | g_app._pushThread.delCurrent(current); 40 | return 0; 41 | } 42 | 43 | int HelloImp::registerPush(tars::TarsCurrentPtr current) 44 | { 45 | g_app._pushThread.addCurrent(current); 46 | return 0; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /examples/PushCallbackDemo/Server/HelloServer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _HelloServer_H_ 18 | #define _HelloServer_H_ 19 | 20 | #include 21 | #include "servant/Application.h" 22 | #include "PushThread.h" 23 | 24 | using namespace tars; 25 | 26 | /** 27 | * 28 | **/ 29 | class HelloServer : public Application 30 | { 31 | public: 32 | /** 33 | * 34 | **/ 35 | virtual ~HelloServer() {}; 36 | 37 | /** 38 | * 39 | **/ 40 | virtual void initialize(); 41 | 42 | /** 43 | * 44 | **/ 45 | virtual void destroyApp(); 46 | 47 | PushThread _pushThread; 48 | }; 49 | 50 | extern HelloServer g_app; 51 | 52 | //////////////////////////////////////////// 53 | #endif 54 | -------------------------------------------------------------------------------- /examples/PushCallbackDemo/Server/Push.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | module TestApp 18 | { 19 | 20 | interface Push 21 | { 22 | int pushMsg(out string sRsp); 23 | }; 24 | 25 | }; 26 | -------------------------------------------------------------------------------- /examples/PushCallbackDemo/Server/PushThread.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by jarod on 2022/9/7. 3 | // 4 | 5 | #include "PushThread.h" 6 | #include "Push.h" 7 | 8 | void PushThread::terminate() 9 | { 10 | std::lock_guard lock(_mutex); 11 | _terminate = true; 12 | _cond.notify_one(); 13 | 14 | } 15 | 16 | void PushThread::addCurrent(CurrentPtr ¤t) 17 | { 18 | std::lock_guard lock(_mutex); 19 | 20 | _currents[current->getUId()] = current; 21 | } 22 | 23 | void PushThread::delCurrent(CurrentPtr ¤t) 24 | { 25 | std::lock_guard lock(_mutex); 26 | 27 | _currents.erase(current->getUId()); 28 | } 29 | 30 | void PushThread::run() 31 | { 32 | while(!_terminate) 33 | { 34 | std::unique_lock lock(_mutex); 35 | 36 | for(auto it : _currents) 37 | { 38 | TestApp::Push::async_response_push_pushMsg(it.second, 0, "push message"); 39 | } 40 | 41 | _cond.wait_for(lock, std::chrono::milliseconds(1000)); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /examples/PushCallbackDemo/Server/PushThread.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by jarod on 2022/9/7. 3 | // 4 | 5 | #ifndef FRAMEWORK_PUSHTHREAD_H 6 | #define FRAMEWORK_PUSHTHREAD_H 7 | 8 | #include 9 | #include "util/tc_thread.h" 10 | #include "servant/Application.h" 11 | using namespace tars; 12 | 13 | class PushThread : public TC_Thread 14 | { 15 | public: 16 | void addCurrent(CurrentPtr ¤t); 17 | void delCurrent(CurrentPtr ¤t); 18 | 19 | void terminate(); 20 | protected: 21 | virtual void run(); 22 | 23 | protected: 24 | bool _terminate = false; 25 | std::mutex _mutex; 26 | std::condition_variable _cond; 27 | map _currents; 28 | }; 29 | 30 | 31 | 32 | #endif //FRAMEWORK_PUSHTHREAD_H 33 | -------------------------------------------------------------------------------- /examples/PushDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_subdirectory(PushClient) 3 | add_subdirectory(PushServer) 4 | 5 | -------------------------------------------------------------------------------- /examples/PushDemo/PushClient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("PushClient" "PushServer") -------------------------------------------------------------------------------- /examples/PushDemo/PushClient/TestRecvThread.h: -------------------------------------------------------------------------------- 1 | #ifndef __TEST_RECV_THREAD_H 2 | #define __TEST_RECV_THREAD_H 3 | 4 | #include "servant/Application.h" 5 | 6 | class TestPushCallBack : public ServantProxyCallback 7 | { 8 | public: 9 | virtual int onDispatch(ReqMessagePtr msg); 10 | }; 11 | 12 | typedef tars::TC_AutoPtr TestPushCallBackPtr; 13 | 14 | class RecvThread : public TC_Thread, public TC_ThreadLock 15 | { 16 | public: 17 | RecvThread(int second); 18 | 19 | virtual void run(); 20 | 21 | private: 22 | int _second; 23 | bool _bTerminate; 24 | 25 | Communicator _comm; 26 | 27 | ServantPrx _prx; 28 | }; 29 | #endif 30 | -------------------------------------------------------------------------------- /examples/PushDemo/PushClient/main.cpp: -------------------------------------------------------------------------------- 1 | #include "servant/Application.h" 2 | #include "TestRecvThread.h" 3 | #include 4 | 5 | using namespace std; 6 | using namespace tars; 7 | 8 | int main(int argc,char**argv) 9 | { 10 | try 11 | { 12 | int second = 5; 13 | 14 | if(argc > 1) 15 | second = TC_Common::strto(argv[1]); 16 | 17 | if(second <=0 ) 18 | second = 1; 19 | 20 | RecvThread thread(second); 21 | thread.start(); 22 | 23 | thread.getThreadControl().join(); 24 | } 25 | catch(std::exception&e) 26 | { 27 | cerr<<"std::exception:"<& response); 37 | 38 | //重载Servant的doClose方法 39 | int doClose(tars::TarsCurrentPtr current); 40 | 41 | }; 42 | ///////////////////////////////////////////////////// 43 | #endif 44 | -------------------------------------------------------------------------------- /examples/PushDemo/PushServer/TestPushServer.h: -------------------------------------------------------------------------------- 1 | #ifndef _TestPushServer_H_ 2 | #define _TestPushServer_H_ 3 | 4 | #include 5 | #include "servant/Application.h" 6 | #include "TestPushThread.h" 7 | 8 | 9 | using namespace tars; 10 | 11 | /** 12 | * 13 | **/ 14 | class TestPushServer : public Application 15 | { 16 | public: 17 | /** 18 | * 19 | **/ 20 | virtual ~TestPushServer() {}; 21 | 22 | /** 23 | * 24 | **/ 25 | virtual void initialize(); 26 | 27 | /** 28 | * 29 | **/ 30 | virtual void destroyApp(); 31 | 32 | private: 33 | //用于push消息的线程 34 | PushInfoThread pushThread; 35 | 36 | }; 37 | 38 | extern TestPushServer g_app; 39 | 40 | //////////////////////////////////////////// 41 | #endif 42 | -------------------------------------------------------------------------------- /examples/PushDemo/PushServer/TestPushThread.h: -------------------------------------------------------------------------------- 1 | #ifndef __TEST_PUSH_THREAD_H 2 | #define __TEST_PUSH_THREAD_H 3 | 4 | #include "servant/Application.h" 5 | 6 | class PushUser 7 | { 8 | public: 9 | static map pushUser; 10 | static TC_ThreadMutex mapMutex; 11 | }; 12 | 13 | class PushInfoThread : public TC_Thread, public TC_ThreadLock 14 | { 15 | public: 16 | PushInfoThread():_bTerminate(false), _iId(0){} 17 | 18 | virtual void run(); 19 | 20 | void terminate(); 21 | 22 | void setPushInfo(const string &sInfo); 23 | 24 | private: 25 | bool _bTerminate; 26 | unsigned int _iId; 27 | string _sPushInfo; 28 | }; 29 | #endif 30 | -------------------------------------------------------------------------------- /examples/PushDemo/README.md: -------------------------------------------------------------------------------- 1 | 该工程是Tars快速入门示例的代码 2 | 3 | 4 | 目录名称 |功能 5 | -----------------|---------------- 6 | HelloServer | 开发快速入门的示例 7 | ProxyServer | 中转代理服务示例,作为HelloServer的代理服务 -------------------------------------------------------------------------------- /examples/QuickStartDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(HelloServer/Server) 3 | add_subdirectory(HelloServer) 4 | add_subdirectory(ProxyServer) 5 | 6 | -------------------------------------------------------------------------------- /examples/QuickStartDemo/HelloServer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(Server) 3 | add_subdirectory(Server) 4 | add_subdirectory(Client) -------------------------------------------------------------------------------- /examples/QuickStartDemo/HelloServer/Client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("QuickStartDemoClient" "QuickStartDemo") -------------------------------------------------------------------------------- /examples/QuickStartDemo/HelloServer/Server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("QuickStartDemo" "") 2 | -------------------------------------------------------------------------------- /examples/QuickStartDemo/HelloServer/Server/Hello.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | module TestApp 18 | { 19 | 20 | interface Hello 21 | { 22 | int test(); 23 | int testHello(string sReq, out string sRsp); 24 | }; 25 | 26 | }; 27 | -------------------------------------------------------------------------------- /examples/QuickStartDemo/HelloServer/Server/HelloServer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _HelloServer_H_ 18 | #define _HelloServer_H_ 19 | 20 | #include 21 | #include "servant/Application.h" 22 | 23 | using namespace tars; 24 | 25 | /** 26 | * 27 | **/ 28 | class HelloServer : public Application 29 | { 30 | public: 31 | /** 32 | * 33 | **/ 34 | virtual ~HelloServer() {}; 35 | 36 | /** 37 | * 38 | **/ 39 | virtual void initialize(); 40 | 41 | /** 42 | * 43 | **/ 44 | virtual void destroyApp(); 45 | }; 46 | 47 | extern HelloServer g_app; 48 | 49 | //////////////////////////////////////////// 50 | #endif 51 | -------------------------------------------------------------------------------- /examples/QuickStartDemo/ProxyServer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(Server) 3 | add_subdirectory(Server) 4 | add_subdirectory(Client) 5 | 6 | -------------------------------------------------------------------------------- /examples/QuickStartDemo/ProxyServer/Client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("ProxyServerClient" "ProxyServer") -------------------------------------------------------------------------------- /examples/QuickStartDemo/ProxyServer/Server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("ProxyServer" "") 2 | 3 | 4 | -------------------------------------------------------------------------------- /examples/QuickStartDemo/ProxyServer/Server/Proxy.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | module TestApp 18 | { 19 | 20 | interface Proxy 21 | { 22 | int test(); 23 | int testProxy(string sReq, out string sRsp); 24 | }; 25 | 26 | }; 27 | -------------------------------------------------------------------------------- /examples/QuickStartDemo/ProxyServer/Server/ProxyServer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __PROXY_SERVER_H_ 18 | #define __PROXY_SERVER_H_ 19 | 20 | #include 21 | #include "servant/Application.h" 22 | 23 | using namespace tars; 24 | 25 | /** 26 | * 27 | **/ 28 | class ProxyServer : public Application 29 | { 30 | public: 31 | /** 32 | * 33 | **/ 34 | virtual ~ProxyServer() {}; 35 | 36 | /** 37 | * 38 | **/ 39 | virtual void initialize(); 40 | 41 | /** 42 | * 43 | **/ 44 | virtual void destroyApp(); 45 | protected: 46 | 47 | }; 48 | 49 | extern ProxyServer g_app; 50 | 51 | //////////////////////////////////////////// 52 | #endif 53 | -------------------------------------------------------------------------------- /examples/QuickStartDemo/README.md: -------------------------------------------------------------------------------- 1 | 该工程是Tars快速入门示例的代码 2 | 3 | 4 | 目录名称 |功能 5 | -----------------|---------------- 6 | HelloServer | 开发快速入门的示例 7 | ProxyServer | 中转代理服务示例,作为HelloServer的代理服务 -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | 该工程是Tars入门示例的代码 2 | 3 | 4 | 目录名称 |功能 5 | -----------------|---------------- 6 | [QuickStartDemo](https://github.com/TarsCloud/TarsCpp/tree/d687aae51a016c313812c973ec75ab4cad7fbcaa/examples/QuickStartDemo) | 开发快速入门的示例 7 | [PromiseDemo](https://github.com/TarsCloud/TarsCpp/tree/d687aae51a016c313812c973ec75ab4cad7fbcaa/examples/PromiseDemo) | promise编程的示例[] 8 | [HttpDemo](https://github.com/TarsCloud/TarsCpp/tree/d687aae51a016c313812c973ec75ab4cad7fbcaa/examples/HttpDemo) | http服务端的示例 9 | [CoroutineDemo](https://github.com/TarsCloud/TarsCpp/tree/d687aae51a016c313812c973ec75ab4cad7fbcaa/examples/CoroutineDemo) | 协程的示例 10 | [StressDemo](https://github.com/TarsCloud/TarsCpp/tree/d687aae51a016c313812c973ec75ab4cad7fbcaa/examples/StressDemo) | tars c++压测代码 11 | [PushDemo](https://github.com/TarsCloud/TarsCpp/tree/d687aae51a016c313812c973ec75ab4cad7fbcaa/examples/PushDemo) | tars push 模式demo -------------------------------------------------------------------------------- /examples/SSLDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(Server) 3 | add_subdirectory(Server) 4 | add_subdirectory(Client) 5 | 6 | -------------------------------------------------------------------------------- /examples/SSLDemo/Client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("SSLClient" "SSLServer") -------------------------------------------------------------------------------- /examples/SSLDemo/Server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("SSLServer" "") 2 | -------------------------------------------------------------------------------- /examples/SSLDemo/Server/SSLImp.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #include "SSLImp.h" 18 | #include "servant/Application.h" 19 | 20 | using namespace std; 21 | 22 | ////////////////////////////////////////////////////// 23 | void SSLImp::initialize() 24 | { 25 | //initialize servant here: 26 | //... 27 | } 28 | 29 | ////////////////////////////////////////////////////// 30 | void SSLImp::destroy() 31 | { 32 | //destroy servant here: 33 | //... 34 | } 35 | 36 | int SSLImp::testHello(const std::string &sReq, std::string &sRsp, tars::TarsCurrentPtr current) 37 | { 38 | // TLOGDEBUG("SSLImp::testHellosReq:"< 21 | #include "servant/Application.h" 22 | 23 | using namespace tars; 24 | 25 | /** 26 | * 27 | **/ 28 | class SSLServer : public Application 29 | { 30 | public: 31 | /** 32 | * 33 | **/ 34 | virtual ~SSLServer() {}; 35 | 36 | /** 37 | * 38 | **/ 39 | virtual void initialize(); 40 | 41 | /** 42 | * 43 | **/ 44 | virtual void destroyApp(); 45 | }; 46 | 47 | extern SSLServer g_app; 48 | 49 | //////////////////////////////////////////// 50 | #endif 51 | -------------------------------------------------------------------------------- /examples/SSLDemo/Server/ssl.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | module TestApp 18 | { 19 | 20 | interface Hello 21 | { 22 | int test(); 23 | int testHello(string sReq, out string sRsp); 24 | }; 25 | 26 | }; 27 | -------------------------------------------------------------------------------- /examples/SSLDemo/certs/ca.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDCzCCAfOgAwIBAgIUblg0MMUtu1YdIF1CmdlcKCXdg5gwDQYJKoZIhvcNAQEL 3 | BQAwFTETMBEGA1UEAwwKKi5kZW1vLmNvbTAeFw0yMDAyMTQxMjQ5MDVaFw0zMzEw 4 | MjMxMjQ5MDVaMBUxEzARBgNVBAMMCiouZGVtby5jb20wggEiMA0GCSqGSIb3DQEB 5 | AQUAA4IBDwAwggEKAoIBAQCv8i3rLGi7j1E62fvpZ+9DI0kz6ASNOrmphzHS/E9p 6 | X7EijiLpat+YARsYC42qA4+Cky1ItDTASUAkvVZNCj+6TNsFx1LSesgE28roOBOi 7 | qXCtwBIQvAJBPRpgZtX5++BWyxexBsHszp8t1k7QKgVY3eXeGCQHOHZZltXNFGKP 8 | 2hruxct2VEcZWqWdYKE1hy0GSyxvejsT2GLv2OMlWwD/iE+UvTKU5+9CTq/vfx3j 9 | vGUo410DniMz1OqqxAAamKhx4lzKvPfZeW/CQe929qwQONxGQENRXKiCiPkMTRIo 10 | JCdXBDS6ztolq4URIB57yCq88qMO8ZY6URA6U97qyhlJAgMBAAGjUzBRMB0GA1Ud 11 | DgQWBBSAwN6/0NtVoAWC7TB9PnYMzJhMJTAfBgNVHSMEGDAWgBSAwN6/0NtVoAWC 12 | 7TB9PnYMzJhMJTAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBX 13 | rGw19azPpFebPM5WHOUNBF5CesevnE4md0lE/9DcXl1wSLAwJC7bVijqt/gA4AgO 14 | i+7AnVxlrrMZ4UBEgMu8cHyAGuaC/u+wSJ49TpciMk3/bKfN1gnQ1O/bzm8zpP/B 15 | zQmffhiQcuM1wqStQeTnqD7bP4vAQKqLZGb0Hca2dPsRYIgW+z1dxLg6dxrFlkG8 16 | dunwDDQXsnYf3PcB2fMQuK1lJltiiu7sVe+XeFeRTFSDGyxDs9q28SwRIHWlzIIC 17 | j+57DkNAgBf9aYf7QM2dnmFNMHSs9fP8MZX7kltu5GadJKprDbjBtJd4IWSCMOv5 18 | A/fdjurUkf3aCj1qGj+o 19 | -----END CERTIFICATE----- 20 | -------------------------------------------------------------------------------- /examples/SSLDemo/certs/ca.srl: -------------------------------------------------------------------------------- 1 | 5C1561567852EF51D268687494029145127A56C7 2 | -------------------------------------------------------------------------------- /examples/SSLDemo/certs/client.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICsTCCAZkCFFwVYVZ4Uu9R0mhodJQCkUUSelbFMA0GCSqGSIb3DQEBCwUAMBUx 3 | EzARBgNVBAMMCiouZGVtby5jb20wHhcNMjAwMjE0MTI0OTA2WhcNMzMxMDIzMTI0 4 | OTA2WjAVMRMwEQYDVQQDDAoqLmRlbW8uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOC 5 | AQ8AMIIBCgKCAQEAzXLpEt1TWXzwWx6eQPGztqo7MSx8r3vxh5l5Wm45tRTNXot8 6 | eh7QWvJChflUlnz9y0J7O2SxFnjdpHrp29AkLlt/aRjvRfLfgDcc7LqfUpWcc3qz 7 | bkYPnktywXAuA1R3JnnsrDKFiwPY5Fc0bVuiZ0VZD9ufalvoc+kd3PjeQYvYkvUa 8 | axZ0iaxKs5PaKwYIKW7RsWQa2bNkArH+slet50JDbDXuZXEnPghBLyjAhkhPmLQ8 9 | jjrMX1t4fl0qQ21/q7TDf4FL+QNTcmEWQFEpz2H3qhM+J8UU2JdW36p+++Nj3CaF 10 | lcWpCpxqJ8UGMqCfTM+KcPmBg/UQ/ByRb0wiqwIDAQABMA0GCSqGSIb3DQEBCwUA 11 | A4IBAQBMED94VcdZJwznIJ3FOyv+8D7P9PYS1KvIVclsC1G2Wzrhohx4sMcCE4QE 12 | 43TJDc0Vj/fQR+g3IyPL3TTWofLuif/Pp+7t2mieST7USrIWPJuUYYdkbch/WUEX 13 | +p9vzdKJOnClCcdcMIptUJdHd7/X+qHPo0m4xg8qEfkW79IvcOQqAcl0Mx+Lxiny 14 | Xps3VTe7j6IOdv4ZycD0OtYj3RSoQPfjWZ8yFV7riYjd0hj05sG/CNJ/9Nvy34tn 15 | xRZnlWzMziOqYK+U/2BS1+j+LrfMJCgeShGdmBziqMde99Vovj2dv7sDvXqfZfCz 16 | jLWfPO5ShCU72n7MoM/yqsTD8FmS 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /examples/SSLDemo/certs/client.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICWjCCAUICAQAwFTETMBEGA1UEAwwKKi5kZW1vLmNvbTCCASIwDQYJKoZIhvcN 3 | AQEBBQADggEPADCCAQoCggEBAM1y6RLdU1l88FsenkDxs7aqOzEsfK978YeZeVpu 4 | ObUUzV6LfHoe0FryQoX5VJZ8/ctCeztksRZ43aR66dvQJC5bf2kY70Xy34A3HOy6 5 | n1KVnHN6s25GD55LcsFwLgNUdyZ57KwyhYsD2ORXNG1bomdFWQ/bn2pb6HPpHdz4 6 | 3kGL2JL1GmsWdImsSrOT2isGCClu0bFkGtmzZAKx/rJXredCQ2w17mVxJz4IQS8o 7 | wIZIT5i0PI46zF9beH5dKkNtf6u0w3+BS/kDU3JhFkBRKc9h96oTPifFFNiXVt+q 8 | fvvjY9wmhZXFqQqcaifFBjKgn0zPinD5gYP1EPwckW9MIqsCAwEAAaAAMA0GCSqG 9 | SIb3DQEBCwUAA4IBAQCG6KZeU22DzRgfoljtuyPNuONyBPLsDbT2nhM8UFNS7Io9 10 | hJYIn5FA57PC6vfJOPW4lvg5c73pjccJlLMYzPZ/TwvxUwcQzjeebZeRpPCB2fgQ 11 | ihX/6pyN0s2Li2WK8dNq02y0bH+f+ItftCoFnrhJPfNxObaSpNQh7rIbkxujOprG 12 | wqPmVFvEydzPwFwe6O42b2Ame+qdjva9QH4nbd8dG47kKCVhP8CMq8UbMvngVcbn 13 | 9A5dg4mS3OnTAdR21bNlZGQVHTiojKd3go7KrFwMlcRrCZ63+M510wIpUBxmFClA 14 | icfaUazi62EikDnnFExu60xQ8MpWL9U57foKV8ci 15 | -----END CERTIFICATE REQUEST----- 16 | -------------------------------------------------------------------------------- /examples/SSLDemo/certs/client1.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICsTCCAZkCFFwVYVZ4Uu9R0mhodJQCkUUSelbHMA0GCSqGSIb3DQEBCwUAMBUx 3 | EzARBgNVBAMMCiouZGVtby5jb20wHhcNMjAwMjE0MTI0OTA2WhcNMzMxMDIzMTI0 4 | OTA2WjAVMRMwEQYDVQQDDAoqLmRlbW8uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOC 5 | AQ8AMIIBCgKCAQEA7Qw+OBtzkGG38r4IOBzgpJte5qHPCTBCeowt/6dmwY3W+1bU 6 | cf5wdHBtSsuv3M5OpWKCG8gu3gpBZQvpz7MfN50ouuM0sDvKUxIUP2KX/nv7uiDg 7 | R4iJy47M4XSH2qbRovKPZeRCeigkiU4gKMnJ0Vx82EgEdOLzBt1wLL8a0q1zVOwC 8 | stII/0d4VhCoWgurddJa1gU7EwQ+ZRLwSbbvtgsEfVYCvwC/gb3fGrljJ2PpeY2/ 9 | UfxggnqGcG0IZoT4zi0uyRgK094nPVupS9JM5ig4I/FpP+KQ1LTlDh9LrwZrCQXj 10 | /DFp0Wka5DWHTXWb7TwZShFo3r3emD3gGZi0owIDAQABMA0GCSqGSIb3DQEBCwUA 11 | A4IBAQB9+YqEgsabF3hh3OBFZmg0Je12mkFBsMCRPwMOXfEY8Mzt7xVHHx5iKsBa 12 | u3XaLhVnOgu6VryGSIRmD7lGMctfIELysWu5xQtoY+m9xWZfDhY8G9sNhLSShJ/H 13 | 7UZ5/FUi+meohIM0SHEdzTyQtBSs+lfhgshsgtpZ4ysZDQTM/ukuOyBf1vXcs+Gx 14 | pQa4hDQ+Tnev0h6z4PIDCeg88KohDgrzFMSFZ04bNUSLeIxjgo47hLxVNa/3xokh 15 | yaTz4QZ3OcOjjfw//5lyfLDAZ7Rk1FBZ+NjdGRPjmTVIic2utT4QwS8aQyqDN/jA 16 | gxo1xb+Tu5YxHXkMGa2hwV3VvhkF 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /examples/SSLDemo/certs/client1.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICWjCCAUICAQAwFTETMBEGA1UEAwwKKi5kZW1vLmNvbTCCASIwDQYJKoZIhvcN 3 | AQEBBQADggEPADCCAQoCggEBAO0MPjgbc5Bht/K+CDgc4KSbXuahzwkwQnqMLf+n 4 | ZsGN1vtW1HH+cHRwbUrLr9zOTqVighvILt4KQWUL6c+zHzedKLrjNLA7ylMSFD9i 5 | l/57+7og4EeIicuOzOF0h9qm0aLyj2XkQnooJIlOICjJydFcfNhIBHTi8wbdcCy/ 6 | GtKtc1TsArLSCP9HeFYQqFoLq3XSWtYFOxMEPmUS8Em277YLBH1WAr8Av4G93xq5 7 | Yydj6XmNv1H8YIJ6hnBtCGaE+M4tLskYCtPeJz1bqUvSTOYoOCPxaT/ikNS05Q4f 8 | S68GawkF4/wxadFpGuQ1h011m+08GUoRaN693pg94BmYtKMCAwEAAaAAMA0GCSqG 9 | SIb3DQEBCwUAA4IBAQDrJMiKZIriezIo2PaJzm1Da4vcB41oiFVQGZuFRRN7Mt9t 10 | tMDuZeVILSqkT1zHu0lamGuS/SKk1VSV0Or7S5Y2Bzm6MtsbVSpbMsRSj9HvXhZJ 11 | lC6+YV1BfiZdSLdWPh/0vn6ku6/znKl8o68DvZyvSDoBahafbQluab/KGf85B0JP 12 | vJ0AHAokfGMiragnKfJhPO18+IT5OClDDdjXbVs/PWx0SLt1EHjzqJOTNtvpDIw+ 13 | BZIiOcxhz7UjnGeyp5dvpnEbmhmk0WhZ0tsP2czOQwZIDesx2Nhbz/V45X1qDU3O 14 | W0K9g37n7m1zsWHlA7LXwpSzG+wJTRWMOVGUxfyg 15 | -----END CERTIFICATE REQUEST----- 16 | -------------------------------------------------------------------------------- /examples/SSLDemo/certs/server.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICsTCCAZkCFFwVYVZ4Uu9R0mhodJQCkUUSelbEMA0GCSqGSIb3DQEBCwUAMBUx 3 | EzARBgNVBAMMCiouZGVtby5jb20wHhcNMjAwMjE0MTI0OTA1WhcNMzMxMDIzMTI0 4 | OTA1WjAVMRMwEQYDVQQDDAoqLmRlbW8uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOC 5 | AQ8AMIIBCgKCAQEAwLHEXgjzTX6Z7MvPI1IAgwiEGuFyPl8b8o/tY9+2mvvs7EU4 6 | oK3DDRFoGwkTGfuLwstuhKllE2QyIr5QN6FmfWWiitjOovlEVRTJ5a274YXes9Kz 7 | uFlw6RT9WDj2iEkgdB7KWfQjaoCWrjhNt1rzh/jRpcmHsLmpOiQYBPeIpqVTnK1o 8 | risQ6352qnmperB8lcj731rKebDwZIo9y5nL/qDzwH3dBJQeFqvNuPcSd76lrpy+ 9 | 9GTA3lFgQQJyUiSwzBD005LKKW4fEcdllPa+/jLAuKO/atm+6dv186w7ojIMceir 10 | 549jn9UUyvWXfSfXl+68Aku1FTFFhRdS6OMsWQIDAQABMA0GCSqGSIb3DQEBCwUA 11 | A4IBAQCLCr8rsrgZskc3Ou7dZ5Br8xA2m7lrLSkFQIsDRosfBPerhGr83mgeyp2+ 12 | DNbPy0+IzgBUyN8N/P3QlZbQFq/3u9bjih3QukJuJe6KfYI0/iQu5jHxFv7VgbE+ 13 | a8yqUsrirWsmpltOMobv19jtWm/v1kofvCIUSBCJXkVi2L75164MhkKTGbSV1dl/ 14 | Ujg+X9yss5ZcDR+MqzuHZOO9580Ky0p+9m+STpZFG7QvC9QQtbvUBogAWECg+sSB 15 | RQ7Maq337ERpJg5EGOG2R+sa8rssMGFMRJ9OfenS+KaRF/oNKKL12pG7Y+oYpfEj 16 | WfSt4Lv16RWdV2vkmrorTovSuTIa 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /examples/SSLDemo/certs/server.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICWjCCAUICAQAwFTETMBEGA1UEAwwKKi5kZW1vLmNvbTCCASIwDQYJKoZIhvcN 3 | AQEBBQADggEPADCCAQoCggEBAMCxxF4I801+mezLzyNSAIMIhBrhcj5fG/KP7WPf 4 | tpr77OxFOKCtww0RaBsJExn7i8LLboSpZRNkMiK+UDehZn1loorYzqL5RFUUyeWt 5 | u+GF3rPSs7hZcOkU/Vg49ohJIHQeyln0I2qAlq44Tbda84f40aXJh7C5qTokGAT3 6 | iKalU5ytaK4rEOt+dqp5qXqwfJXI+99aynmw8GSKPcuZy/6g88B93QSUHharzbj3 7 | Ene+pa6cvvRkwN5RYEECclIksMwQ9NOSyiluHxHHZZT2vv4ywLijv2rZvunb9fOs 8 | O6IyDHHoq+ePY5/VFMr1l30n15fuvAJLtRUxRYUXUujjLFkCAwEAAaAAMA0GCSqG 9 | SIb3DQEBCwUAA4IBAQBLD12Bwb5YZE0PSLMm37/KMoN1nl1bug002HXGjtK48I+J 10 | 8pyd4BX5yW69gIP/CeHouDqJ/vhTdJmm/mLsexcby21RW55XYouCGLT/Cmh5qj+K 11 | HmcMR6lo38Q324cjNaMiqX8yAthbfWIC2Wupzb69SUiaXqXZ7F5dC+tB8DSVEvIY 12 | LBwxcXQBHC4C4k5aCIaPTlA20wdT0CKmD914Jby+iP5HP64nvc5yxacjKO+uOwNB 13 | AZe/uLWeCJs6v372oiFaiN+m8EQhmcD/2i8qSiFCcC3V3MRAZitoJseaYnRR9Aev 14 | wYCI6lpn2nCdM/L0+uOxZ2sA3hkb2muoUSPaRLq/ 15 | -----END CERTIFICATE REQUEST----- 16 | -------------------------------------------------------------------------------- /examples/SSLDemo/certs/server1.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICsTCCAZkCFFwVYVZ4Uu9R0mhodJQCkUUSelbGMA0GCSqGSIb3DQEBCwUAMBUx 3 | EzARBgNVBAMMCiouZGVtby5jb20wHhcNMjAwMjE0MTI0OTA2WhcNMzMxMDIzMTI0 4 | OTA2WjAVMRMwEQYDVQQDDAoqLmRlbW8uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOC 5 | AQ8AMIIBCgKCAQEA3o5I31gvK3AiF0sFAtHSt1diLMZEG1JtkeaKm9lIQgzqdG8+ 6 | f2nZPVAvU66M3B6uiYMU/QQVh3KAXF5bMyKhJtLGNYHqj6VoJatvWVdb1iasQW9M 7 | 8eGl2exxDMTPHWJ44vOYLcXJ6M3WRcfIXHC9K3rIjz2bWjDqHU8Y0fecCSJX8ctR 8 | gxgNBwM41P45dExbxQp5RGye7TOfXnf0yQJReFx2JDzzYqQ61VoqlkTw2RkuSr0Q 9 | ydr8S7CuReWF0xbKzMGf1L+SzmyGB2SAc9jkJ7T3Y4B36iy3y8hvMBTbCmke4ZpO 10 | FDrTw95wfC611nTXNKjUOlulKxSf+cfhACPFWwIDAQABMA0GCSqGSIb3DQEBCwUA 11 | A4IBAQCpQEXaFJiXSLeL9HKnvIexlxWfjTvikMoNR0t3UMxShazKE5gkQSw3WtCo 12 | E+LmmDvt0bqn54fk77oWxwZTx/qe8vJwpo0/gl/tNnGnzdzIAXk10G1W7kWkU2eG 13 | gpvYcQXKpW0QORHRzEXMbGIzdqjZOaFZYA+VtbtFB0cSLx8eNtd/bKxtwZyl66es 14 | uhPF40TnH6ccyq0Z2WuQylG4aSZ7qQcxCJUKj/Ych1+wr45ncgTZIsKXPBd0k7Kx 15 | xYvEuW8WGSjpJD8qPXt8hEwWpOfwLsmpnF1kMyaONLSHcqhfNU0bPTolLUSDJxkY 16 | 0JVVfeStdEsrmos1SrpEjD+wGlng 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /examples/SSLDemo/certs/server1.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICWjCCAUICAQAwFTETMBEGA1UEAwwKKi5kZW1vLmNvbTCCASIwDQYJKoZIhvcN 3 | AQEBBQADggEPADCCAQoCggEBAN6OSN9YLytwIhdLBQLR0rdXYizGRBtSbZHmipvZ 4 | SEIM6nRvPn9p2T1QL1OujNweromDFP0EFYdygFxeWzMioSbSxjWB6o+laCWrb1lX 5 | W9YmrEFvTPHhpdnscQzEzx1ieOLzmC3FyejN1kXHyFxwvSt6yI89m1ow6h1PGNH3 6 | nAkiV/HLUYMYDQcDONT+OXRMW8UKeURsnu0zn1539MkCUXhcdiQ882KkOtVaKpZE 7 | 8NkZLkq9EMna/EuwrkXlhdMWyszBn9S/ks5shgdkgHPY5Ce092OAd+ost8vIbzAU 8 | 2wppHuGaThQ608PecHwutdZ01zSo1DpbpSsUn/nH4QAjxVsCAwEAAaAAMA0GCSqG 9 | SIb3DQEBCwUAA4IBAQBUY5PIac76NGf+rHFG0xAXrZDuttwJOUjywz0La//+iPPK 10 | RFm+x+LK5tLc6Iunfo3Po7BedISIQ1+QxA8l2x6SmEczrJxGolwgjkj4iozhL5m+ 11 | UKbsKF6V+3ZF7wHcbVZ9dCQsr6dO39Qg4x07U0DUDll4L3bk7cMyZBX2WAq3Tp6u 12 | jBJI96A8VcnVs0lTghQNfJlGBv6OFPXJPHpgJucZ/e4Kpbr/bMxVF/bRRoEaNz1G 13 | 1JbieeB4Ohv0P3SzYTj4zgOYV1NTizg1a7SeODFJ3uDtGm2oN3TAzE6yg3ngzxvk 14 | u+F5d+KbhSewBe/AuAWIK1Jn1Ez3NGMoR5zMbKCg 15 | -----END CERTIFICATE REQUEST----- 16 | -------------------------------------------------------------------------------- /examples/StressDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(TarsStressServer) 3 | add_subdirectory(TarsStressServer) 4 | add_subdirectory(TarsStressClient) 5 | 6 | -------------------------------------------------------------------------------- /examples/StressDemo/README.md: -------------------------------------------------------------------------------- 1 | 该工程是Tars入门示例的代码 2 | 3 | 4 | 目录名称 |功能 5 | -----------------|---------------- 6 | TarsStressServer | Tars性能压测服务端的程序 7 | TarsStressClient | Tars性能压测客户端的程序 8 | -------------------------------------------------------------------------------- /examples/StressDemo/TarsStressClient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("TarsStressClient" "TarsStressServer") -------------------------------------------------------------------------------- /examples/StressDemo/TarsStressClient/teststress.sh: -------------------------------------------------------------------------------- 1 | # Language: bash 2 | for((i=1; i<=$1; i++)); do { 3 | ./TarsStressClient $2 1500000 Test.StressServer.StressObj $3 4 | } & done 5 | wait 6 | -------------------------------------------------------------------------------- /examples/StressDemo/TarsStressServer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("TarsStressServer" "") -------------------------------------------------------------------------------- /examples/StressDemo/TarsStressServer/Stress.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | module Test 18 | { 19 | 20 | interface Stress 21 | { 22 | int test(); 23 | int testStr(string sIn, out string sOut); 24 | }; 25 | 26 | }; 27 | -------------------------------------------------------------------------------- /examples/StressDemo/TarsStressServer/TarsStressServer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _TarsStressServer_H_ 18 | #define _TarsStressServer_H_ 19 | 20 | #include 21 | #include "servant/Application.h" 22 | 23 | using namespace tars; 24 | 25 | /** 26 | * 27 | **/ 28 | class TarsStressServer : public Application 29 | { 30 | public: 31 | /** 32 | * 33 | **/ 34 | virtual ~TarsStressServer() {}; 35 | 36 | /** 37 | * 38 | **/ 39 | virtual void initialize(); 40 | 41 | /** 42 | * 43 | **/ 44 | virtual void destroyApp(); 45 | 46 | protected: 47 | 48 | }; 49 | 50 | extern TarsStressServer g_app; 51 | 52 | //////////////////////////////////////////// 53 | #endif 54 | -------------------------------------------------------------------------------- /examples/UdpDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(Server) 3 | add_subdirectory(Server) 4 | add_subdirectory(Client) 5 | 6 | -------------------------------------------------------------------------------- /examples/UdpDemo/Client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server(UdpClient UdpServer) 2 | -------------------------------------------------------------------------------- /examples/UdpDemo/Client/config.conf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #tarsregistry locator 6 | locator = tars.tarsregistry.QueryObj@tcp -h 127.0.0.1 -p 17890 7 | #max invoke timeout 8 | sync-invoke-timeout = 5000 9 | #refresh endpoint interval 10 | refresh-endpoint-interval = 10000 11 | #stat obj 12 | stat = tars.tarsstat.StatObj 13 | #max send queue length limit 14 | sendqueuelimit = 100000 15 | #async queue length limit 16 | asyncqueuecap = 100000 17 | #async callback thread num 18 | asyncthread = 3 19 | #net thread 20 | netthread = 1 21 | #merge net and sync thread 22 | mergenetasync = 0 23 | #module name 24 | modulename = TestApp.UdpClient 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/UdpDemo/Server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | build_tars_server("UdpServer" "") 2 | 3 | -------------------------------------------------------------------------------- /examples/UdpDemo/Server/Hello.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | module TestApp 18 | { 19 | 20 | interface Hello 21 | { 22 | int test(); 23 | int testHello(string sReq, out string sRsp); 24 | }; 25 | 26 | }; 27 | -------------------------------------------------------------------------------- /examples/UdpDemo/Server/HelloImp.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #include "HelloImp.h" 18 | #include "servant/Application.h" 19 | 20 | using namespace std; 21 | 22 | ////////////////////////////////////////////////////// 23 | void HelloImp::initialize() 24 | { 25 | //initialize servant here: 26 | //... 27 | } 28 | 29 | ////////////////////////////////////////////////////// 30 | void HelloImp::destroy() 31 | { 32 | //destroy servant here: 33 | //... 34 | } 35 | 36 | int HelloImp::testHello(const std::string &sReq, std::string &sRsp, tars::TarsCurrentPtr current) 37 | { 38 | // TLOGDEBUG("HelloImp::testHellosReq:"< 21 | #include "servant/Application.h" 22 | 23 | using namespace tars; 24 | 25 | /** 26 | * 27 | **/ 28 | class HelloServer : public Application 29 | { 30 | public: 31 | /** 32 | * 33 | **/ 34 | virtual ~HelloServer() {}; 35 | 36 | /** 37 | * 38 | **/ 39 | virtual void initialize(); 40 | 41 | /** 42 | * 43 | **/ 44 | virtual void destroyApp(); 45 | }; 46 | 47 | extern HelloServer g_app; 48 | 49 | //////////////////////////////////////////// 50 | #endif 51 | -------------------------------------------------------------------------------- /examples/UtilDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_subdirectory(demo-server) 3 | add_subdirectory(demo-util) 4 | 5 | -------------------------------------------------------------------------------- /examples/UtilDemo/demo-server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${util_SOURCE_DIR}/include) 2 | 3 | FILE(GLOB_RECURSE SRC_LIST "*.cpp") 4 | 5 | if (TARS_SSL) 6 | if (WIN32) 7 | link_libraries(tarsutil ${LIB_SSL} ${LIB_CRYPTO} Crypt32) 8 | else () 9 | link_libraries(tarsutil ${LIB_SSL} ${LIB_CRYPTO}) 10 | endif () 11 | else () 12 | link_libraries(tarsutil) 13 | endif () 14 | 15 | add_executable(demo-server ${SRC_LIST}) 16 | 17 | add_dependencies(demo-server tarsutil) 18 | 19 | -------------------------------------------------------------------------------- /examples/UtilDemo/demo-util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${util_SOURCE_DIR}/include) 2 | include_directories(${CMAKE_BINARY_DIR}/src/gtest/include) 3 | link_directories(${CMAKE_BINARY_DIR}/src/gtest/lib) 4 | link_directories(${CMAKE_BINARY_DIR}/src/gtest/lib64) 5 | 6 | FILE(GLOB_RECURSE SRC_LIST "*.cpp") 7 | 8 | if (TARS_SSL) 9 | if (WIN32) 10 | link_libraries(tarsutil ${LIB_GTEST} ${LIB_SSL} ${LIB_CRYPTO} Crypt32) 11 | else () 12 | link_libraries(tarsutil ${LIB_GTEST} ${LIB_SSL} ${LIB_CRYPTO}) 13 | endif () 14 | else () 15 | link_libraries(tarsutil ${LIB_GTEST}) 16 | endif () 17 | 18 | add_executable(demo-util ${SRC_LIST}) 19 | 20 | add_dependencies(demo-util tarsutil) 21 | 22 | 23 | -------------------------------------------------------------------------------- /examples/UtilDemo/demo-util/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "gtest/gtest.h" 5 | 6 | using namespace std; 7 | 8 | int main(int argc, char** argv) 9 | { 10 | testing::InitGoogleTest(&argc, argv); 11 | return RUN_ALL_TESTS(); 12 | } -------------------------------------------------------------------------------- /examples/UtilDemo/demo-util/test_tc_encoder.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by jarod on 2020/2/20. 3 | // 4 | 5 | #include "util/tc_encoder.h" 6 | #include "gtest/gtest.h" 7 | #include "util/tc_common.h" 8 | 9 | using namespace tars; 10 | 11 | class EncodeTest : public testing::Test 12 | { 13 | public: 14 | //添加日志 15 | static void SetUpTestCase() 16 | { 17 | } 18 | static void TearDownTestCase() 19 | { 20 | } 21 | virtual void SetUp() //TEST跑之前会执行SetUp 22 | { 23 | } 24 | virtual void TearDown() //TEST跑完之后会执行TearDown 25 | { 26 | } 27 | }; 28 | 29 | TEST_F(EncodeTest, encode) 30 | { 31 | string utf8="我们的祖国;"; 32 | string gbk; 33 | 34 | gbk = TC_Encoder::utf82gbk(utf8);//, TC_Encoder::ICONV_NORMAL); 35 | 36 | string tmpUtf8 = TC_Encoder::gbk2utf8(gbk);//, TC_Encoder::ICONV_NORMAL); 37 | 38 | ASSERT_TRUE(utf8 == tmpUtf8); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /examples/scripts/run-auth.bat: -------------------------------------------------------------------------------- 1 | 2 | echo "run-auth.bat" 3 | 4 | set EXE_PATH=%1 5 | set SRC_PATH=%2\\.. 6 | 7 | echo %EXE_PATH% %SRC_PATH% 8 | 9 | taskkill /im AuthServer.exe /t /f 10 | 11 | timeout /T 1 12 | 13 | echo "start server: %EXE_PATH%/AuthServer.exe --config=%SRC_PATH%/examples/AuthDemo/Server/config.conf" 14 | 15 | start /b %EXE_PATH%\\AuthServer.exe --config=%SRC_PATH%\\examples\\AuthDemo\\Server\\config.conf 16 | 17 | timeout /T 3 18 | 19 | echo "client: ${EXE_PATH}/AuthClient.exe" 20 | 21 | %EXE_PATH%\\AuthClient.exe --count=10000 --thread=2 --call=sync --buffersize=1000 --netthread=1 22 | %EXE_PATH%\\AuthClient.exe --count=10000 --thread=2 --call=async --buffersize=1000 --netthread=1 23 | 24 | timeout /T 1 25 | 26 | taskkill /im AuthServer.exe /t /f 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /examples/scripts/run-auth.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "run-auth.sh" 4 | 5 | EXE_PATH=$1 6 | SRC_PATH=$2/.. 7 | 8 | echo ${EXE_PATH} ${SRC_PATH} 9 | 10 | killall -9 AuthServer 11 | 12 | sleep 1 13 | echo "start server: ${EXE_PATH}/AuthServer --config=${SRC_PATH}/examples/AuthDemo/Server/config.conf &" 14 | 15 | ${EXE_PATH}/AuthServer --config=${SRC_PATH}/examples/AuthDemo/Server/config.conf & 16 | 17 | sleep 1 18 | 19 | echo "client: ${EXE_PATH}/AuthClient" 20 | 21 | ${EXE_PATH}/AuthClient --config=${SRC_PATH}/examples/AuthDemo/Client/config.conf --count=10000 --thread=2 --call=sync --buffersize=1000 --netthread=1 22 | ${EXE_PATH}/AuthClient --config=${SRC_PATH}/examples/AuthDemo/Client/config.conf --count=10000 --thread=2 --call=async --buffersize=1000 --netthread=1 23 | 24 | sleep 1 25 | 26 | killall -9 AuthServer 27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/scripts/run-custom.bat: -------------------------------------------------------------------------------- 1 | 2 | echo "run-push.bat" 3 | 4 | set EXE_PATH=%1 5 | set SRC_PATH=%2\\.. 6 | 7 | echo %EXE_PATH% %SRC_PATH% 8 | 9 | taskkill /im CustomServer.exe /t /f 10 | 11 | timeout /T 1 12 | 13 | echo "start server: %EXE_PATH%\\CustomServer.exe --config=%SRC_PATH%\\examples\\CustomDemo\\CustomServer\\config.conf " 14 | 15 | start /b %EXE_PATH%\\CustomServer.exe --config=%SRC_PATH%\\examples\\CustomDemo\\CustomServer\\config.conf 16 | 17 | timeout /T 1 18 | 19 | ::------------------------------------------------------------------------------------------------------- 20 | 21 | echo "client: %EXE_PATH%\\CustomClient.exe" 22 | 23 | %EXE_PATH%\\CustomClient.exe --count=10000 --thread=2 --call=sync --netthread=2 --buffersize=100 24 | %EXE_PATH%\\CustomClient.exe --count=10000 --thread=2 --call=async --netthread=2 --buffersize=100 25 | 26 | taskkill /im CustomServer.exe /t /f 27 | 28 | -------------------------------------------------------------------------------- /examples/scripts/run-custom.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "run-custom.sh" 4 | 5 | EXE_PATH=$1 6 | SRC_PATH=$2/.. 7 | 8 | echo ${EXE_PATH} ${SRC_PATH} 9 | 10 | killall -9 CustomServer 11 | 12 | sleep 1 13 | echo "start server: ${EXE_PATH}/CustomServer --config=${SRC_PATH}/examples/CustomDemo/CustomServer/config.conf &" 14 | 15 | ${EXE_PATH}/CustomServer --config=${SRC_PATH}/examples/CustomDemo/CustomServer/config.conf & 16 | 17 | sleep 2 18 | 19 | #------------------------------------------------------------------------------------------------------- 20 | 21 | echo "client: ${EXE_PATH}/CustomClient" 22 | 23 | ${EXE_PATH}/CustomClient --count=10000 --thread=2 --call=sync --netthread=1 --buffersize=100 24 | 25 | ${EXE_PATH}/CustomClient --count=10000 --thread=2 --call=async --netthread=1 --buffersize=100 26 | 27 | killall -9 CustomServer 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /examples/scripts/run-http.bat: -------------------------------------------------------------------------------- 1 | 2 | echo "run-http.bat" 3 | 4 | set EXE_PATH=%1 5 | set SRC_PATH=%2\\.. 6 | 7 | echo %EXE_PATH% %SRC_PATH% 8 | 9 | taskkill /im HttpServer.exe /t /f 10 | 11 | timeout /T 1 12 | 13 | echo "start server: ${EXE_PATH}/HttpServer.exe --config=%SRC_PATH%/examples/HttpDemo/HttpServer/config.conf" 14 | 15 | start /b %EXE_PATH%\\HttpServer.exe --config=%SRC_PATH%\\examples\\HttpDemo\\HttpServer\\config.conf 16 | 17 | timeout /T 3 18 | 19 | echo "client: ${EXE_PATH}/HttpClient.exe" 20 | 21 | %EXE_PATH%\\HttpClient.exe --count=10000 --thread=2 --call=basehttp 22 | 23 | timeout /T 1 24 | 25 | taskkill /im HttpServer.exe /t /f 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/scripts/run-http.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "run-http.sh" 4 | 5 | EXE_PATH=$1 6 | SRC_PATH=$2/.. 7 | 8 | echo ${EXE_PATH} ${SRC_PATH} 9 | 10 | killall -9 HttpServer 11 | 12 | sleep 1 13 | echo "start server: ${EXE_PATH}/HttpServer --config=${SRC_PATH}/examples/HttpDemo/HttpServer/config.conf &" 14 | 15 | ${EXE_PATH}/HttpServer --config=${SRC_PATH}/examples/HttpDemo/HttpServer/config.conf & 16 | 17 | sleep 1 18 | 19 | echo "client: ${EXE_PATH}/HttpClient" 20 | 21 | ${EXE_PATH}/HttpClient --count=10000 --thread=2 --call=base 22 | ${EXE_PATH}/HttpClient --count=10000 --thread=2 --call=sync 23 | ${EXE_PATH}/HttpClient --count=10000 --thread=2 --call=async 24 | #${EXE_PATH}/HttpClient --count=10000 --thread=2 --call=synchttp 25 | 26 | sleep 1 27 | 28 | killall -9 HttpServer 29 | 30 | 31 | -------------------------------------------------------------------------------- /examples/scripts/run-http2.bat: -------------------------------------------------------------------------------- 1 | 2 | echo "run-http2.bat" 3 | 4 | set EXE_PATH=%1 5 | set SRC_PATH=%2\\.. 6 | 7 | echo %EXE_PATH% %SRC_PATH% 8 | 9 | taskkill /im Http2Server.exe /t /f 10 | 11 | timeout /T 1 12 | 13 | echo "start server: %EXE_PATH%\\Http2Server.exe --config=%SRC_PATH%\\examples\\HttpDemo\\Http2Server\\config.conf " 14 | 15 | start /b %EXE_PATH%\\Http2Server.exe --config=%SRC_PATH%\\examples\\HttpDemo\\Http2Server\\config.conf 16 | 17 | timeout /T 3 18 | 19 | echo "client: %EXE_PATH%\\Http2Client.exe" 20 | 21 | %EXE_PATH%\\Http2Client.exe --count=10000 --thread=2 --call=sync 22 | %EXE_PATH%\\Http2Client.exe --count=10000 --thread=2 --call=async 23 | 24 | timeout /T 1 25 | 26 | taskkill /im Http2Server.exe /t /f 27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/scripts/run-http2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "run-http2.sh" 4 | EXE_PATH=$1 5 | SRC_PATH=$2/.. 6 | 7 | echo ${EXE_PATH} ${SRC_PATH} 8 | 9 | killall -9 Http2Server 10 | 11 | sleep 1 12 | echo "start server: ${EXE_PATH}/Http2Server --config=${SRC_PATH}/examples/HttpDemo/Http2Server/config.conf &" 13 | 14 | ${EXE_PATH}/Http2Server --config=${SRC_PATH}/examples/HttpDemo/Http2Server/config.conf & 15 | 16 | sleep 1 17 | 18 | echo "client: ${EXE_PATH}/Http2Client" 19 | 20 | ${EXE_PATH}/Http2Client --count=10000 --thread=2 --call=async 21 | ${EXE_PATH}/Http2Client --count=10000 --thread=2 --call=sync 22 | 23 | sleep 1 24 | 25 | killall -9 Http2Server 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/scripts/run-kill.bat: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "run-kill.bat" 4 | 5 | taskkill /im SSLServer.exe /f 6 | taskkill /im AuthServer.exe /f 7 | taskkill /im CoroutineDemoAServer.exe /f 8 | taskkill /im CoroutineDemoBServer.exe /f 9 | taskkill /im CustomServer.exe /f 10 | taskkill /im HttpServer.exe /f 11 | taskkill /im Http2Server.exe /f 12 | taskkill /im PushServer.exe /f 13 | taskkill /im QuickStartDemo.exe /f 14 | taskkill /im ProxyServer.exe /f 15 | taskkill /im busybox.exe /f 16 | 17 | taskkill /im HttpClient.exe /f 18 | taskkill /im Http2Client.exe /f 19 | taskkill /im AuthClient.exe /f 20 | taskkill /im SSLClient.exe /f 21 | taskkill /im CoroutineDemoClient.exe /f 22 | taskkill /im testCoro.exe /f 23 | taskkill /im testParallelCoro.exe /f 24 | taskkill /im CustomClient.exe /f 25 | taskkill /im PushClient.exe /f 26 | taskkill /im QuickStartDemoClient.exe /f -------------------------------------------------------------------------------- /examples/scripts/run-kill.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "run-kill.sh" 4 | 5 | killall -9 SSLServer 6 | killall -9 AuthServer 7 | killall -9 CoroutineDemoAServer 8 | killall -9 CoroutineDemoBServer 9 | killall -9 CustomServer 10 | killall -9 HttpServer 11 | killall -9 Http2Server 12 | killall -9 PushServer 13 | killall -9 QuickStartDemo 14 | killall -9 ProxyServer 15 | 16 | killall -9 HttpClient 17 | killall -9 Http2Client 18 | killall -9 AuthClient 19 | killall -9 SSLClient 20 | killall -9 CoroutineDemoClient 21 | killall -9 testCoro 22 | killall -9 testParallelCoro 23 | killall -9 CustomClient 24 | killall -9 PushClient 25 | killall -9 QuickStartDemoClient -------------------------------------------------------------------------------- /examples/scripts/run-push-callback.bat: -------------------------------------------------------------------------------- 1 | 2 | echo "run-push-callback.bat" 3 | 4 | set EXE_PATH=%1 5 | set SRC_PATH=%2\\.. 6 | 7 | echo %EXE_PATH% %SRC_PATH% 8 | 9 | taskkill /im PushCallbackServer.exe /t /f 10 | 11 | timeout /T 1 12 | 13 | echo "start server: %EXE_PATH%/PushCallbackServer.exe --config=%SRC_PATH%/examples/PushCallbackDemo/Server/config.conf" 14 | 15 | start /b %EXE_PATH%\\PushCallbackServer.exe --config=%SRC_PATH%\\examples\\PushCallbackDemo\\Server\\config.conf 16 | 17 | timeout /T 3 18 | 19 | echo "client: ${EXE_PATH}/PushCallbackClient.exe" 20 | 21 | %EXE_PATH%\\PushCallbackClient.exe 22 | 23 | timeout /T 1 24 | 25 | taskkill /im PushCallbackServer.exe /t /f 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /examples/scripts/run-push-callback.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "run-push-callback.sh" 4 | 5 | EXE_PATH=$1 6 | SRC_PATH=$2/.. 7 | 8 | echo ${EXE_PATH} ${SRC_PATH} 9 | 10 | killall -9 PushCallbackServer 11 | 12 | sleep 1 13 | echo "start server: ${EXE_PATH}/PushCallbackServer --config=${SRC_PATH}/examples/PushCallbackDemo/Server/config.conf &" 14 | 15 | ${EXE_PATH}/PushCallbackServer --config=${SRC_PATH}/examples/PushCallbackDemo/Server/config.conf & 16 | 17 | sleep 1 18 | 19 | echo "client: ${EXE_PATH}/PushCallbackClient" 20 | 21 | ${EXE_PATH}/PushCallbackClient --config=${SRC_PATH}/examples/PushCallbackDemo/Client/config.conf 22 | 23 | sleep 1 24 | 25 | killall -9 PushCallbackServer 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/scripts/run-push.bat: -------------------------------------------------------------------------------- 1 | 2 | echo "run-push.bat" 3 | 4 | set EXE_PATH=%1 5 | set SRC_PATH=%2\\.. 6 | 7 | echo %EXE_PATH% %SRC_PATH% 8 | 9 | taskkill /im PushServer.exe /t /f 10 | 11 | timeout /T 1 12 | 13 | echo "start server: %EXE_PATH%\\PushServer.exe --config=%SRC_PATH%\\examples\\PushDemo\\PushServer\\config.conf" 14 | 15 | start /b %EXE_PATH%\\PushServer.exe --config=%SRC_PATH%\\examples\\PushDemo\\PushServer\\config.conf 16 | 17 | timeout /T 3 18 | 19 | ::------------------------------------------------------------------------------------------------------- 20 | 21 | echo "client: %EXE_PATH%\\PushClient.exe" 22 | 23 | %EXE_PATH%\\PushClient.exe 5 24 | 25 | taskkill /im PushServer.exe /t /f 26 | 27 | -------------------------------------------------------------------------------- /examples/scripts/run-push.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "run-co.sh" 4 | EXE_PATH=$1 5 | SRC_PATH=$2/.. 6 | 7 | echo ${EXE_PATH} ${SRC_PATH} 8 | 9 | killall -9 PushServer 10 | 11 | sleep 1 12 | echo "start server: ${EXE_PATH}/PushServer --config=${SRC_PATH}/examples/PushDemo/PushServer/config.conf &" 13 | 14 | ${EXE_PATH}/PushServer --config=${SRC_PATH}/examples/PushDemo/PushServer/config.conf & 15 | 16 | sleep 2 17 | 18 | #------------------------------------------------------------------------------------------------------- 19 | 20 | echo "client: ${EXE_PATH}/PushClient" 21 | 22 | ${EXE_PATH}/PushClient 5 23 | 24 | killall -9 PushServer 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/scripts/run-quick-start.bat: -------------------------------------------------------------------------------- 1 | 2 | echo "run-quick-start.bat" 3 | 4 | set EXE_PATH=%1 5 | set SRC_PATH=%2\\.. 6 | 7 | echo %EXE_PATH% %SRC_PATH% 8 | 9 | taskkill /im QuickStartDemo.exe /t /f 10 | taskkill /im ProxyServer.exe /t /f 11 | timeout /T 1 12 | 13 | echo "start server: %EXE_PATH%\\QuickStartDemo.exe --config=%SRC_PATH%\\examples\\QuickStartDemo\\HelloServer\\Server\\config.conf " 14 | 15 | start /b %EXE_PATH%\\QuickStartDemo.exe --config=%SRC_PATH%\\examples\\QuickStartDemo\\HelloServer\\Server\\config.conf 16 | start /b %EXE_PATH%\\ProxyServer.exe --config=%SRC_PATH%\\examples\\QuickStartDemo\\ProxyServer\\Server\\config.conf 17 | 18 | timeout /T 3 19 | 20 | echo "client: %EXE_PATH%\\QuickStartDemoClient.exe" 21 | 22 | %EXE_PATH%\\QuickStartDemoClient.exe --count=100000 --call=sync --thread=2 --buffersize=100 --netthread=2 23 | 24 | %EXE_PATH%\\QuickStartDemoClient.exe --count=100000 --call=async --thread=2 --buffersize=100 --netthread=2 25 | 26 | %EXE_PATH%\\QuickStartDemoClient.exe --count=100000 --call=synctup --thread=2 --buffersize=100 --netthread=2 27 | 28 | %EXE_PATH%\\QuickStartDemoClient.exe --count=100000 --call=asynctup --thread=2 --buffersize=100 --netthread=2 29 | 30 | echo "client: %EXE_PATH%\\ProxyServerClient.exe" 31 | 32 | %EXE_PATH%\\ProxyServerClient.exe 33 | 34 | timeout /T 1 35 | 36 | taskkill /im QuickStartDemo.exe /t /f 37 | taskkill /im ProxyServer.exe /t /f 38 | -------------------------------------------------------------------------------- /examples/scripts/run-quick-start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "run-quick-start.sh" 4 | EXE_PATH=$1 5 | SRC_PATH=$2/.. 6 | 7 | echo ${EXE_PATH} ${SRC_PATH} 8 | 9 | killall -9 QuickStartDemo ProxyServer 10 | 11 | sleep 1 12 | echo "start server: ${EXE_PATH}/QuickStartDemo --config=${SRC_PATH}/examples/QuickStartDemo/HelloServer/Server/config.conf &" 13 | 14 | ${EXE_PATH}/QuickStartDemo --config=${SRC_PATH}/examples/QuickStartDemo/HelloServer/Server/config.conf & 15 | ${EXE_PATH}/ProxyServer --config=${SRC_PATH}/examples/QuickStartDemo/ProxyServer/Server/config.conf & 16 | 17 | sleep 2 18 | 19 | echo "client: ${EXE_PATH}/QuickStartDemoClient" 20 | 21 | ${EXE_PATH}/QuickStartDemoClient --count=100000 --call=sync --thread=2 --buffersize=100 --netthread=2 22 | 23 | ${EXE_PATH}/QuickStartDemoClient --count=100000 --call=async --thread=2 --buffersize=100 --netthread=2 24 | 25 | ${EXE_PATH}/QuickStartDemoClient --count=100000 --call=synctup --thread=2 --buffersize=100 --netthread=2 26 | 27 | ${EXE_PATH}/QuickStartDemoClient --count=100000 --call=asynctup --thread=2 --buffersize=100 --netthread=2 28 | 29 | echo "client: ${EXE_PATH}/ProxyServerClient" 30 | 31 | ${EXE_PATH}/ProxyServerClient 32 | 33 | sleep 1 34 | 35 | killall -9 ProxyServer QuickStartDemo 36 | 37 | 38 | -------------------------------------------------------------------------------- /examples/scripts/run-ssl.bat: -------------------------------------------------------------------------------- 1 | 2 | echo "run-ssl.bat" 3 | 4 | set EXE_PATH=%1 5 | set SRC_PATH=%2\\.. 6 | 7 | echo %EXE_PATH% %SRC_PATH% 8 | 9 | taskkill /im SSLServer.exe /t /f 10 | timeout /T 1 11 | 12 | echo "start server: %EXE_PATH%\\SSLServer.exe --config=%SRC_PATH%\\examples\\SSLDemo\\Server\\config.conf " 13 | 14 | start /b %EXE_PATH%\\SSLServer.exe --config=%SRC_PATH%\\examples\\SSLDemo\\Server\\config.conf 15 | 16 | sleep 3 17 | 18 | echo "client: %EXE_PATH%\\SSLClient.exe" 19 | 20 | %EXE_PATH%\\SSLClient.exe --count=10000 --thread=2 --call=sync --buffersize=1000 --netthread=1 21 | %EXE_PATH%\\SSLClient.exe --count=10000 --thread=2 --call=async --buffersize=1000 --netthread=1 22 | 23 | %EXE_PATH%\\SSLClient.exe --count=10000 --thread=2 --call=syncauth --buffersize=1000 --netthread=1 24 | %EXE_PATH%\\SSLClient.exe --count=10000 --thread=2 --call=asyncauth --buffersize=1000 --netthread=1 25 | 26 | timeout /T 1 27 | 28 | taskkill /im SSLServer.exe /t /f 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /examples/scripts/run-udp.bat: -------------------------------------------------------------------------------- 1 | 2 | echo "run-auth.bat" 3 | 4 | set EXE_PATH=%1 5 | set SRC_PATH=%2\\.. 6 | 7 | echo %EXE_PATH% %SRC_PATH% 8 | 9 | taskkill /im UdpServer.exe /t /f 10 | 11 | timeout /T 1 12 | 13 | echo "start server: %EXE_PATH%/UdpServer.exe --config=%SRC_PATH%/examples/UdpDemo/Server/config.conf" 14 | 15 | start /b %EXE_PATH%\\UdpServer.exe --config=%SRC_PATH%\\examples\\UdpDemo\\Server\\config.conf 16 | 17 | timeout /T 3 18 | 19 | echo "client: ${EXE_PATH}/UdpClient.exe" 20 | 21 | %EXE_PATH%\\UdpClient.exe --count=10000 --thread=2 --call=sync --buffersize=1000 --netthread=1 22 | %EXE_PATH%\\UdpClient.exe --count=10000 --thread=2 --call=async --buffersize=1000 --netthread=1 23 | 24 | timeout /T 1 25 | 26 | taskkill /im UdpServer.exe /t /f 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /examples/scripts/run-udp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "run-auth.sh" 4 | 5 | EXE_PATH=$1 6 | SRC_PATH=$2/.. 7 | 8 | echo ${EXE_PATH} ${SRC_PATH} 9 | 10 | killall -9 UdpServer 11 | 12 | sleep 1 13 | echo "start server: ${EXE_PATH}/UdpServer --config=${SRC_PATH}/examples/UdpDemo/Server/config.conf &" 14 | 15 | ${EXE_PATH}/UdpServer --config=${SRC_PATH}/examples/UdpDemo/Server/config.conf & 16 | 17 | sleep 1 18 | 19 | echo "client: ${EXE_PATH}/UdpClient" 20 | 21 | ${EXE_PATH}/UdpClient --config=${SRC_PATH}/examples/UdpDemo/Client/config.conf --count=10000 --thread=2 --call=sync --buffersize=1000 --netthread=1 22 | ${EXE_PATH}/UdpClient --config=${SRC_PATH}/examples/UdpDemo/Client/config.conf --count=10000 --thread=2 --call=async --buffersize=1000 --netthread=1 23 | 24 | sleep 1 25 | 26 | killall -9 UdpServer 27 | 28 | 29 | -------------------------------------------------------------------------------- /mock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(../) 3 | file(GLOB_RECURSE SRC_FILES *.cpp) 4 | add_library(tarsmock STATIC ${SRC_FILES}) 5 | 6 | add_dependencies(tarsmock tarsservant) 7 | 8 | install(DIRECTORY . DESTINATION include/mock FILES_MATCHING PATTERN "*.h") 9 | 10 | install(TARGETS tarsmock RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) 11 | 12 | # if(ENABLE_SHARED) 13 | # add_library(tarsmock_shared SHARED ${SRC_FILES}) 14 | # target_compile_definitions(tarsmock_shared PRIVATE SVT_USE_DLL UTIL_USE_DLL) 15 | # target_link_libraries(tarsmock_shared tarsservant_shared tarsutil_shared) 16 | # add_dependencies(tarsmock_shared tarsservant_shared) 17 | 18 | # install(TARGETS tarsmock_shared RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) 19 | 20 | # if (WIN32) 21 | # install(FILES $ DESTINATION bin) 22 | # endif() 23 | 24 | # endif() 25 | -------------------------------------------------------------------------------- /mock/ConfigImp.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "ConfigImp.h" 3 | 4 | map ConfigImp::files; 5 | std::mutex ConfigImp::_mutex; 6 | 7 | void ConfigImp::setConfigFile(const string &name, const string &content) 8 | { 9 | std::lock_guard lock(_mutex); 10 | files[name] = content; 11 | } 12 | -------------------------------------------------------------------------------- /mock/FrameworkServer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "servant/Application.h" 5 | 6 | using namespace tars; 7 | 8 | extern vector> _clientStatData; 9 | extern vector> _serverStatData; 10 | 11 | class UTIL_DLL_API FrameworkServer : public Application, public TC_Thread 12 | { 13 | public: 14 | /** 15 | * 析构函数 16 | **/ 17 | virtual ~FrameworkServer(); 18 | 19 | /** 20 | * 服务初始化 21 | **/ 22 | virtual void initialize(); 23 | 24 | /** 25 | * 服务销毁 26 | **/ 27 | virtual void destroyApp(); 28 | 29 | protected: 30 | virtual void run(); 31 | 32 | 33 | bool loadLogFormat(const string& command, const string& params, string& result); 34 | }; 35 | 36 | 37 | -------------------------------------------------------------------------------- /mock/StatImp.cpp: -------------------------------------------------------------------------------- 1 |  2 | 3 | #include "StatImp.h" 4 | #include "FrameworkServer.h" 5 | 6 | /////////////////////////////////////////////////////////// 7 | // 8 | int StatImp::reportMicMsg( const map& statmsg,bool bFromClient, tars::CurrentPtr current ) 9 | { 10 | // LOG_CONSOLE_DEBUG << "report---------------------------------access size:" << statmsg.size() << "|bFromClient:" < &msg,tars::CurrentPtr current ) 25 | { 26 | TLOGINFO("sample---------------------------------access size:" << msg.size() << endl); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /mock/StatImp.h: -------------------------------------------------------------------------------- 1 |  2 | 3 | #ifndef __STAT_IMP_H_ 4 | #define __STAT_IMP_H_ 5 | 6 | #include 7 | #include "util/tc_common.h" 8 | #include "util/tc_thread.h" 9 | #include "servant/RemoteLogger.h" 10 | #include "servant/StatF.h" 11 | 12 | using namespace tars; 13 | 14 | class UTIL_DLL_API StatImp : public StatF 15 | { 16 | public: 17 | /** 18 | * 19 | */ 20 | StatImp() 21 | { 22 | } 23 | 24 | ~StatImp() 25 | { 26 | } 27 | 28 | /** 29 | * 初始化 30 | * 31 | * @return int 32 | */ 33 | virtual void initialize() {}; 34 | 35 | /** 36 | * 退出 37 | */ 38 | virtual void destroy() 39 | { 40 | } 41 | 42 | /** 43 | * 上报模块间调用信息 44 | * @param statmsg, 上报信息 45 | * @return int, 返回0表示成功 46 | */ 47 | virtual int reportMicMsg( const map& statmsg, bool bFromClient, tars::CurrentPtr current ); 48 | 49 | /** 50 | * 上报模块间调用采样信息 51 | * @param sample, 上报信息 52 | * @return int, 返回0表示成功 53 | */ 54 | virtual int reportSampleMsg(const vector &msg,tars::CurrentPtr current ); 55 | 56 | }; 57 | 58 | #endif 59 | 60 | 61 | -------------------------------------------------------------------------------- /mock/TarsMockUtil.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by jarod on 2024/3/6. 3 | // 4 | 5 | #include "mock/TarsMockUtil.h" 6 | #include "mock/FrameworkServer.h" 7 | #include "mock/framework.h" 8 | 9 | TarsMockUtil::TarsMockUtil() 10 | { 11 | _fs = std::make_shared(); 12 | } 13 | 14 | void TarsMockUtil::startFramework() 15 | { 16 | _fs->main(MOCK_FRAMEWORK_CONFIG); 17 | _fs->start(); 18 | _fs->waitForReady(); 19 | } 20 | 21 | void TarsMockUtil::stopFramework() 22 | { 23 | _fs->terminate(); 24 | } 25 | 26 | std::shared_ptr TarsMockUtil::getFrameworkServer() 27 | { 28 | return _fs; 29 | } 30 | 31 | void TarsMockUtil::refreshRegistry(const string &obj, size_t count) 32 | { 33 | do 34 | { 35 | TC_Common::sleep(1); 36 | 37 | vector activeEp; 38 | vector inactiveEp; 39 | 40 | _fs->getApplicationCommunicator()->getLocatorPrx()->findObjectById4All(obj, activeEp, inactiveEp); 41 | 42 | auto eps1 = EndpointInfo::toNodeEndpointF(activeEp); 43 | 44 | if(eps1.size() == count) 45 | { 46 | break; 47 | } 48 | 49 | }while(true); 50 | } 51 | 52 | -------------------------------------------------------------------------------- /mock/TarsMockUtil.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by jarod on 2024/3/6. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include "servant/Application.h" 10 | #include "mock/FrameworkServer.h" 11 | 12 | class FrameworkServer; 13 | 14 | class UTIL_DLL_API TarsMockUtil 15 | { 16 | public: 17 | TarsMockUtil(); 18 | 19 | /** 20 | * 启动framework 21 | * @param fs 22 | */ 23 | void startFramework(); 24 | 25 | /** 26 | * 停止framework 27 | * @param fs 28 | */ 29 | void stopFramework(); 30 | 31 | /** 32 | * 等待主控返回count个服务 33 | * @param obj 34 | * @param count 35 | */ 36 | void refreshRegistry(const std::string &obj, size_t count); 37 | 38 | /** 39 | * 40 | * @return 41 | */ 42 | std::shared_ptr getFrameworkServer(); 43 | 44 | protected: 45 | std::shared_ptr _fs; 46 | }; 47 | 48 | -------------------------------------------------------------------------------- /servant/README.md: -------------------------------------------------------------------------------- 1 | [点我查看中文版](README.zh.md) 2 | 3 | This project is the source code of the rpc implementation of the Tars framework C++ language. 4 | 5 | Directory |Features 6 | ------------------|---------------- 7 | wup |Uniform communication protocol (tars/wup protocol) of rpc framework and codec implementation of protocol 8 | protocol |The return code of the underlying communication defined by the rpc framework and the communication interface file that interacts with the framework underlying service 9 | servant/libservant |Source code implementation of rpc framework 10 | jmem |Source code implementation of memory data structure component based on tars protocol 11 | promise |Source implementation based on promise asynchronous programming 12 | makefile |The makefile implementation of the compiled source code using the TARS framework C++ language 13 | script |Script tool to generate TARS service template code 14 | -------------------------------------------------------------------------------- /servant/README.zh.md: -------------------------------------------------------------------------------- 1 | 该工程是Tars框架C++语言的rpc实现的源代码 2 | 3 | 目录名称 |功能 4 | ------------------|---------------- 5 | wup |rpc框架的统一的通信协议(tars/wup协议)和协议的编解码实现方式 6 | protocol |rpc框架定义的底层通信的返回码和与框架基础服务进行交互的通信接口文件 7 | servant/libservant |rpc框架的源码实现 8 | jmem |基于tars协议的内存数据结构组件的源码实现 9 | promise |基于promise异步编程的源码实现 10 | makefile |使用TARS框架C++语言的编译源代码的makefile实现 11 | script |生成TARS服务模版代码的脚本工具 12 | -------------------------------------------------------------------------------- /servant/libservant/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # if(TARS_OPENTRACKING) 2 | # include_directories(${PROJECT_SOURCE_DIR} ${OPENTRACKING_INC}) 3 | # else() 4 | include_directories(${PROJECT_SOURCE_DIR}) 5 | # endif() 6 | 7 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 8 | 9 | aux_source_directory(. DIR_SRCS) 10 | 11 | add_library(tarsservant STATIC ${DIR_SRCS}) 12 | 13 | add_dependencies(tarsservant tarsparse COPY-SERVENT-TARS) 14 | 15 | install(TARGETS tarsservant 16 | LIBRARY DESTINATION lib 17 | ARCHIVE DESTINATION lib) 18 | 19 | if(ENABLE_SHARED) 20 | add_library(tarsservant_shared SHARED ${DIR_SRCS}) 21 | target_compile_definitions(tarsservant_shared PRIVATE SVT_DLL_EXPORT UTIL_USE_DLL) 22 | 23 | target_link_libraries(tarsservant_shared tarsutil_shared tarsparse_shared) 24 | 25 | add_dependencies(tarsservant_shared tarsservant tarsutil_shared tarsparse_shared) 26 | 27 | install(TARGETS tarsservant_shared 28 | RUNTIME DESTINATION lib 29 | LIBRARY DESTINATION lib 30 | ARCHIVE DESTINATION lib) 31 | if (WIN32) 32 | install(FILES $ DESTINATION bin) 33 | endif() 34 | endif() 35 | -------------------------------------------------------------------------------- /servant/promise/template_helper.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _TARS_TEMPLATE_HELPER_H_ 18 | #define _TARS_TEMPLATE_HELPER_H_ 19 | 20 | #include 21 | 22 | namespace tars { 23 | 24 | template 25 | using enable_if_t = typename std::enable_if::type; 26 | 27 | } // end namespace tars 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /servant/script/busybox.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TarsCloud/TarsCpp/d08d5f764c08cea45ac06d9dc6e4ec41aa347aeb/servant/script/busybox.exe -------------------------------------------------------------------------------- /servant/script/cmake_demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(Demo-DemoServer) 4 | 5 | option(TARS_MYSQL "option for mysql" ON) 6 | option(TARS_SSL "option for ssl" OFF) 7 | option(TARS_HTTP2 "option for http2" OFF) 8 | 9 | if(WIN32) 10 | include (c:\\tars\\cpp\\makefile\\tars-tools.cmake) 11 | else() 12 | include (/usr/local/tars/cpp/makefile/tars-tools.cmake) 13 | endif() 14 | 15 | ####you can: cd build; cmake .. -DTARS_WEB_HOST={your web host} 16 | set(TARS_WEB_HOST "" CACHE STRING "set web host") 17 | IF (TARS_WEB_HOST STREQUAL "") 18 | set(TARS_WEB_HOST "http://tars.test.com") 19 | ENDIF () 20 | 21 | include_directories(/usr/local/tars/cpp/thirdparty/include) 22 | # link_directories(/usr/local/tars/cpp/thirdparty/lib) 23 | 24 | #include_directories(/home/tarsprotol/App/OtherServer) 25 | 26 | add_subdirectory(src) 27 | 28 | #target_link_libraries(mysqlclient ssl crypto nghttp2-static) 29 | -------------------------------------------------------------------------------- /servant/script/cmake_demo/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(DemoApp-DemoServer) 4 | 5 | gen_server(DemoApp DemoServer) 6 | 7 | #target_link_libraries(mysqlclient ssl crypto nghttp2-static) 8 | -------------------------------------------------------------------------------- /servant/script/cmake_demo/src/DemoServant.tars: -------------------------------------------------------------------------------- 1 | 2 | module DemoApp 3 | { 4 | 5 | interface DemoServant 6 | { 7 | int test(); 8 | }; 9 | 10 | }; 11 | -------------------------------------------------------------------------------- /servant/script/cmake_demo/src/DemoServantImp.cpp: -------------------------------------------------------------------------------- 1 | #include "DemoServantImp.h" 2 | #include "servant/Application.h" 3 | 4 | using namespace std; 5 | 6 | ////////////////////////////////////////////////////// 7 | void DemoServantImp::initialize() 8 | { 9 | //initialize servant here: 10 | //... 11 | } 12 | 13 | ////////////////////////////////////////////////////// 14 | void DemoServantImp::destroy() 15 | { 16 | //destroy servant here: 17 | //... 18 | } 19 | 20 | -------------------------------------------------------------------------------- /servant/script/cmake_demo/src/DemoServantImp.h: -------------------------------------------------------------------------------- 1 | #ifndef _DemoServantImp_H_ 2 | #define _DemoServantImp_H_ 3 | 4 | #include "servant/Application.h" 5 | #include "DemoServant.h" 6 | 7 | /** 8 | * 9 | * 10 | */ 11 | class DemoServantImp : public DemoApp::DemoServant 12 | { 13 | public: 14 | /** 15 | * 16 | */ 17 | virtual ~DemoServantImp() {} 18 | 19 | /** 20 | * 21 | */ 22 | virtual void initialize(); 23 | 24 | /** 25 | * 26 | */ 27 | virtual void destroy(); 28 | 29 | /** 30 | * 31 | */ 32 | virtual int test(tars::TarsCurrentPtr current) { return 0;}; 33 | }; 34 | ///////////////////////////////////////////////////// 35 | #endif 36 | -------------------------------------------------------------------------------- /servant/script/cmake_demo/src/DemoServer.cpp: -------------------------------------------------------------------------------- 1 | #include "DemoServer.h" 2 | #include "DemoServantImp.h" 3 | 4 | using namespace std; 5 | 6 | DemoServer g_app; 7 | 8 | ///////////////////////////////////////////////////////////////// 9 | void 10 | DemoServer::initialize() 11 | { 12 | //initialize application here: 13 | //... 14 | 15 | addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".DemoServantObj"); 16 | } 17 | ///////////////////////////////////////////////////////////////// 18 | void 19 | DemoServer::destroyApp() 20 | { 21 | //destroy application here: 22 | //... 23 | } 24 | ///////////////////////////////////////////////////////////////// 25 | int 26 | main(int argc, char* argv[]) 27 | { 28 | try 29 | { 30 | g_app.main(argc, argv); 31 | g_app.waitForShutdown(); 32 | } 33 | catch (std::exception& e) 34 | { 35 | cerr << "std::exception:" << e.what() << std::endl; 36 | } 37 | catch (...) 38 | { 39 | cerr << "unknown exception." << std::endl; 40 | } 41 | return -1; 42 | } 43 | ///////////////////////////////////////////////////////////////// 44 | -------------------------------------------------------------------------------- /servant/script/cmake_demo/src/DemoServer.h: -------------------------------------------------------------------------------- 1 | #ifndef _DemoServer_H_ 2 | #define _DemoServer_H_ 3 | 4 | #include 5 | #include "servant/Application.h" 6 | 7 | using namespace tars; 8 | 9 | /** 10 | * 11 | **/ 12 | class DemoServer : public Application 13 | { 14 | public: 15 | /** 16 | * 17 | **/ 18 | virtual ~DemoServer() {}; 19 | 20 | /** 21 | * 22 | **/ 23 | virtual void initialize(); 24 | 25 | /** 26 | * 27 | **/ 28 | virtual void destroyApp(); 29 | }; 30 | 31 | extern DemoServer g_app; 32 | 33 | //////////////////////////////////////////// 34 | #endif 35 | -------------------------------------------------------------------------------- /servant/script/cmake_http_demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(Demo-DemoServer) 4 | 5 | option(TARS_MYSQL "option for mysql" ON) 6 | option(TARS_SSL "option for ssl" OFF) 7 | option(TARS_HTTP2 "option for http2" OFF) 8 | 9 | if(WIN32) 10 | include (c:\\tars\\cpp\\makefile\\tars-tools.cmake) 11 | else() 12 | include (/usr/local/tars/cpp/makefile/tars-tools.cmake) 13 | endif() 14 | 15 | ####you can: cd build; cmake .. -DTARS_WEB_HOST={your web host} 16 | set(TARS_WEB_HOST "" CACHE STRING "set web host") 17 | IF (TARS_WEB_HOST STREQUAL "") 18 | set(TARS_WEB_HOST "http://tars.test.com") 19 | ENDIF () 20 | 21 | include_directories(/usr/local/tars/cpp/thirdparty/include) 22 | # link_directories(/usr/local/tars/cpp/thirdparty/lib) 23 | 24 | #include_directories(/home/tarsprotol/App/OtherServer) 25 | 26 | add_subdirectory(src) 27 | 28 | #target_link_libraries(mysqlclient ssl crypto nghttp2-static) 29 | -------------------------------------------------------------------------------- /servant/script/cmake_http_demo/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(DemoApp-DemoServer) 4 | 5 | gen_server(DemoApp DemoServer) 6 | -------------------------------------------------------------------------------- /servant/script/cmake_http_demo/src/DemoServantImp.cpp: -------------------------------------------------------------------------------- 1 | #include "DemoServantImp.h" 2 | #include "servant/Application.h" 3 | 4 | using namespace std; 5 | 6 | ////////////////////////////////////////////////////// 7 | void DemoServantImp::initialize() 8 | { 9 | //initialize servant here: 10 | //... 11 | } 12 | 13 | ////////////////////////////////////////////////////// 14 | void DemoServantImp::destroy() 15 | { 16 | //destroy servant here: 17 | //... 18 | } 19 | 20 | int DemoServantImp::doRequest(TarsCurrentPtr current, vector &buffer) 21 | { 22 | TC_HttpRequest req; 23 | TC_HttpResponse rsp; 24 | 25 | // parse request header 26 | vector v = current->getRequestBuffer(); 27 | string sBuf; 28 | sBuf.assign(v.data(), v.size()); 29 | req.decode(sBuf); 30 | 31 | int ret = doRequest(req, rsp); 32 | 33 | rsp.encode(buffer); 34 | 35 | return ret; 36 | } 37 | 38 | int DemoServantImp::doRequest(const TC_HttpRequest &req, TC_HttpResponse &rsp) 39 | { 40 | string msg = "Hello Tars!"; 41 | rsp.setContentType("text/html"); 42 | rsp.setResponse(msg.c_str(), msg.size()); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /servant/script/cmake_http_demo/src/DemoServantImp.h: -------------------------------------------------------------------------------- 1 | #ifndef _DemoServantImp_H_ 2 | #define _DemoServantImp_H_ 3 | 4 | #include "servant/Application.h" 5 | 6 | /** 7 | * 8 | * 9 | */ 10 | class DemoServantImp : public Servant 11 | { 12 | public: 13 | /** 14 | * 15 | */ 16 | virtual ~DemoServantImp() {} 17 | 18 | /** 19 | * 20 | */ 21 | virtual void initialize(); 22 | 23 | /** 24 | * 25 | */ 26 | virtual void destroy(); 27 | 28 | /** 29 | * 30 | */ 31 | int doRequest(TarsCurrentPtr current, vector &buffer); 32 | 33 | private: 34 | int doRequest(const TC_HttpRequest &req, TC_HttpResponse &rsp); 35 | }; 36 | ///////////////////////////////////////////////////// 37 | #endif 38 | -------------------------------------------------------------------------------- /servant/script/cmake_http_demo/src/DemoServer.cpp: -------------------------------------------------------------------------------- 1 | #include "DemoServer.h" 2 | #include "DemoServantImp.h" 3 | 4 | using namespace std; 5 | 6 | DemoServer g_app; 7 | 8 | ///////////////////////////////////////////////////////////////// 9 | void 10 | DemoServer::initialize() 11 | { 12 | //initialize application here: 13 | //... 14 | 15 | addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".DemoServantObj"); 16 | addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName + ".DemoServantObj", &TC_NetWorkBuffer::parseHttp); 17 | } 18 | ///////////////////////////////////////////////////////////////// 19 | void 20 | DemoServer::destroyApp() 21 | { 22 | //destroy application here: 23 | //... 24 | } 25 | ///////////////////////////////////////////////////////////////// 26 | int 27 | main(int argc, char* argv[]) 28 | { 29 | try 30 | { 31 | g_app.main(argc, argv); 32 | g_app.waitForShutdown(); 33 | } 34 | catch (std::exception& e) 35 | { 36 | cerr << "std::exception:" << e.what() << std::endl; 37 | } 38 | catch (...) 39 | { 40 | cerr << "unknown exception." << std::endl; 41 | } 42 | return -1; 43 | } 44 | ///////////////////////////////////////////////////////////////// 45 | -------------------------------------------------------------------------------- /servant/script/cmake_http_demo/src/DemoServer.h: -------------------------------------------------------------------------------- 1 | #ifndef _DemoServer_H_ 2 | #define _DemoServer_H_ 3 | 4 | #include 5 | #include "servant/Application.h" 6 | 7 | using namespace tars; 8 | 9 | /** 10 | * 11 | **/ 12 | class DemoServer : public Application 13 | { 14 | public: 15 | /** 16 | * 17 | **/ 18 | virtual ~DemoServer() {}; 19 | 20 | /** 21 | * 22 | **/ 23 | virtual void initialize(); 24 | 25 | /** 26 | * 27 | **/ 28 | virtual void destroyApp(); 29 | }; 30 | 31 | extern DemoServer g_app; 32 | 33 | //////////////////////////////////////////// 34 | #endif 35 | -------------------------------------------------------------------------------- /servant/script/cmake_http_server.bat: -------------------------------------------------------------------------------- 1 | c:\\tars\\cpp\\script\\busybox.exe bash c:\\tars\\cpp\\script\\cmake_http_server.sh %1 %2 %3 c:/tars -------------------------------------------------------------------------------- /servant/script/cmake_http_server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $# -lt 3 ] 4 | then 5 | echo "" 6 | exit 0 7 | fi 8 | 9 | APP=$1 10 | SERVER=$2 11 | SERVANT=$3 12 | 13 | echo "APP:$APP, SERVER:$SERVER, SERVANT:$SERVANT" 14 | 15 | if [ "$SERVER" == "$SERVANT" ] 16 | then 17 | echo "Error!(ServerName == ServantName)" 18 | exit -1 19 | fi 20 | 21 | if [ ! -d $SERVER ] 22 | then 23 | echo "[mkdir: $SERVER]" 24 | mkdir -p $SERVER 25 | fi 26 | 27 | echo "[create server: $APP.$SERVER ...]" 28 | 29 | TARSPATH=$4 30 | 31 | if [ "$TARSPATH" == "" ]; then 32 | TARSPATH=/usr/local/tars 33 | fi 34 | 35 | DEMO_PATH=${TARSPATH}/cpp/script/cmake_http_demo 36 | 37 | #make cleanall -C $DEMO_PATH 38 | 39 | cp -rf $DEMO_PATH/* $SERVER/ 40 | 41 | cd $SERVER/src 42 | 43 | SRC_FILE="DemoServer.h DemoServer.cpp DemoServantImp.h DemoServantImp.cpp CMakeLists.txt" 44 | 45 | for FILE in $SRC_FILE 46 | do 47 | cat $FILE | sed "s/DemoServer/$SERVER/g" > $FILE.tmp 48 | mv $FILE.tmp $FILE 49 | 50 | cat $FILE | sed "s/DemoApp/$APP/g" > $FILE.tmp 51 | mv $FILE.tmp $FILE 52 | 53 | cat $FILE | sed "s/DemoServant/$SERVANT/g" > $FILE.tmp 54 | mv $FILE.tmp $FILE 55 | done 56 | 57 | mv DemoServer.h ${SERVER}.h 58 | mv DemoServer.cpp ${SERVER}.cpp 59 | mv DemoServantImp.h ${SERVANT}Imp.h 60 | mv DemoServantImp.cpp ${SERVANT}Imp.cpp 61 | 62 | cd .. 63 | mkdir build; cd build 64 | cmake .. 65 | cmake --build . --config Release 66 | 67 | #cd ../../ 68 | 69 | echo "[done.]" 70 | -------------------------------------------------------------------------------- /servant/script/cmake_tars_server.bat: -------------------------------------------------------------------------------- 1 | c:\\tars\\cpp\\script\\busybox.exe bash c:\\tars\\cpp\\script\\cmake_tars_server.sh %1 %2 %3 c:/tars 2 | -------------------------------------------------------------------------------- /servant/script/create_http_server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $# -lt 3 ] 4 | then 5 | echo "" 6 | exit 0 7 | fi 8 | 9 | APP=$1 10 | SERVER=$2 11 | SERVANT=$3 12 | TARSPATH=$4 13 | 14 | if [ "$TARSPATH" == "" ]; then 15 | TARSPATH=/usr/local/tars/ 16 | fi 17 | 18 | if [ "$SERVER" == "$SERVANT" ] 19 | then 20 | echo "Error!(ServerName == ServantName)" 21 | exit -1 22 | fi 23 | 24 | if [ ! -d $APP/$SERVER ] 25 | then 26 | echo "[mkdir: $APP/$SERVER]" 27 | mkdir -p $APP/$SERVER 28 | fi 29 | 30 | echo "[create server: $APP.$SERVER ...]" 31 | 32 | DEMO_PATH=${TARSPATH}/cpp/script/http_demo 33 | 34 | cp $DEMO_PATH/* $APP/$SERVER/ 35 | 36 | cd $APP/$SERVER/ 37 | 38 | SRC_FILE="DemoServer.h DemoServer.cpp DemoServantImp.h DemoServantImp.cpp makefile" 39 | 40 | for FILE in $SRC_FILE 41 | do 42 | cat $FILE | sed "s/DemoServer/$SERVER/g" > $FILE.tmp 43 | mv $FILE.tmp $FILE 44 | 45 | cat $FILE | sed "s/DemoApp/$APP/g" > $FILE.tmp 46 | mv $FILE.tmp $FILE 47 | 48 | cat $FILE | sed "s/DemoServant/$SERVANT/g" > $FILE.tmp 49 | mv $FILE.tmp $FILE 50 | done 51 | 52 | rename "DemoServer" "$SERVER" $SRC_FILE 53 | rename "DemoServant" "$SERVANT" $SRC_FILE 54 | 55 | cd ../../ 56 | 57 | echo "[done.]" -------------------------------------------------------------------------------- /servant/script/create_tars_server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $# -lt 3 ] 4 | then 5 | echo "" 6 | exit 0 7 | fi 8 | 9 | APP=$1 10 | SERVER=$2 11 | SERVANT=$3 12 | 13 | echo "APP:$APP, SERVER:$SERVER, SERVANT:$SERVANT" 14 | 15 | if [ "$SERVER" == "$SERVANT" ] 16 | then 17 | echo "Error!(ServerName == ServantName)" 18 | exit -1 19 | fi 20 | 21 | if [ ! -d $SERVER ] 22 | then 23 | echo "[mkdir: $SERVER]" 24 | mkdir -p $SERVER 25 | fi 26 | 27 | echo "[create server: $APP.$SERVER ...]" 28 | 29 | DEMO_PATH=/usr/local/tars/cpp/script/demo 30 | 31 | #make cleanall -C $DEMO_PATH 32 | 33 | cp -rf $DEMO_PATH/* $SERVER/ 34 | 35 | cd $SERVER 36 | 37 | SRC_FILE="DemoServer.h DemoServer.cpp DemoServantImp.h DemoServantImp.cpp DemoServant.tars makefile" 38 | 39 | for FILE in $SRC_FILE 40 | do 41 | cat $FILE | sed "s/DemoServer/$SERVER/g" > $FILE.tmp 42 | mv $FILE.tmp $FILE 43 | 44 | cat $FILE | sed "s/DemoApp/$APP/g" > $FILE.tmp 45 | mv $FILE.tmp $FILE 46 | 47 | cat $FILE | sed "s/DemoServant/$SERVANT/g" > $FILE.tmp 48 | mv $FILE.tmp $FILE 49 | done 50 | 51 | mv DemoServer.h ${SERVER}.h 52 | mv DemoServer.cpp ${SERVER}.cpp 53 | mv DemoServantImp.h ${SERVANT}Imp.h 54 | mv DemoServantImp.cpp ${SERVANT}Imp.cpp 55 | mv DemoServant.tars ${SERVANT}.tars 56 | 57 | make 58 | 59 | echo "[done.]" 60 | -------------------------------------------------------------------------------- /servant/script/demo/DemoServant.tars: -------------------------------------------------------------------------------- 1 | 2 | module DemoApp 3 | { 4 | 5 | interface DemoServant 6 | { 7 | int test(); 8 | }; 9 | 10 | }; 11 | -------------------------------------------------------------------------------- /servant/script/demo/DemoServantImp.cpp: -------------------------------------------------------------------------------- 1 | #include "DemoServantImp.h" 2 | #include "servant/Application.h" 3 | 4 | using namespace std; 5 | 6 | ////////////////////////////////////////////////////// 7 | void DemoServantImp::initialize() 8 | { 9 | //initialize servant here: 10 | //... 11 | } 12 | 13 | ////////////////////////////////////////////////////// 14 | void DemoServantImp::destroy() 15 | { 16 | //destroy servant here: 17 | //... 18 | } 19 | 20 | -------------------------------------------------------------------------------- /servant/script/demo/DemoServantImp.h: -------------------------------------------------------------------------------- 1 | #ifndef _DemoServantImp_H_ 2 | #define _DemoServantImp_H_ 3 | 4 | #include "servant/Application.h" 5 | #include "DemoServant.h" 6 | 7 | /** 8 | * 9 | * 10 | */ 11 | class DemoServantImp : public DemoApp::DemoServant 12 | { 13 | public: 14 | /** 15 | * 16 | */ 17 | virtual ~DemoServantImp() {} 18 | 19 | /** 20 | * 21 | */ 22 | virtual void initialize(); 23 | 24 | /** 25 | * 26 | */ 27 | virtual void destroy(); 28 | 29 | /** 30 | * 31 | */ 32 | virtual int test(tars::TarsCurrentPtr current) { return 0;}; 33 | }; 34 | ///////////////////////////////////////////////////// 35 | #endif 36 | -------------------------------------------------------------------------------- /servant/script/demo/DemoServer.cpp: -------------------------------------------------------------------------------- 1 | #include "DemoServer.h" 2 | #include "DemoServantImp.h" 3 | 4 | using namespace std; 5 | 6 | DemoServer g_app; 7 | 8 | ///////////////////////////////////////////////////////////////// 9 | void 10 | DemoServer::initialize() 11 | { 12 | //initialize application here: 13 | //... 14 | 15 | addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".DemoServantObj"); 16 | } 17 | ///////////////////////////////////////////////////////////////// 18 | void 19 | DemoServer::destroyApp() 20 | { 21 | //destroy application here: 22 | //... 23 | } 24 | ///////////////////////////////////////////////////////////////// 25 | int 26 | main(int argc, char* argv[]) 27 | { 28 | try 29 | { 30 | g_app.main(argc, argv); 31 | g_app.waitForShutdown(); 32 | } 33 | catch (std::exception& e) 34 | { 35 | cerr << "std::exception:" << e.what() << std::endl; 36 | } 37 | catch (...) 38 | { 39 | cerr << "unknown exception." << std::endl; 40 | } 41 | return -1; 42 | } 43 | ///////////////////////////////////////////////////////////////// 44 | -------------------------------------------------------------------------------- /servant/script/demo/DemoServer.h: -------------------------------------------------------------------------------- 1 | #ifndef _DemoServer_H_ 2 | #define _DemoServer_H_ 3 | 4 | #include 5 | #include "servant/Application.h" 6 | 7 | using namespace tars; 8 | 9 | /** 10 | * 11 | **/ 12 | class DemoServer : public Application 13 | { 14 | public: 15 | /** 16 | * 17 | **/ 18 | virtual ~DemoServer() {}; 19 | 20 | /** 21 | * 22 | **/ 23 | virtual void initialize(); 24 | 25 | /** 26 | * 27 | **/ 28 | virtual void destroyApp(); 29 | }; 30 | 31 | extern DemoServer g_app; 32 | 33 | //////////////////////////////////////////// 34 | #endif 35 | -------------------------------------------------------------------------------- /servant/script/demo/makefile: -------------------------------------------------------------------------------- 1 | #----------------------------------------------------------------------- 2 | 3 | APP := DemoApp 4 | TARGET := DemoServer 5 | CONFIG := 6 | STRIP_FLAG:= N 7 | TARS2CPP_FLAG:= 8 | 9 | INCLUDE += 10 | LIB += 11 | 12 | #----------------------------------------------------------------------- 13 | 14 | include /usr/local/tars/cpp/makefile/makefile.tars 15 | 16 | #----------------------------------------------------------------------- -------------------------------------------------------------------------------- /servant/script/http_demo/DemoServantImp.cpp: -------------------------------------------------------------------------------- 1 | #include "DemoServantImp.h" 2 | #include "servant/Application.h" 3 | 4 | using namespace std; 5 | 6 | ////////////////////////////////////////////////////// 7 | void DemoServantImp::initialize() 8 | { 9 | //initialize servant here: 10 | //... 11 | } 12 | 13 | ////////////////////////////////////////////////////// 14 | void DemoServantImp::destroy() 15 | { 16 | //destroy servant here: 17 | //... 18 | } 19 | 20 | int DemoServantImp::doRequest(TarsCurrentPtr current, vector &buffer) 21 | { 22 | TC_HttpRequest req; 23 | TC_HttpResponse rsp; 24 | 25 | // parse request header 26 | vector v = current->getRequestBuffer(); 27 | string sBuf; 28 | sBuf.assign(v.data(), v.size()); 29 | req.decode(sBuf); 30 | 31 | int ret = doRequest(req, rsp); 32 | 33 | rsp.encode(buffer); 34 | 35 | return ret; 36 | } 37 | 38 | int DemoServantImp::doRequest(const TC_HttpRequest &req, TC_HttpResponse &rsp) 39 | { 40 | string msg = "Hello Tars!"; 41 | rsp.setContentType("text/html"); 42 | rsp.setResponse(msg.c_str(), msg.size()); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /servant/script/http_demo/DemoServantImp.h: -------------------------------------------------------------------------------- 1 | #ifndef _DemoServantImp_H_ 2 | #define _DemoServantImp_H_ 3 | 4 | #include "servant/Application.h" 5 | 6 | /** 7 | * 8 | * 9 | */ 10 | class DemoServantImp : public Servant 11 | { 12 | public: 13 | /** 14 | * 15 | */ 16 | virtual ~DemoServantImp() {} 17 | 18 | /** 19 | * 20 | */ 21 | virtual void initialize(); 22 | 23 | /** 24 | * 25 | */ 26 | virtual void destroy(); 27 | 28 | /** 29 | * 30 | */ 31 | int doRequest(TarsCurrentPtr current, vector &buffer); 32 | 33 | private: 34 | int doRequest(const TC_HttpRequest &req, TC_HttpResponse &rsp); 35 | }; 36 | ///////////////////////////////////////////////////// 37 | #endif 38 | -------------------------------------------------------------------------------- /servant/script/http_demo/DemoServer.cpp: -------------------------------------------------------------------------------- 1 | #include "DemoServer.h" 2 | #include "DemoServantImp.h" 3 | 4 | using namespace std; 5 | 6 | DemoServer g_app; 7 | 8 | ///////////////////////////////////////////////////////////////// 9 | void 10 | DemoServer::initialize() 11 | { 12 | //initialize application here: 13 | //... 14 | 15 | addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".DemoServantObj"); 16 | addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName + ".DemoServantObj", &TC_NetWorkBuffer::parseHttp); 17 | } 18 | ///////////////////////////////////////////////////////////////// 19 | void 20 | DemoServer::destroyApp() 21 | { 22 | //destroy application here: 23 | //... 24 | } 25 | ///////////////////////////////////////////////////////////////// 26 | int 27 | main(int argc, char* argv[]) 28 | { 29 | try 30 | { 31 | g_app.main(argc, argv); 32 | g_app.waitForShutdown(); 33 | } 34 | catch (std::exception& e) 35 | { 36 | cerr << "std::exception:" << e.what() << std::endl; 37 | } 38 | catch (...) 39 | { 40 | cerr << "unknown exception." << std::endl; 41 | } 42 | return -1; 43 | } 44 | ///////////////////////////////////////////////////////////////// 45 | -------------------------------------------------------------------------------- /servant/script/http_demo/DemoServer.h: -------------------------------------------------------------------------------- 1 | #ifndef _DemoServer_H_ 2 | #define _DemoServer_H_ 3 | 4 | #include 5 | #include "servant/Application.h" 6 | 7 | using namespace tars; 8 | 9 | /** 10 | * 11 | **/ 12 | class DemoServer : public Application 13 | { 14 | public: 15 | /** 16 | * 17 | **/ 18 | virtual ~DemoServer() {}; 19 | 20 | /** 21 | * 22 | **/ 23 | virtual void initialize(); 24 | 25 | /** 26 | * 27 | **/ 28 | virtual void destroyApp(); 29 | }; 30 | 31 | extern DemoServer g_app; 32 | 33 | //////////////////////////////////////////// 34 | #endif 35 | -------------------------------------------------------------------------------- /servant/script/http_demo/makefile: -------------------------------------------------------------------------------- 1 | #----------------------------------------------------------------------- 2 | 3 | APP := DemoApp 4 | TARGET := DemoServer 5 | CONFIG := 6 | STRIP_FLAG:= N 7 | TARS2CPP_FLAG:= 8 | 9 | INCLUDE += 10 | LIB += 11 | 12 | #----------------------------------------------------------------------- 13 | 14 | include /usr/local/tars/cpp/makefile/makefile.tars 15 | 16 | #----------------------------------------------------------------------- -------------------------------------------------------------------------------- /servant/servant/AuthLogic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "servant/AuthF.h" 4 | #include "util/tc_epoll_server.h" 5 | 6 | namespace tars 7 | { 8 | /** 9 | * server:默认生成鉴权请求方法 10 | */ 11 | pair> serverVerifyAuthCallback(TC_NetWorkBuffer &, TC_Transceiver*, weak_ptr adapter, const string &expectObj); 12 | 13 | /** 14 | * client:默认生成鉴权请求方法 15 | */ 16 | vector defaultCreateAuthReq(const BasicAuthInfo& info); 17 | 18 | } // end namespace tars 19 | 20 | -------------------------------------------------------------------------------- /servant/servant/TarsLogger.h: -------------------------------------------------------------------------------- 1 |  2 | #include "RemoteLogger.h" 3 | 4 | -------------------------------------------------------------------------------- /servant/tup/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(OUT_DEPENDS_LIST) 2 | 3 | complice_tars(OUT_DEPENDS_LIST "" "") 4 | 5 | add_custom_target(TUP-TARS ALL DEPENDS ${OUT_DEPENDS_LIST}) 6 | -------------------------------------------------------------------------------- /tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | project(tools) 3 | 4 | include_directories(${util_SOURCE_DIR}/include) 5 | 6 | function(tars2language TARGET) 7 | set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin") 8 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 9 | foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES}) 10 | string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG) 11 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/bin) 12 | endforeach() 13 | 14 | include_directories(${PROJECT_SOURCE_DIR}/tarsparse) 15 | 16 | aux_source_directory(. DIR_SRCS) 17 | 18 | add_executable(${TARGET} ${DIR_SRCS}) 19 | 20 | target_link_libraries(${TARGET} tarsutil tarsparse) 21 | 22 | if(TARS_SSL AND ENABLE_SHARED) 23 | target_link_libraries(${TARGET} ${LIB_SSL} ${LIB_CRYPTO}) 24 | endif() 25 | install(TARGETS ${TARGET} 26 | RUNTIME DESTINATION tools) 27 | endfunction() 28 | 29 | IF(UNIX) 30 | add_subdirectory(tarsgrammar) 31 | ENDIF(UNIX) 32 | 33 | add_subdirectory(tarsparse) 34 | add_subdirectory(tarsmerge) 35 | add_subdirectory(tars2cpp) 36 | add_subdirectory(tars2python) 37 | add_subdirectory(tars2cs) 38 | add_subdirectory(tars2c) 39 | add_subdirectory(tars2oc) 40 | add_subdirectory(tars2php) 41 | add_subdirectory(tars2android) 42 | add_subdirectory(tars2node) 43 | add_subdirectory(tars2case) 44 | 45 | IF(TARS_PROTOBUF) 46 | add_subdirectory(pb2tarscpp) 47 | ENDIF() 48 | -------------------------------------------------------------------------------- /tools/README.md: -------------------------------------------------------------------------------- 1 | [点我查看中文版](README.zh.md) 2 | 3 | The project is the source code of the Tars framework C++ language IDL 4 | 5 | Code directory introduction 6 | 7 | 8 | Directory | Features 9 | ------------------|---------------- 10 | tarsgrammer | Defining rules for tars lexical and grammatical analysis 11 | tarsparse | Parsing tars words and parsing source code implementation 12 | tars2cpp | Source code implementation of IDL tool for generating C++ code through tars file 13 | tars2c | Source code implementation of IDL tool for generating C code through tars file 14 | tars2cs | Source code implementation of IDL tool for generating C# code through tars file 15 | tars2oc | Source code implementation of IDL tool for generating Object-C code through tars file 16 | tars2php | Source code implementation of IDL tool for generating PHP code through tars file 17 | tars2python | Source code implementation of IDL tool for generating Python code through tars file 18 | tars2node | Source code implementation of IDL tool for generating Node.js code through tars file 19 | tars2android | Source code implementation of IDL tool for generating Android code through tars file 20 | tars2case | Generate test case for tars server 21 | pb2tarscpp | Generate protoc plugin source code for tars C++ code via proto file 22 | -------------------------------------------------------------------------------- /tools/README.zh.md: -------------------------------------------------------------------------------- 1 | 该工程是Tars框架C++语言IDL的源代码 2 | 3 | 代码目录介绍 4 | 5 | 6 | 目录名称 |功能 7 | ------------------|---------------- 8 | tarsgrammer | 定义tars词法和语法的分析规则 9 | tarsparse | 解析tars词语和语法分析的源码实现 10 | tars2cpp | 通过tars文件生成 C++ 代码的IDL工具的源码实现 11 | tars2c | 通过tars文件生成 C 代码的IDL工具的源码实现 12 | tars2cs | 通过tars文件生成 C# 代码的IDL工具的源码实现 13 | tars2oc | 通过tars文件生成 ObjectC 代码的IDL工具的源码实现 14 | tars2php | 通过tars文件生成 PHP 代码的IDL工具的源码实现 15 | tars2python | 通过tars文件生成 Python 代码的IDL工具的源码实现 16 | tars2node | 通过tars文件生成 Node.js 代码的IDL工具的源码实现 17 | tars2android | 通过tars文件生成 Android 代码的IDL工具的源码实现 18 | tars2case | 通过tars文件生成 tars 服务生成测试用例 19 | pb2tarscpp | 通过proto文件生成tars C++ 代码的protoc插件源码实现 20 | -------------------------------------------------------------------------------- /tools/pb2tarscpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MODULE "pb2tarscpp") 2 | 3 | set(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin") 4 | 5 | if(WIN32) 6 | add_definitions(-DPROTOBUF_USE_DLLS) 7 | endif() 8 | 9 | aux_source_directory(. DIR_SRCS) 10 | 11 | add_executable(pb2tarscpp ${DIR_SRCS}) 12 | 13 | add_dependencies(pb2tarscpp thirdparty) 14 | 15 | target_link_libraries(pb2tarscpp ${LIB_PROTOBUF} ${LIB_PROTOC}) 16 | 17 | install(TARGETS "pb2tarscpp" 18 | RUNTIME DESTINATION tools) 19 | 20 | -------------------------------------------------------------------------------- /tools/pb2tarscpp/CppGenCallback.h: -------------------------------------------------------------------------------- 1 | // Generates C++ tars service interface out of Protobuf IDL. 2 | // 3 | // This is a Proto2 compiler plugin. See net/proto2/compiler/proto/plugin.proto 4 | // and net/proto2/compiler/public/plugin.h for more information on plugins. 5 | 6 | #pragma once 7 | 8 | #include 9 | #include "CppPbUtils.h" 10 | 11 | namespace google 12 | { 13 | 14 | namespace protobuf 15 | { 16 | class ServiceDescriptor; 17 | } 18 | 19 | } 20 | 21 | 22 | // gen prx callback 23 | std::string GenPrxCallback(const ::google::protobuf::ServiceDescriptor* desc, int indent); 24 | 25 | -------------------------------------------------------------------------------- /tools/pb2tarscpp/CppGenProxy.h: -------------------------------------------------------------------------------- 1 | // Generates C++ tars service interface out of Protobuf IDL. 2 | // 3 | // This is a Proto2 compiler plugin. See net/proto2/compiler/proto/plugin.proto 4 | // and net/proto2/compiler/public/plugin.h for more information on plugins. 5 | 6 | #pragma once 7 | 8 | #include 9 | #include "CppPbUtils.h" 10 | 11 | namespace google 12 | { 13 | 14 | namespace protobuf 15 | { 16 | class ServiceDescriptor; 17 | } 18 | 19 | } 20 | 21 | // gen proxy 22 | std::string GenPrx(const ::google::protobuf::ServiceDescriptor* desc, int indent); 23 | 24 | -------------------------------------------------------------------------------- /tools/pb2tarscpp/CppGenServant.h: -------------------------------------------------------------------------------- 1 | // Generates C++ tars service interface out of Protobuf IDL. 2 | // 3 | // This is a Proto2 compiler plugin. See net/proto2/compiler/proto/plugin.proto 4 | // and net/proto2/compiler/public/plugin.h for more information on plugins. 5 | 6 | #pragma once 7 | 8 | #include 9 | #include "CppPbUtils.h" 10 | 11 | namespace google 12 | { 13 | 14 | namespace protobuf 15 | { 16 | class ServiceDescriptor; 17 | } 18 | 19 | } 20 | 21 | std::string GenServant(const ::google::protobuf::ServiceDescriptor* desc, int indent); 22 | 23 | -------------------------------------------------------------------------------- /tools/pb2tarscpp/CppPbUtils.h: -------------------------------------------------------------------------------- 1 | // Generates C++ tars service interface out of Protobuf IDL. 2 | // 3 | // This is a Proto2 compiler plugin. See net/proto2/compiler/proto/plugin.proto 4 | // and net/proto2/compiler/public/plugin.h for more information on plugins. 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | std::string ProtoFileBaseName(const std::string& fullName); 11 | 12 | extern const std::string kDeclaration; 13 | extern const std::string kIndent; 14 | 15 | std::string LineFeed(int indent = 0) ; 16 | 17 | 18 | std::string ToCppNamespace(const std::string& name); 19 | 20 | -------------------------------------------------------------------------------- /tools/pb2tarscpp/CppPlugin.h: -------------------------------------------------------------------------------- 1 | // Generates C++ tars service interface out of Protobuf IDL. 2 | // 3 | // This is a Proto2 compiler plugin. See net/proto2/compiler/proto/plugin.proto 4 | // and net/proto2/compiler/public/plugin.h for more information on plugins. 5 | 6 | #include 7 | #include 8 | 9 | namespace google 10 | { 11 | 12 | namespace protobuf 13 | { 14 | class FileDescriptor; 15 | } 16 | 17 | } 18 | 19 | class CppTarsGenerator : public google::protobuf::compiler::CodeGenerator { 20 | public: 21 | CppTarsGenerator() {} 22 | 23 | virtual ~CppTarsGenerator() {} 24 | 25 | bool Generate(const google::protobuf::FileDescriptor *file, 26 | const std::string ¶meter, 27 | google::protobuf::compiler::GeneratorContext *context, 28 | std::string *error) const; //override final; 29 | private: 30 | bool _CheckFile(const google::protobuf::FileDescriptor* file, std::string* error) const; 31 | static std::string _GenHeader(const std::string& file); 32 | static std::string _GenNamespaceBegin(const std::string& ns); 33 | static std::string _GenNamespaceEnd(const std::string& ns); 34 | 35 | static std::string _GenResponse(const std::string& filename, const std::string& content); 36 | }; 37 | 38 | -------------------------------------------------------------------------------- /tools/tars2android/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | tars2language("tars2android") 2 | -------------------------------------------------------------------------------- /tools/tars2android/tars_filter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | #ifndef TARS_FILTER_H_WILEY 17 | #define TARS_FILTER_H_WILEY 18 | 19 | #include "parse.h" 20 | #include 21 | 22 | class TarsFilter { 23 | public: 24 | TarsFilter(); 25 | 26 | void filterStructs(const std::map& orignalMap 27 | , std::map& resultMap) const; 28 | void filterEnums(const std::map& orignalMap 29 | , std::map& resultMap) const; 30 | 31 | private: 32 | void addSid(const std::string& sid); 33 | 34 | std::map mFilterTarsSidMap; 35 | }; 36 | 37 | 38 | 39 | #endif /* TARS_FILTER_H_ */ 40 | -------------------------------------------------------------------------------- /tools/tars2c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | tars2language("tars2c") 2 | -------------------------------------------------------------------------------- /tools/tars2case/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | tars2language("tars2case") 2 | -------------------------------------------------------------------------------- /tools/tars2cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | tars2language("tars2cpp") 2 | -------------------------------------------------------------------------------- /tools/tars2cs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | tars2language("tars2cs") 2 | -------------------------------------------------------------------------------- /tools/tars2node/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # version 2 | set(PARSER_VERSION "${TARS_VERSION}") 3 | set(GENERATOR_VERSION "20240216") 4 | 5 | # namespace 6 | set(IDL_NAMESPACE Tars) 7 | string(TOLOWER ${IDL_NAMESPACE} TC_NAMESPACE) 8 | set(GRAMMAR_NAME Grammar) 9 | 10 | # idl 11 | set(RPC_MODULE_PATH "@tars/rpc") 12 | set(STREAM_MODULE_PATH "@tars/stream") 13 | set(IDL_TYPE "Tars") 14 | set(PROTOCOL_NAME "Tup") 15 | 16 | # flag 17 | if(UNIX) 18 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O2 -Wall") 19 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -Wall") 20 | endif(UNIX) 21 | 22 | # define 23 | add_definitions(-DPARSER_VERSION="${PARSER_VERSION}") 24 | add_definitions(-DGENERATOR_VERSION="${GENERATOR_VERSION}") 25 | add_definitions(-DTC_NAMESPACE=${TC_NAMESPACE}) 26 | add_definitions(-DIDL_NAMESPACE=${IDL_NAMESPACE}) 27 | add_definitions(-DGRAMMAR_NAME=${GRAMMAR_NAME}) 28 | add_definitions(-DRPC_MODULE_PATH="${RPC_MODULE_PATH}") 29 | add_definitions(-DSTREAM_MODULE_PATH="${STREAM_MODULE_PATH}") 30 | add_definitions(-DEXECUTE_FILENAME="${PROJECT_NAME}") 31 | add_definitions(-DIDL_TYPE="${IDL_TYPE}") 32 | add_definitions(-DPROTOCOL_NAME="${PROTOCOL_NAME}") 33 | 34 | tars2language("tars2node") 35 | -------------------------------------------------------------------------------- /tools/tars2node/file_util.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #include "code_generator.h" 18 | 19 | void CodeGenerator::makeUTF8File(const string& sFileName, const string& sFileContent) 20 | { 21 | try { 22 | string sData = TC_Encoder::gbk2utf8(sFileContent); 23 | 24 | TC_File::save2file(sFileName, sData.c_str()); 25 | } catch (...) { 26 | cout << "Convert GBK to UTF8 failed, current encoding is GBK."; 27 | TC_File::save2file(sFileName, sFileContent.c_str()); 28 | } 29 | } 30 | 31 | string CodeGenerator::getRealFileInfo(const string& sPath) 32 | { 33 | return TC_File::extractFilePath(sPath) + TC_File::excludeFileExt(TC_File::extractFileName(sPath)) + "." + TC_Common::lower(IDL_TYPE); 34 | } -------------------------------------------------------------------------------- /tools/tars2oc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | tars2language("tars2oc") 2 | -------------------------------------------------------------------------------- /tools/tars2php/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | tars2language("tars2php") 2 | -------------------------------------------------------------------------------- /tools/tars2python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | tars2language("tars2python") 2 | -------------------------------------------------------------------------------- /tools/tarsmerge/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | tars2language("tarsmerge") 2 | -------------------------------------------------------------------------------- /unit-test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(unit-test) 2 | 3 | 4 | include_directories(${servant_SOURCE_DIR}/protocol/framework) 5 | include_directories(${servant_SOURCE_DIR}/protocol/servant) 6 | 7 | include_directories(${CMAKE_BINARY_DIR}/src/gtest/include) 8 | link_directories(${CMAKE_BINARY_DIR}/src/gtest/lib) 9 | link_directories(${CMAKE_BINARY_DIR}/src/gtest/lib64) 10 | include_directories(./) 11 | include_directories(../) 12 | 13 | # set(ENABLE_SHARED OFF) 14 | build_tars_server("unit-test" "") 15 | 16 | add_definitions(-DCMAKE_SOURCE_DIR="${PROJECT_SOURCE_DIR}") 17 | target_link_libraries(unit-test ${LIB_GTEST} tarsmock) 18 | 19 | if(TARS_MYSQL) 20 | target_link_libraries(unit-test ${LIB_MYSQL}) 21 | endif() 22 | 23 | add_dependencies(unit-test FRAMEWORK-PROTOCOL tarsmock) 24 | -------------------------------------------------------------------------------- /unit-test/certs/ca.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDCzCCAfOgAwIBAgIUblg0MMUtu1YdIF1CmdlcKCXdg5gwDQYJKoZIhvcNAQEL 3 | BQAwFTETMBEGA1UEAwwKKi5kZW1vLmNvbTAeFw0yMDAyMTQxMjQ5MDVaFw0zMzEw 4 | MjMxMjQ5MDVaMBUxEzARBgNVBAMMCiouZGVtby5jb20wggEiMA0GCSqGSIb3DQEB 5 | AQUAA4IBDwAwggEKAoIBAQCv8i3rLGi7j1E62fvpZ+9DI0kz6ASNOrmphzHS/E9p 6 | X7EijiLpat+YARsYC42qA4+Cky1ItDTASUAkvVZNCj+6TNsFx1LSesgE28roOBOi 7 | qXCtwBIQvAJBPRpgZtX5++BWyxexBsHszp8t1k7QKgVY3eXeGCQHOHZZltXNFGKP 8 | 2hruxct2VEcZWqWdYKE1hy0GSyxvejsT2GLv2OMlWwD/iE+UvTKU5+9CTq/vfx3j 9 | vGUo410DniMz1OqqxAAamKhx4lzKvPfZeW/CQe929qwQONxGQENRXKiCiPkMTRIo 10 | JCdXBDS6ztolq4URIB57yCq88qMO8ZY6URA6U97qyhlJAgMBAAGjUzBRMB0GA1Ud 11 | DgQWBBSAwN6/0NtVoAWC7TB9PnYMzJhMJTAfBgNVHSMEGDAWgBSAwN6/0NtVoAWC 12 | 7TB9PnYMzJhMJTAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBX 13 | rGw19azPpFebPM5WHOUNBF5CesevnE4md0lE/9DcXl1wSLAwJC7bVijqt/gA4AgO 14 | i+7AnVxlrrMZ4UBEgMu8cHyAGuaC/u+wSJ49TpciMk3/bKfN1gnQ1O/bzm8zpP/B 15 | zQmffhiQcuM1wqStQeTnqD7bP4vAQKqLZGb0Hca2dPsRYIgW+z1dxLg6dxrFlkG8 16 | dunwDDQXsnYf3PcB2fMQuK1lJltiiu7sVe+XeFeRTFSDGyxDs9q28SwRIHWlzIIC 17 | j+57DkNAgBf9aYf7QM2dnmFNMHSs9fP8MZX7kltu5GadJKprDbjBtJd4IWSCMOv5 18 | A/fdjurUkf3aCj1qGj+o 19 | -----END CERTIFICATE----- 20 | -------------------------------------------------------------------------------- /unit-test/certs/ca.srl: -------------------------------------------------------------------------------- 1 | 5C1561567852EF51D268687494029145127A56C7 2 | -------------------------------------------------------------------------------- /unit-test/certs/client.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICsTCCAZkCFFwVYVZ4Uu9R0mhodJQCkUUSelbFMA0GCSqGSIb3DQEBCwUAMBUx 3 | EzARBgNVBAMMCiouZGVtby5jb20wHhcNMjAwMjE0MTI0OTA2WhcNMzMxMDIzMTI0 4 | OTA2WjAVMRMwEQYDVQQDDAoqLmRlbW8uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOC 5 | AQ8AMIIBCgKCAQEAzXLpEt1TWXzwWx6eQPGztqo7MSx8r3vxh5l5Wm45tRTNXot8 6 | eh7QWvJChflUlnz9y0J7O2SxFnjdpHrp29AkLlt/aRjvRfLfgDcc7LqfUpWcc3qz 7 | bkYPnktywXAuA1R3JnnsrDKFiwPY5Fc0bVuiZ0VZD9ufalvoc+kd3PjeQYvYkvUa 8 | axZ0iaxKs5PaKwYIKW7RsWQa2bNkArH+slet50JDbDXuZXEnPghBLyjAhkhPmLQ8 9 | jjrMX1t4fl0qQ21/q7TDf4FL+QNTcmEWQFEpz2H3qhM+J8UU2JdW36p+++Nj3CaF 10 | lcWpCpxqJ8UGMqCfTM+KcPmBg/UQ/ByRb0wiqwIDAQABMA0GCSqGSIb3DQEBCwUA 11 | A4IBAQBMED94VcdZJwznIJ3FOyv+8D7P9PYS1KvIVclsC1G2Wzrhohx4sMcCE4QE 12 | 43TJDc0Vj/fQR+g3IyPL3TTWofLuif/Pp+7t2mieST7USrIWPJuUYYdkbch/WUEX 13 | +p9vzdKJOnClCcdcMIptUJdHd7/X+qHPo0m4xg8qEfkW79IvcOQqAcl0Mx+Lxiny 14 | Xps3VTe7j6IOdv4ZycD0OtYj3RSoQPfjWZ8yFV7riYjd0hj05sG/CNJ/9Nvy34tn 15 | xRZnlWzMziOqYK+U/2BS1+j+LrfMJCgeShGdmBziqMde99Vovj2dv7sDvXqfZfCz 16 | jLWfPO5ShCU72n7MoM/yqsTD8FmS 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /unit-test/certs/client.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICWjCCAUICAQAwFTETMBEGA1UEAwwKKi5kZW1vLmNvbTCCASIwDQYJKoZIhvcN 3 | AQEBBQADggEPADCCAQoCggEBAM1y6RLdU1l88FsenkDxs7aqOzEsfK978YeZeVpu 4 | ObUUzV6LfHoe0FryQoX5VJZ8/ctCeztksRZ43aR66dvQJC5bf2kY70Xy34A3HOy6 5 | n1KVnHN6s25GD55LcsFwLgNUdyZ57KwyhYsD2ORXNG1bomdFWQ/bn2pb6HPpHdz4 6 | 3kGL2JL1GmsWdImsSrOT2isGCClu0bFkGtmzZAKx/rJXredCQ2w17mVxJz4IQS8o 7 | wIZIT5i0PI46zF9beH5dKkNtf6u0w3+BS/kDU3JhFkBRKc9h96oTPifFFNiXVt+q 8 | fvvjY9wmhZXFqQqcaifFBjKgn0zPinD5gYP1EPwckW9MIqsCAwEAAaAAMA0GCSqG 9 | SIb3DQEBCwUAA4IBAQCG6KZeU22DzRgfoljtuyPNuONyBPLsDbT2nhM8UFNS7Io9 10 | hJYIn5FA57PC6vfJOPW4lvg5c73pjccJlLMYzPZ/TwvxUwcQzjeebZeRpPCB2fgQ 11 | ihX/6pyN0s2Li2WK8dNq02y0bH+f+ItftCoFnrhJPfNxObaSpNQh7rIbkxujOprG 12 | wqPmVFvEydzPwFwe6O42b2Ame+qdjva9QH4nbd8dG47kKCVhP8CMq8UbMvngVcbn 13 | 9A5dg4mS3OnTAdR21bNlZGQVHTiojKd3go7KrFwMlcRrCZ63+M510wIpUBxmFClA 14 | icfaUazi62EikDnnFExu60xQ8MpWL9U57foKV8ci 15 | -----END CERTIFICATE REQUEST----- 16 | -------------------------------------------------------------------------------- /unit-test/certs/client1.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICsTCCAZkCFFwVYVZ4Uu9R0mhodJQCkUUSelbHMA0GCSqGSIb3DQEBCwUAMBUx 3 | EzARBgNVBAMMCiouZGVtby5jb20wHhcNMjAwMjE0MTI0OTA2WhcNMzMxMDIzMTI0 4 | OTA2WjAVMRMwEQYDVQQDDAoqLmRlbW8uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOC 5 | AQ8AMIIBCgKCAQEA7Qw+OBtzkGG38r4IOBzgpJte5qHPCTBCeowt/6dmwY3W+1bU 6 | cf5wdHBtSsuv3M5OpWKCG8gu3gpBZQvpz7MfN50ouuM0sDvKUxIUP2KX/nv7uiDg 7 | R4iJy47M4XSH2qbRovKPZeRCeigkiU4gKMnJ0Vx82EgEdOLzBt1wLL8a0q1zVOwC 8 | stII/0d4VhCoWgurddJa1gU7EwQ+ZRLwSbbvtgsEfVYCvwC/gb3fGrljJ2PpeY2/ 9 | UfxggnqGcG0IZoT4zi0uyRgK094nPVupS9JM5ig4I/FpP+KQ1LTlDh9LrwZrCQXj 10 | /DFp0Wka5DWHTXWb7TwZShFo3r3emD3gGZi0owIDAQABMA0GCSqGSIb3DQEBCwUA 11 | A4IBAQB9+YqEgsabF3hh3OBFZmg0Je12mkFBsMCRPwMOXfEY8Mzt7xVHHx5iKsBa 12 | u3XaLhVnOgu6VryGSIRmD7lGMctfIELysWu5xQtoY+m9xWZfDhY8G9sNhLSShJ/H 13 | 7UZ5/FUi+meohIM0SHEdzTyQtBSs+lfhgshsgtpZ4ysZDQTM/ukuOyBf1vXcs+Gx 14 | pQa4hDQ+Tnev0h6z4PIDCeg88KohDgrzFMSFZ04bNUSLeIxjgo47hLxVNa/3xokh 15 | yaTz4QZ3OcOjjfw//5lyfLDAZ7Rk1FBZ+NjdGRPjmTVIic2utT4QwS8aQyqDN/jA 16 | gxo1xb+Tu5YxHXkMGa2hwV3VvhkF 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /unit-test/certs/client1.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICWjCCAUICAQAwFTETMBEGA1UEAwwKKi5kZW1vLmNvbTCCASIwDQYJKoZIhvcN 3 | AQEBBQADggEPADCCAQoCggEBAO0MPjgbc5Bht/K+CDgc4KSbXuahzwkwQnqMLf+n 4 | ZsGN1vtW1HH+cHRwbUrLr9zOTqVighvILt4KQWUL6c+zHzedKLrjNLA7ylMSFD9i 5 | l/57+7og4EeIicuOzOF0h9qm0aLyj2XkQnooJIlOICjJydFcfNhIBHTi8wbdcCy/ 6 | GtKtc1TsArLSCP9HeFYQqFoLq3XSWtYFOxMEPmUS8Em277YLBH1WAr8Av4G93xq5 7 | Yydj6XmNv1H8YIJ6hnBtCGaE+M4tLskYCtPeJz1bqUvSTOYoOCPxaT/ikNS05Q4f 8 | S68GawkF4/wxadFpGuQ1h011m+08GUoRaN693pg94BmYtKMCAwEAAaAAMA0GCSqG 9 | SIb3DQEBCwUAA4IBAQDrJMiKZIriezIo2PaJzm1Da4vcB41oiFVQGZuFRRN7Mt9t 10 | tMDuZeVILSqkT1zHu0lamGuS/SKk1VSV0Or7S5Y2Bzm6MtsbVSpbMsRSj9HvXhZJ 11 | lC6+YV1BfiZdSLdWPh/0vn6ku6/znKl8o68DvZyvSDoBahafbQluab/KGf85B0JP 12 | vJ0AHAokfGMiragnKfJhPO18+IT5OClDDdjXbVs/PWx0SLt1EHjzqJOTNtvpDIw+ 13 | BZIiOcxhz7UjnGeyp5dvpnEbmhmk0WhZ0tsP2czOQwZIDesx2Nhbz/V45X1qDU3O 14 | W0K9g37n7m1zsWHlA7LXwpSzG+wJTRWMOVGUxfyg 15 | -----END CERTIFICATE REQUEST----- 16 | -------------------------------------------------------------------------------- /unit-test/certs/server.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICsTCCAZkCFFwVYVZ4Uu9R0mhodJQCkUUSelbEMA0GCSqGSIb3DQEBCwUAMBUx 3 | EzARBgNVBAMMCiouZGVtby5jb20wHhcNMjAwMjE0MTI0OTA1WhcNMzMxMDIzMTI0 4 | OTA1WjAVMRMwEQYDVQQDDAoqLmRlbW8uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOC 5 | AQ8AMIIBCgKCAQEAwLHEXgjzTX6Z7MvPI1IAgwiEGuFyPl8b8o/tY9+2mvvs7EU4 6 | oK3DDRFoGwkTGfuLwstuhKllE2QyIr5QN6FmfWWiitjOovlEVRTJ5a274YXes9Kz 7 | uFlw6RT9WDj2iEkgdB7KWfQjaoCWrjhNt1rzh/jRpcmHsLmpOiQYBPeIpqVTnK1o 8 | risQ6352qnmperB8lcj731rKebDwZIo9y5nL/qDzwH3dBJQeFqvNuPcSd76lrpy+ 9 | 9GTA3lFgQQJyUiSwzBD005LKKW4fEcdllPa+/jLAuKO/atm+6dv186w7ojIMceir 10 | 549jn9UUyvWXfSfXl+68Aku1FTFFhRdS6OMsWQIDAQABMA0GCSqGSIb3DQEBCwUA 11 | A4IBAQCLCr8rsrgZskc3Ou7dZ5Br8xA2m7lrLSkFQIsDRosfBPerhGr83mgeyp2+ 12 | DNbPy0+IzgBUyN8N/P3QlZbQFq/3u9bjih3QukJuJe6KfYI0/iQu5jHxFv7VgbE+ 13 | a8yqUsrirWsmpltOMobv19jtWm/v1kofvCIUSBCJXkVi2L75164MhkKTGbSV1dl/ 14 | Ujg+X9yss5ZcDR+MqzuHZOO9580Ky0p+9m+STpZFG7QvC9QQtbvUBogAWECg+sSB 15 | RQ7Maq337ERpJg5EGOG2R+sa8rssMGFMRJ9OfenS+KaRF/oNKKL12pG7Y+oYpfEj 16 | WfSt4Lv16RWdV2vkmrorTovSuTIa 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /unit-test/certs/server.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICWjCCAUICAQAwFTETMBEGA1UEAwwKKi5kZW1vLmNvbTCCASIwDQYJKoZIhvcN 3 | AQEBBQADggEPADCCAQoCggEBAMCxxF4I801+mezLzyNSAIMIhBrhcj5fG/KP7WPf 4 | tpr77OxFOKCtww0RaBsJExn7i8LLboSpZRNkMiK+UDehZn1loorYzqL5RFUUyeWt 5 | u+GF3rPSs7hZcOkU/Vg49ohJIHQeyln0I2qAlq44Tbda84f40aXJh7C5qTokGAT3 6 | iKalU5ytaK4rEOt+dqp5qXqwfJXI+99aynmw8GSKPcuZy/6g88B93QSUHharzbj3 7 | Ene+pa6cvvRkwN5RYEECclIksMwQ9NOSyiluHxHHZZT2vv4ywLijv2rZvunb9fOs 8 | O6IyDHHoq+ePY5/VFMr1l30n15fuvAJLtRUxRYUXUujjLFkCAwEAAaAAMA0GCSqG 9 | SIb3DQEBCwUAA4IBAQBLD12Bwb5YZE0PSLMm37/KMoN1nl1bug002HXGjtK48I+J 10 | 8pyd4BX5yW69gIP/CeHouDqJ/vhTdJmm/mLsexcby21RW55XYouCGLT/Cmh5qj+K 11 | HmcMR6lo38Q324cjNaMiqX8yAthbfWIC2Wupzb69SUiaXqXZ7F5dC+tB8DSVEvIY 12 | LBwxcXQBHC4C4k5aCIaPTlA20wdT0CKmD914Jby+iP5HP64nvc5yxacjKO+uOwNB 13 | AZe/uLWeCJs6v372oiFaiN+m8EQhmcD/2i8qSiFCcC3V3MRAZitoJseaYnRR9Aev 14 | wYCI6lpn2nCdM/L0+uOxZ2sA3hkb2muoUSPaRLq/ 15 | -----END CERTIFICATE REQUEST----- 16 | -------------------------------------------------------------------------------- /unit-test/certs/server1.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICsTCCAZkCFFwVYVZ4Uu9R0mhodJQCkUUSelbGMA0GCSqGSIb3DQEBCwUAMBUx 3 | EzARBgNVBAMMCiouZGVtby5jb20wHhcNMjAwMjE0MTI0OTA2WhcNMzMxMDIzMTI0 4 | OTA2WjAVMRMwEQYDVQQDDAoqLmRlbW8uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOC 5 | AQ8AMIIBCgKCAQEA3o5I31gvK3AiF0sFAtHSt1diLMZEG1JtkeaKm9lIQgzqdG8+ 6 | f2nZPVAvU66M3B6uiYMU/QQVh3KAXF5bMyKhJtLGNYHqj6VoJatvWVdb1iasQW9M 7 | 8eGl2exxDMTPHWJ44vOYLcXJ6M3WRcfIXHC9K3rIjz2bWjDqHU8Y0fecCSJX8ctR 8 | gxgNBwM41P45dExbxQp5RGye7TOfXnf0yQJReFx2JDzzYqQ61VoqlkTw2RkuSr0Q 9 | ydr8S7CuReWF0xbKzMGf1L+SzmyGB2SAc9jkJ7T3Y4B36iy3y8hvMBTbCmke4ZpO 10 | FDrTw95wfC611nTXNKjUOlulKxSf+cfhACPFWwIDAQABMA0GCSqGSIb3DQEBCwUA 11 | A4IBAQCpQEXaFJiXSLeL9HKnvIexlxWfjTvikMoNR0t3UMxShazKE5gkQSw3WtCo 12 | E+LmmDvt0bqn54fk77oWxwZTx/qe8vJwpo0/gl/tNnGnzdzIAXk10G1W7kWkU2eG 13 | gpvYcQXKpW0QORHRzEXMbGIzdqjZOaFZYA+VtbtFB0cSLx8eNtd/bKxtwZyl66es 14 | uhPF40TnH6ccyq0Z2WuQylG4aSZ7qQcxCJUKj/Ych1+wr45ncgTZIsKXPBd0k7Kx 15 | xYvEuW8WGSjpJD8qPXt8hEwWpOfwLsmpnF1kMyaONLSHcqhfNU0bPTolLUSDJxkY 16 | 0JVVfeStdEsrmos1SrpEjD+wGlng 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /unit-test/certs/server1.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICWjCCAUICAQAwFTETMBEGA1UEAwwKKi5kZW1vLmNvbTCCASIwDQYJKoZIhvcN 3 | AQEBBQADggEPADCCAQoCggEBAN6OSN9YLytwIhdLBQLR0rdXYizGRBtSbZHmipvZ 4 | SEIM6nRvPn9p2T1QL1OujNweromDFP0EFYdygFxeWzMioSbSxjWB6o+laCWrb1lX 5 | W9YmrEFvTPHhpdnscQzEzx1ieOLzmC3FyejN1kXHyFxwvSt6yI89m1ow6h1PGNH3 6 | nAkiV/HLUYMYDQcDONT+OXRMW8UKeURsnu0zn1539MkCUXhcdiQ882KkOtVaKpZE 7 | 8NkZLkq9EMna/EuwrkXlhdMWyszBn9S/ks5shgdkgHPY5Ce092OAd+ost8vIbzAU 8 | 2wppHuGaThQ608PecHwutdZ01zSo1DpbpSsUn/nH4QAjxVsCAwEAAaAAMA0GCSqG 9 | SIb3DQEBCwUAA4IBAQBUY5PIac76NGf+rHFG0xAXrZDuttwJOUjywz0La//+iPPK 10 | RFm+x+LK5tLc6Iunfo3Po7BedISIQ1+QxA8l2x6SmEczrJxGolwgjkj4iozhL5m+ 11 | UKbsKF6V+3ZF7wHcbVZ9dCQsr6dO39Qg4x07U0DUDll4L3bk7cMyZBX2WAq3Tp6u 12 | jBJI96A8VcnVs0lTghQNfJlGBv6OFPXJPHpgJucZ/e4Kpbr/bMxVF/bRRoEaNz1G 13 | 1JbieeB4Ohv0P3SzYTj4zgOYV1NTizg1a7SeODFJ3uDtGm2oN3TAzE6yg3ngzxvk 14 | u+F5d+KbhSewBe/AuAWIK1Jn1Ez3NGMoR5zMbKCg 15 | -----END CERTIFICATE REQUEST----- 16 | -------------------------------------------------------------------------------- /unit-test/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "util/tc_common.h" 5 | #include "util/tc_logger.h" 6 | #include "gtest/gtest.h" 7 | 8 | using namespace std; 9 | using namespace tars; 10 | 11 | int main(int argc, char** argv) 12 | { 13 | #if TARGET_PLATFORM_LINUX || TARGET_PLATFORM_IOS 14 | tars::TC_Common::ignorePipe(); 15 | #endif 16 | 17 | testing::InitGoogleTest(&argc, argv); 18 | return RUN_ALL_TESTS(); 19 | } -------------------------------------------------------------------------------- /unit-test/rpc/test_auth.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "hello_test.h" 3 | 4 | TEST_F(HelloTest, authSyncServerCommunicator) 5 | { 6 | transServerCommunicator([&](Communicator *comm){ 7 | checkSync(comm, "AuthObjAdapter"); 8 | }); 9 | } 10 | 11 | TEST_F(HelloTest, authASyncGlobalCommunicatorInCoroutine) 12 | { 13 | transInCoroutineServerCommunicator([&](Communicator *comm){ 14 | checkASync(comm, "AuthObjAdapter"); 15 | }); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /unit-test/rpc/test_close.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "hello_test.h" 3 | #include "servant/CommunicatorEpoll.h" 4 | #include "servant/ObjectProxy.h" 5 | #include "server/HelloImp.h" 6 | #include "server/WinServer.h" 7 | 8 | TEST_F(HelloTest, prxClose) 9 | { 10 | auto comm = getCommunicator(); 11 | 12 | WinServer ws; 13 | startServer(ws, WIN_CONFIG()); 14 | 15 | string obj = getObj(ws.getConfig(), "WinAdapter"); 16 | 17 | HelloPrx prx = comm->stringToProxy(obj); 18 | prx->testClose(); 19 | 20 | EXPECT_EQ(HelloImp::_current.size(), 1); 21 | 22 | prx->tars_close(); 23 | 24 | TC_Common::msleep(10); 25 | EXPECT_EQ(HelloImp::_current.size(), 0); 26 | 27 | stopServer(ws); 28 | 29 | } 30 | 31 | TEST_F(HelloTest, prxCloseInCoroutine) 32 | { 33 | auto comm = getCommunicator(); 34 | 35 | WinServer ws; 36 | startServer(ws, WIN_CONFIG()); 37 | 38 | string obj = getObj(ws.getConfig(), "WinAdapter"); 39 | 40 | HelloPrx prx = comm->stringToProxy(obj); 41 | prx->testClose(); 42 | 43 | EXPECT_EQ(HelloImp::_current.size(), 1); 44 | 45 | funcInCoroutine([&](){ 46 | prx->testClose(); 47 | }); 48 | 49 | EXPECT_EQ(HelloImp::_current.size(), 2); 50 | 51 | prx->tars_close(); 52 | 53 | TC_Common::msleep(100); 54 | EXPECT_LE(HelloImp::_current.size(), 2); 55 | 56 | stopServer(ws); 57 | 58 | } -------------------------------------------------------------------------------- /unit-test/rpc/test_custom.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "hello_test.h" 3 | 4 | TEST_F(HelloTest, customSyncGlobalCommunicator) 5 | { 6 | shared_ptr c = getCommunicator(); 7 | 8 | transGlobalCommunicator([&](Communicator *comm){ 9 | syncCustom(comm); 10 | }, c.get()); 11 | } 12 | 13 | TEST_F(HelloTest, customASyncGlobalCommunicatorInCoroutine) 14 | { 15 | shared_ptr c = getCommunicator(); 16 | 17 | transInCoroutineGlobalCommunicator([&](Communicator *comm){ 18 | asyncCustom(comm); 19 | }, c.get()); 20 | } 21 | -------------------------------------------------------------------------------- /unit-test/rpc/test_wup.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "hello_test.h" 3 | 4 | TEST_F(HelloTest, wupSync) 5 | { 6 | forEach([&](){ 7 | checkWup(); 8 | }); 9 | } 10 | -------------------------------------------------------------------------------- /unit-test/server/CustomImp.cpp: -------------------------------------------------------------------------------- 1 | #include "CustomImp.h" 2 | #include "servant/Application.h" 3 | 4 | using namespace std; 5 | 6 | ////////////////////////////////////////////////////// 7 | void CustomImp::initialize() 8 | { 9 | //initialize servant here: 10 | //... 11 | } 12 | 13 | ////////////////////////////////////////////////////// 14 | void CustomImp::destroy() 15 | { 16 | //destroy servant here: 17 | //... 18 | } 19 | 20 | 21 | int CustomImp::doRequest(tars::CurrentPtr current, vector& response) 22 | { 23 | //Return to the data package requested by the client itself, that is, the original package return (4-byte length + 4-byte request + buffer) 24 | const vector& request = current->getRequestBuffer(); 25 | response = request; 26 | 27 | // cout << "doRequest: requestId:" << current->getRequestId() << ", funcName:" << current->getFuncName() << endl; 28 | return 0; 29 | } 30 | 31 | int CustomImp::doClose(CurrentPtr current) 32 | { 33 | LOG->debug() << "close ip: " << current->getIp() << endl; 34 | 35 | return 0; 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /unit-test/server/CustomImp.h: -------------------------------------------------------------------------------- 1 | #ifndef _CustomServantImp_H_ 2 | #define _CustomServantImp_H_ 3 | 4 | #include "servant/Application.h" 5 | //#include "CustomServant.h" 6 | 7 | /** 8 | * 9 | * 10 | */ 11 | class CustomImp : public tars::Servant 12 | { 13 | public: 14 | /** 15 | * 16 | */ 17 | virtual ~CustomImp() {} 18 | 19 | /** 20 | * 21 | */ 22 | virtual void initialize(); 23 | 24 | /** 25 | * 26 | */ 27 | virtual void destroy(); 28 | 29 | //overloading method of Servant::doRequest 30 | int doRequest(tars::CurrentPtr current, vector& response); 31 | 32 | //overloading method of Servant::doClose 33 | int doClose(tars::CurrentPtr current); 34 | 35 | }; 36 | ///////////////////////////////////////////////////// 37 | #endif 38 | -------------------------------------------------------------------------------- /unit-test/server/HelloServer.h: -------------------------------------------------------------------------------- 1 | #ifndef __HelloServer_H_ 2 | #define __HelloServer_H_ 3 | 4 | #include 5 | #include "servant/Application.h" 6 | #include "PushThread.h" 7 | 8 | using namespace tars; 9 | 10 | extern string g_HelloServerObj; 11 | extern string g_TransDstServerObj; 12 | extern atomic g_handleDestroy; 13 | 14 | class HelloServer : public Application, public TC_Thread 15 | { 16 | public: 17 | HelloServer() {} 18 | virtual ~HelloServer() {} 19 | /** 20 | * 服务初始化 21 | **/ 22 | virtual void initialize(); 23 | 24 | /** 25 | * 服务销毁 26 | **/ 27 | virtual void destroyApp(); 28 | 29 | protected: 30 | virtual void run(); 31 | 32 | private: 33 | //用于push消息的线程 34 | PushInfoThread *pushThread; 35 | 36 | }; 37 | 38 | //////////////////////////////////////////// 39 | #endif 40 | -------------------------------------------------------------------------------- /unit-test/server/HttpImp.cpp: -------------------------------------------------------------------------------- 1 | #include "HttpImp.h" 2 | //#include "HttpServer.h" 3 | #include "servant/RemoteLogger.h" 4 | #include "util/tc_http.h" 5 | 6 | using namespace tars; 7 | 8 | HttpImp::HttpImp() 9 | { 10 | } 11 | 12 | int HttpImp::doRequest(tars::CurrentPtr current, vector& response) 13 | { 14 | const vector& request = current->getRequestBuffer(); 15 | 16 | // LOG_CONSOLE_DEBUG << string(request.data(), request.size()) << endl; 17 | 18 | TC_HttpRequest req; 19 | req.decode(request); 20 | 21 | TC_HttpResponse rsp; 22 | rsp.setResponse(200, "OK", req.getContent()); 23 | // rsp.setContentType("text/html;charset=utf-8"); 24 | // rsp.setConnection("close"); 25 | string buffer = rsp.encode(); 26 | 27 | // LOG_CONSOLE_DEBUG << buffer << endl; 28 | 29 | current->sendResponse(buffer.c_str(), (uint32_t)buffer.length()); 30 | // current->close(); 31 | 32 | return 0; 33 | } 34 | 35 | void HttpImp::initialize() 36 | { 37 | } 38 | 39 | void HttpImp::destroy() 40 | { 41 | } 42 | 43 | /////////////////////////////////////////////////////////////////////////////// 44 | -------------------------------------------------------------------------------- /unit-test/server/HttpImp.h: -------------------------------------------------------------------------------- 1 | #ifndef _HTTP_IMP_H_ 2 | #define _HTTP_IMP_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include "servant/Application.h" 8 | 9 | using namespace std; 10 | using namespace tars; 11 | 12 | ///////////////////////////////////////////////////////////////////////// 13 | class HttpImp : public Servant { 14 | 15 | public: 16 | /** 17 | * 构造函数 18 | */ 19 | HttpImp(); 20 | 21 | public: 22 | /** 23 | * 对象初始化 24 | */ 25 | virtual void initialize(); 26 | 27 | /** 28 | * 处理客户端的主动请求 29 | * @param current 30 | * @param response 31 | * @return int 32 | */ 33 | virtual int doRequest(tars::CurrentPtr current, vector &response); 34 | 35 | /** 36 | * 对象销毁 37 | */ 38 | virtual void destroy(); 39 | }; 40 | /////////////////////////////////////////////////////////////////////////////// 41 | #endif 42 | -------------------------------------------------------------------------------- /unit-test/server/Push.tars: -------------------------------------------------------------------------------- 1 | 2 | module Test 3 | { 4 | interface Push 5 | { 6 | int testPush(out string msg); 7 | }; 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /unit-test/server/PushImp.h: -------------------------------------------------------------------------------- 1 | #ifndef _PushImp_H_ 2 | #define _PushImp_H_ 3 | 4 | #include "servant/Application.h" 5 | //#include "TestPushServant.h" 6 | 7 | /** 8 | * 9 | * 10 | */ 11 | class PushImp : public tars::Servant 12 | { 13 | public: 14 | /** 15 | * 16 | */ 17 | virtual ~PushImp() {} 18 | 19 | /** 20 | * 21 | */ 22 | virtual void initialize(); 23 | 24 | /** 25 | * 26 | */ 27 | virtual void destroy(); 28 | 29 | //重载Servant的doRequest方法 30 | int doRequest(tars::CurrentPtr current, vector& response); 31 | 32 | //重载Servant的doClose方法 33 | int doClose(tars::CurrentPtr current); 34 | 35 | }; 36 | ///////////////////////////////////////////////////// 37 | #endif 38 | -------------------------------------------------------------------------------- /unit-test/server/PushThread.h: -------------------------------------------------------------------------------- 1 | #ifndef __PUSH_THREAD_H 2 | #define __PUSH_THREAD_H 3 | 4 | #include "servant/Application.h" 5 | 6 | class PushUser 7 | { 8 | public: 9 | static map pushUser; 10 | static TC_ThreadMutex mapMutex; 11 | }; 12 | 13 | class PushInfoThread : public TC_Thread, public TC_ThreadLock 14 | { 15 | public: 16 | PushInfoThread():_bTerminate(false),_iId(0){} 17 | ~PushInfoThread(); 18 | 19 | virtual void run(); 20 | 21 | void terminate(); 22 | 23 | void setPushInfo(const string &sInfo); 24 | 25 | private: 26 | bool _bTerminate; 27 | unsigned int _iId; 28 | string _sPushInfo; 29 | }; 30 | #endif 31 | -------------------------------------------------------------------------------- /unit-test/server/RpcServer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by jarod on 2024/3/14. 3 | // 4 | 5 | #include "RpcServer.h" 6 | #include "HelloImp.h" 7 | #include "HttpImp.h" 8 | 9 | RpcServer::~RpcServer() 10 | { 11 | 12 | } 13 | 14 | 15 | void 16 | RpcServer::initialize() 17 | { 18 | addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".HelloObj"); 19 | addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".HttpObj"); 20 | addServantProtocol(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".HttpObj", &TC_NetWorkBuffer::parseHttp); 21 | 22 | } 23 | 24 | ///////////////////////////////////////////////////////////////// 25 | void RpcServer::destroyApp() 26 | { 27 | } 28 | 29 | void RpcServer::run() 30 | { 31 | this->waitForShutdown(); 32 | } -------------------------------------------------------------------------------- /unit-test/server/RpcServer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by jarod on 2024/3/14. 3 | // 4 | 5 | #pragma once 6 | #include 7 | #include "servant/Application.h" 8 | 9 | using namespace tars; 10 | 11 | class RpcServer : public Application, public TC_Thread 12 | { 13 | public: 14 | /** 15 | * 析构函数 16 | **/ 17 | virtual ~RpcServer(); 18 | 19 | /** 20 | * 服务初始化 21 | **/ 22 | virtual void initialize(); 23 | 24 | /** 25 | * 服务销毁 26 | **/ 27 | virtual void destroyApp(); 28 | 29 | protected: 30 | virtual void run(); 31 | 32 | }; 33 | -------------------------------------------------------------------------------- /unit-test/server/TranImp.h: -------------------------------------------------------------------------------- 1 | #ifndef _TRAN_IMP_H_ 2 | #define _TRAN_IMP_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include "servant/Application.h" 8 | 9 | using namespace std; 10 | using namespace tars; 11 | 12 | ///////////////////////////////////////////////////////////////////////// 13 | class TranImp : public Servant { 14 | 15 | public: 16 | /** 17 | * 构造函数 18 | */ 19 | TranImp(); 20 | 21 | public: 22 | /** 23 | * 对象初始化 24 | */ 25 | virtual void initialize(); 26 | 27 | /** 28 | * 处理客户端的主动请求 29 | * @param current 30 | * @param response 31 | * @return int 32 | */ 33 | virtual int doRequest(tars::CurrentPtr current, vector &response); 34 | 35 | /** 36 | * @param resp 37 | * @return int 38 | */ 39 | virtual int doResponse(ReqMessagePtr resp); 40 | 41 | /** 42 | * 对象销毁 43 | */ 44 | virtual void destroy(); 45 | 46 | protected: 47 | void async_call(tars::CurrentPtr current, vector &response); 48 | protected: 49 | ServantPrx _servantPrx; 50 | 51 | }; 52 | /////////////////////////////////////////////////////////////////////////////// 53 | #endif 54 | -------------------------------------------------------------------------------- /unit-test/server/WinServer.cpp: -------------------------------------------------------------------------------- 1 | #include "WinServer.h" 2 | #include "HelloImp.h" 3 | #include "servant/Application.h" 4 | 5 | using namespace std; 6 | 7 | WinServer::~WinServer() 8 | { 9 | 10 | } 11 | 12 | 13 | void 14 | WinServer::initialize() 15 | { 16 | addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".WinObj"); 17 | 18 | addConfig("test.conf"); 19 | TARS_ADD_ADMIN_CMD_NORMAL("AdminCmdNormalTest", WinServer::cmdAdd); 20 | 21 | TARS_ADD_ADMIN_CMD_NORMAL("CmdToDelete", WinServer::cmdAdd); 22 | 23 | getNotifyObserver()->unregisterNotify("CmdToDelete", this); 24 | 25 | TARS_ADD_ADMIN_CMD_NORMAL("DeletePrefixCmd", WinServer::delTarsViewVersion); 26 | 27 | } 28 | 29 | void WinServer::destroyApp() 30 | { 31 | _destroyApp = true; 32 | } 33 | 34 | void WinServer::run() 35 | { 36 | this->waitForShutdown(); 37 | } 38 | 39 | bool WinServer::cmdAdd(const string& command, const string& params, string& result) 40 | { 41 | result = params + " AdminCmdNormalTest success!"; 42 | return true; 43 | } 44 | 45 | bool WinServer::delTarsViewVersion(const string& command, const string& params, string& result) 46 | { 47 | getNotifyObserver()->unregisterPrefix("tars.viewversion", this); 48 | 49 | result = "Delete success!"; 50 | return true; 51 | } 52 | -------------------------------------------------------------------------------- /unit-test/server/WinServer.h: -------------------------------------------------------------------------------- 1 | #ifndef _WinServer_H_ 2 | #define _WinServer_H_ 3 | 4 | #include 5 | #include "servant/Application.h" 6 | 7 | using namespace tars; 8 | 9 | class WinServer : public Application, public TC_Thread 10 | { 11 | public: 12 | /** 13 | * 析构函数 14 | **/ 15 | virtual ~WinServer(); 16 | 17 | /** 18 | * 服务初始化 19 | **/ 20 | virtual void initialize(); 21 | 22 | /** 23 | * 服务销毁 24 | **/ 25 | virtual void destroyApp(); 26 | 27 | bool cmdAdd(const string& command, const string& params, string& result); 28 | 29 | bool delTarsViewVersion(const string& command, const string& params, string& result); 30 | 31 | protected: 32 | virtual void run(); 33 | 34 | public: 35 | bool _destroyApp = false; 36 | 37 | }; 38 | 39 | //////////////////////////////////////////// 40 | #endif 41 | -------------------------------------------------------------------------------- /unit-test/util/test_tc_config.cpp: -------------------------------------------------------------------------------- 1 | #include "util/tc_config.h" 2 | #include "util/tc_common.h" 3 | #include 4 | #include "gtest/gtest.h" 5 | 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | using namespace tars; 11 | 12 | class UtilConfigTest : public testing::Test 13 | { 14 | public: 15 | //添加日志 16 | static void SetUpTestCase() 17 | { 18 | } 19 | static void TearDownTestCase() 20 | { 21 | } 22 | virtual void SetUp() //TEST跑之前会执行SetUp 23 | { 24 | } 25 | virtual void TearDown() //TEST跑完之后会执行TearDown 26 | { 27 | } 28 | }; 29 | 30 | #define CONFIG "\r\n" 31 | 32 | 33 | TEST_F(UtilConfigTest, config_test) 34 | { 35 | TC_Config conf; 36 | conf.parseString(CONFIG); 37 | 38 | conf.set("/root", "def"); 39 | 40 | ASSERT_TRUE(conf.get("/root") == "def"); 41 | 42 | conf.set("/root/test", "defdef"); 43 | 44 | ASSERT_TRUE(conf.get("/root/test") == "defdef"); 45 | 46 | conf.erase("/root/test"); 47 | 48 | ASSERT_TRUE(conf.get("/root/test") == ""); 49 | 50 | conf.eraseDomain("/root/test"); 51 | 52 | auto v =conf.getDomainVector("/root"); 53 | ASSERT_TRUE(v.empty()); 54 | 55 | } 56 | -------------------------------------------------------------------------------- /unit-test/util/test_tc_encoder.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by jarod on 2020/2/20. 3 | // 4 | 5 | #include "util/tc_encoder.h" 6 | #include "gtest/gtest.h" 7 | #include "util/tc_common.h" 8 | 9 | using namespace tars; 10 | 11 | class UtilEncodeTest : public testing::Test 12 | { 13 | public: 14 | //添加日志 15 | static void SetUpTestCase() 16 | { 17 | } 18 | static void TearDownTestCase() 19 | { 20 | } 21 | virtual void SetUp() //TEST跑之前会执行SetUp 22 | { 23 | } 24 | virtual void TearDown() //TEST跑完之后会执行TearDown 25 | { 26 | } 27 | }; 28 | 29 | TEST_F(UtilEncodeTest, encode) //此时使用的是TEST_F宏 30 | { 31 | string utf8="我们的祖国;"; 32 | string gbk; 33 | 34 | gbk = TC_Encoder::utf82gbk(utf8);//, TC_Encoder::ICONV_NORMAL); 35 | 36 | string tmpUtf8 = TC_Encoder::gbk2utf8(gbk);//, TC_Encoder::ICONV_NORMAL); 37 | 38 | ASSERT_TRUE(utf8 == tmpUtf8); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /unit-test/util/test_tc_logger.cpp: -------------------------------------------------------------------------------- 1 | #include "util/tc_common.h" 2 | #include "util/tc_cas_queue.h" 3 | #include "util/tc_thread.h" 4 | #include "util/tc_autoptr.h" 5 | #include "util/tc_spin_lock.h" 6 | #include "util/tc_thread_queue.h" 7 | #include "gtest/gtest.h" 8 | #include "servant/RemoteLogger.h" 9 | #include 10 | #include 11 | 12 | using namespace tars; 13 | 14 | class UtilLogTest : public testing::Test 15 | { 16 | public: 17 | //添加日志 18 | static void SetUpTestCase() 19 | { 20 | // cout<<"SetUpTestCase"<initFormat("./test.log", "%Y%m%d"); 39 | 40 | string s= "test"; 41 | 42 | int i = 10000000; 43 | while(i > 0) 44 | { 45 | FDLOG("abc") << s << endl; 46 | 47 | i--; 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /unit-test/util/test_tc_mysql.cpp: -------------------------------------------------------------------------------- 1 | #include "util/tc_common.h" 2 | #ifdef TARS_MYSQL 3 | #include "util/tc_mysql.h" 4 | #endif 5 | #include "gtest/gtest.h" 6 | 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | using namespace tars; 12 | 13 | class UtilMysqlTest : public testing::Test 14 | { 15 | public: 16 | //添加日志 17 | static void SetUpTestCase() 18 | { 19 | } 20 | static void TearDownTestCase() 21 | { 22 | } 23 | virtual void SetUp() //TEST跑之前会执行SetUp 24 | { 25 | } 26 | virtual void TearDown() //TEST跑完之后会执行TearDown 27 | { 28 | } 29 | }; 30 | 31 | #ifdef TARS_MYSQL 32 | 33 | TEST_F(UtilMysqlTest, test80) 34 | { 35 | try 36 | { 37 | TC_Mysql mysql; 38 | 39 | mysql.init("127.0.0.1", "root", "123456", "", "utf8", 3307, 0); 40 | 41 | mysql.queryRecord("select 1"); 42 | } 43 | catch(exception &ex) 44 | { 45 | cerr << ex.what() << endl; 46 | } 47 | 48 | try 49 | { 50 | TC_Mysql mysql; 51 | 52 | mysql.init("127.0.0.1", "root", "tars@12345", "", "utf8", 3306, 0); 53 | 54 | mysql.queryRecord("select 1"); 55 | 56 | cout << "success" << endl; 57 | } 58 | catch(exception &ex) 59 | { 60 | cerr << ex.what() << endl; 61 | } 62 | } 63 | 64 | #endif -------------------------------------------------------------------------------- /unit-test/util/test_tc_socket.cpp: -------------------------------------------------------------------------------- 1 | #include "util/tc_common.h" 2 | #include "util/tc_socket.h" 3 | #include "gtest/gtest.h" 4 | 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | using namespace tars; 10 | 11 | class UtilSocketTest : public testing::Test 12 | { 13 | public: 14 | //添加日志 15 | static void SetUpTestCase() 16 | { 17 | } 18 | static void TearDownTestCase() 19 | { 20 | } 21 | virtual void SetUp() //TEST跑之前会执行SetUp 22 | { 23 | } 24 | virtual void TearDown() //TEST跑完之后会执行TearDown 25 | { 26 | } 27 | }; 28 | 29 | TEST_F(UtilSocketTest, testGetLocalHosts) 30 | { 31 | vector v1 = TC_Socket::getLocalHosts(AF_INET); 32 | 33 | for(size_t i = 0; i < v1.size(); i++) 34 | { 35 | cout << v1[i] << endl; 36 | } 37 | 38 | vector v2 = TC_Socket::getLocalHosts(AF_INET6); 39 | 40 | for(size_t i = 0; i < v2.size(); i++) 41 | { 42 | cout << v2[i] << endl; 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /unit-test/util/test_tc_thread_pool.cpp: -------------------------------------------------------------------------------- 1 | #include "util/tc_timer.h" 2 | #include "util/tc_logger.h" 3 | #include "util/tc_common.h" 4 | #include "util/tc_thread_pool.h" 5 | #include "gtest/gtest.h" 6 | 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | using namespace tars; 12 | 13 | class UtilThreadPollTest : public testing::Test 14 | { 15 | public: 16 | //添加日志 17 | static void SetUpTestCase() 18 | { 19 | } 20 | static void TearDownTestCase() 21 | { 22 | } 23 | virtual void SetUp() //TEST跑之前会执行SetUp 24 | { 25 | } 26 | virtual void TearDown() //TEST跑完之后会执行TearDown 27 | { 28 | } 29 | }; 30 | 31 | class TestClass 32 | { 33 | public: 34 | ~TestClass() 35 | { 36 | // LOG_CONSOLE_DEBUG << endl; 37 | } 38 | void test(int i) 39 | { 40 | _data.push_back(i); 41 | } 42 | 43 | vector _data; 44 | }; 45 | 46 | TEST_F(UtilThreadPollTest, testDecontructor) 47 | { 48 | TC_ThreadPool tpool; 49 | tpool.init(5); 50 | shared_ptr tPtr = std::make_shared(); 51 | 52 | for(int i = 0; i < 5; i++) 53 | { 54 | tpool.exec(std::bind(&TestClass::test, tPtr.get(), std::placeholders::_1), i); 55 | } 56 | 57 | tpool.stop(); 58 | } -------------------------------------------------------------------------------- /unit-test/util/test_tc_timeout_queue_map.cpp: -------------------------------------------------------------------------------- 1 | #include "util/tc_timeout_queue_map.h" 2 | #include "util/tc_common.h" 3 | #include "gtest/gtest.h" 4 | 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | using namespace tars; 10 | 11 | class UtilTimeoutQueueMapTest : public testing::Test 12 | { 13 | public: 14 | //添加日志 15 | static void SetUpTestCase() 16 | { 17 | } 18 | static void TearDownTestCase() 19 | { 20 | } 21 | virtual void SetUp() //TEST跑之前会执行SetUp 22 | { 23 | } 24 | virtual void TearDown() //TEST跑完之后会执行TearDown 25 | { 26 | } 27 | }; 28 | 29 | TEST_F(UtilTimeoutQueueMapTest, test) 30 | { 31 | TC_TimeoutQueueMap queueMap; 32 | queueMap.setTimeout(100); 33 | 34 | queueMap.push("abc1", "def1"); 35 | queueMap.push("abc2", "def2"); 36 | queueMap.push("abc", "def"); 37 | 38 | TC_Common::msleep(110); 39 | queueMap.timeout(); 40 | 41 | EXPECT_EQ(queueMap.size(), 0); 42 | ASSERT_FALSE(queueMap.has("abc")); 43 | 44 | queueMap.push("abc", "def1"); 45 | TC_Common::msleep(50); 46 | queueMap.push("abc", "def2"); 47 | TC_Common::msleep(50); 48 | queueMap.push("abc", "def3"); 49 | TC_Common::msleep(50); 50 | 51 | queueMap.timeout(); 52 | ASSERT_TRUE(queueMap.has("abc")); 53 | EXPECT_EQ(queueMap.get("abc"), "def3"); 54 | EXPECT_EQ(queueMap.size(), 1); 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | project(util) 3 | 4 | if(WIN32) 5 | enable_language(ASM_MASM) 6 | else() 7 | enable_language(ASM) 8 | endif() 9 | 10 | 11 | add_subdirectory(src) 12 | add_subdirectory(include) 13 | 14 | 15 | -------------------------------------------------------------------------------- /util/README.md: -------------------------------------------------------------------------------- 1 | This project is the Tars base tool library. 2 | -------------------------------------------------------------------------------- /util/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | install(DIRECTORY util DESTINATION include) 3 | 4 | -------------------------------------------------------------------------------- /util/include/util/sys/epoll.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef EPOLL_H_ 3 | #define EPOLL_H_ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #define EPOLLIN 0x001 10 | // #define EPOLLPRI 0x002 11 | #define EPOLLOUT 0x004 12 | #define EPOLLERR 0x008 13 | #define EPOLLHUP 0x010 14 | #define EPOLLRDNORM 0x040 15 | #define EPOLLRDBAND 0x080 16 | #define EPOLLWRNORM 0x100 17 | // #define EPOLLMSG 0x400 18 | #define EPOLLWRBAND 0x200 19 | #define EPOLLRDHUP 0x2000 20 | 21 | /* #define EPOLLET (1 << 30) Not supported */ 22 | // #define EPOLLONESHOT (1 << 31) 23 | 24 | #define EPOLL_CTL_ADD 1 25 | #define EPOLL_CTL_MOD 2 26 | #define EPOLL_CTL_DEL 3 27 | 28 | typedef void *epoll_t; 29 | 30 | typedef union epoll_data { 31 | void *ptr; 32 | int fd; 33 | uint32_t u32; 34 | uint64_t u64; 35 | } epoll_data_t; 36 | 37 | struct epoll_event 38 | { 39 | uint32_t events; /* Epoll events */ 40 | epoll_data_t data; /* User data variable */ 41 | }; 42 | 43 | epoll_t epoll_create(int); 44 | 45 | int epoll_close(epoll_t epoll_hnd); 46 | 47 | int epoll_ctl(epoll_t epoll_hnd, int op, SOCKET sock, struct epoll_event *event); 48 | 49 | int epoll_wait(epoll_t epoll_hnd, struct epoll_event *events, int maxevents, int timeout); 50 | 51 | #endif /* EPOLL_H_ */ -------------------------------------------------------------------------------- /util/include/util/tc_coroutine_mutex.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include "util/tc_coroutine.h" 7 | #include "util/tc_spin_lock.h" 8 | 9 | namespace tars 10 | { 11 | ///////////////////////////////////////////////// 12 | /** 13 | * @file tc_coroutine_mutex.h 14 | * @brief 协程锁互斥类 15 | * 16 | * @author edisenwang 17 | */ 18 | ///////////////////////////////////////////////// 19 | 20 | /** 21 | * @brief 协程锁 . 22 | * 23 | * 开启协程后使用 24 | */ 25 | class UTIL_DLL_API TC_CoMutex 26 | { 27 | protected: 28 | struct CoMutexInfo 29 | { 30 | const std::shared_ptr _sched; 31 | uint32_t _coroId; 32 | 33 | CoMutexInfo(const std::shared_ptr sched, uint32_t coroId):_sched(sched), _coroId(coroId){} 34 | }; 35 | 36 | public: 37 | TC_CoMutex(); 38 | 39 | virtual ~TC_CoMutex(); 40 | 41 | /** 42 | * @brief 尝试锁 43 | * 44 | * @return bool 45 | */ 46 | bool try_lock(); 47 | 48 | /** 49 | * @brief 加锁 50 | */ 51 | void lock(); 52 | 53 | /** 54 | * @brief 解锁 55 | */ 56 | void unlock(); 57 | 58 | protected: 59 | 60 | // noncopyable 61 | TC_CoMutex(const TC_CoMutex&) = delete; 62 | void operator=(const TC_CoMutex&) = delete; 63 | 64 | protected: 65 | 66 | TC_SpinLock _slck; 67 | 68 | mutable std::mutex _mutex; 69 | 70 | std::list _list; 71 | }; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /util/include/util/tc_fcontext.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace tars 4 | { 5 | 6 | 7 | typedef void* fcontext_t; 8 | 9 | struct transfer_t { 10 | fcontext_t fctx; 11 | void * data; 12 | }; 13 | 14 | extern "C" transfer_t tars_jump_fcontext( fcontext_t const to, void * vp); 15 | extern "C" fcontext_t tars_make_fcontext( void * sp, std::size_t size, void (* fn)( transfer_t) ); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /util/include/util/tc_spin_lock.h: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #include "util/tc_platform.h" 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | namespace tars 11 | { 12 | 13 | /** 14 | * 自旋锁 15 | * 不能阻塞wait, 只能快速加解锁, 适用于锁粒度非常小的情况, 减小线程切换的开销 16 | * 不支持trylock 17 | */ 18 | class UTIL_DLL_API TC_SpinLock 19 | { 20 | public: 21 | 22 | TC_SpinLock(); 23 | virtual ~TC_SpinLock(); 24 | 25 | void lock() const; 26 | bool tryLock() const; 27 | void unlock() const; 28 | 29 | private: 30 | 31 | TC_SpinLock(const TC_SpinLock&) = delete; 32 | TC_SpinLock(TC_SpinLock&&) = delete; 33 | TC_SpinLock& operator=(const TC_SpinLock&) = delete; 34 | TC_SpinLock& operator=(TC_SpinLock&&) = delete; 35 | 36 | private: 37 | 38 | mutable std::atomic_flag _flag; 39 | }; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /util/include/util/tc_strptime.h: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #ifdef TARGET_PLATFORM_WINDOWS 5 | 6 | char * strptime(const char *buf, const char *fmt, struct tm *tm); 7 | #endif 8 | -------------------------------------------------------------------------------- /util/src/asm/jump_combined_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__i386__) 11 | #include "jump_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "jump_x86_64_sysv_macho_gas.S" 14 | #elif defined(__ppc__) 15 | #include "jump_ppc32_sysv_macho_gas.S" 16 | #elif defined(__ppc64__) 17 | #include "jump_ppc64_sysv_macho_gas.S" 18 | #elif defined(__arm__) 19 | #include "jump_arm_aapcs_macho_gas.S" 20 | #elif defined(__arm64__) 21 | #include "jump_arm64_aapcs_macho_gas.S" 22 | #else 23 | #error "No arch's" 24 | #endif 25 | -------------------------------------------------------------------------------- /util/src/asm/jump_i386_x86_64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__i386__) 11 | #include "jump_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "jump_x86_64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /util/src/asm/jump_ppc32_ppc64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__ppc__) 11 | #include "jump_ppc32_sysv_macho_gas.S" 12 | #elif defined(__ppc64__) 13 | #include "jump_ppc64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /util/src/asm/make_combined_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__i386__) 11 | #include "make_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "make_x86_64_sysv_macho_gas.S" 14 | #elif defined(__ppc__) 15 | #include "make_ppc32_sysv_macho_gas.S" 16 | #elif defined(__ppc64__) 17 | #include "make_ppc64_sysv_macho_gas.S" 18 | #elif defined(__arm__) 19 | #include "make_arm_aapcs_macho_gas.S" 20 | #elif defined(__arm64__) 21 | #include "make_arm64_aapcs_macho_gas.S" 22 | #else 23 | #error "No arch's" 24 | #endif 25 | -------------------------------------------------------------------------------- /util/src/asm/make_i386_x86_64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__i386__) 11 | #include "make_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "make_x86_64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /util/src/asm/make_ppc32_ppc64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__ppc__) 11 | #include "make_ppc32_sysv_macho_gas.S" 12 | #elif defined(__ppc64__) 13 | #include "make_ppc64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /util/src/asm/ontop_combined_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__i386__) 11 | #include "ontop_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "ontop_x86_64_sysv_macho_gas.S" 14 | #elif defined(__ppc__) 15 | #include "ontop_ppc32_sysv_macho_gas.S" 16 | #elif defined(__ppc64__) 17 | #include "ontop_ppc64_sysv_macho_gas.S" 18 | #elif defined(__arm__) 19 | #include "ontop_arm_aapcs_macho_gas.S" 20 | #elif defined(__arm64__) 21 | #include "ontop_arm64_aapcs_macho_gas.S" 22 | #else 23 | #error "No arch's" 24 | #endif 25 | -------------------------------------------------------------------------------- /util/src/asm/ontop_i386_x86_64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__i386__) 11 | #include "ontop_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "ontop_x86_64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /util/src/asm/ontop_ppc32_ppc64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__ppc__) 11 | #include "ontop_ppc32_sysv_macho_gas.S" 12 | #elif defined(__ppc64__) 13 | #include "ontop_ppc64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /util/src/tc_coroutine_mutex.cpp: -------------------------------------------------------------------------------- 1 | #include "util/tc_coroutine_mutex.h" 2 | 3 | namespace tars 4 | { 5 | TC_CoMutex::TC_CoMutex() 6 | { 7 | } 8 | 9 | TC_CoMutex::~TC_CoMutex() 10 | { 11 | } 12 | 13 | bool TC_CoMutex::try_lock() 14 | { 15 | return _slck.tryLock(); 16 | } 17 | 18 | void TC_CoMutex::lock() 19 | { 20 | if(_slck.tryLock()) 21 | { 22 | return ; 23 | } 24 | else 25 | { 26 | std::shared_ptr sched = TC_CoroutineScheduler::scheduler(); 27 | assert(sched && sched->getCoroutineId() != 0); 28 | { 29 | std::lock_guard lock(_mutex); 30 | //加锁后再检查一次, 如果获取到执行条件则直接退出 31 | if(_slck.tryLock()) 32 | { 33 | return ; 34 | } 35 | 36 | _list.emplace_back(CoMutexInfo(sched, sched->getCoroutineId())); 37 | } 38 | 39 | sched->yield(false); 40 | } 41 | } 42 | 43 | void TC_CoMutex::unlock() 44 | { 45 | std::lock_guard lock(_mutex); 46 | if(!_list.empty()) 47 | { 48 | CoMutexInfo &info= _list.front(); 49 | info._sched->put(info._coroId); 50 | _list.pop_front(); 51 | } 52 | else 53 | { 54 | _slck.unlock(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /util/src/tc_spin_lock.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "util/tc_spin_lock.h" 3 | #include "util/tc_common.h" 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | #define TRYS_COUNT 10 11 | #define TRYS_SLEEP 1 12 | namespace tars 13 | { 14 | 15 | TC_SpinLock::TC_SpinLock() 16 | { 17 | _flag.clear(std::memory_order_release); 18 | } 19 | 20 | TC_SpinLock::~TC_SpinLock() 21 | { 22 | } 23 | 24 | void TC_SpinLock::lock() const 25 | { 26 | for (size_t i = 1; _flag.test_and_set(std::memory_order_acquire); i++) 27 | { 28 | if(i % TRYS_COUNT == 0) 29 | { 30 | TC_Common::msleep(TRYS_SLEEP); 31 | } 32 | else 33 | { 34 | std::this_thread::yield(); 35 | } 36 | } 37 | } 38 | 39 | void TC_SpinLock::unlock() const 40 | { 41 | _flag.clear(std::memory_order_release); 42 | } 43 | 44 | bool TC_SpinLock::tryLock() const 45 | { 46 | int trys = TRYS_COUNT; 47 | for (; trys > 0 && _flag.test_and_set(std::memory_order_acquire); --trys) 48 | { 49 | std::this_thread::yield(); 50 | } 51 | 52 | if (trys > 0) 53 | return true; 54 | 55 | return false; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /util/src/tc_thread_cond.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #include "util/tc_thread_cond.h" 18 | #include "util/tc_timeprovider.h" 19 | #include 20 | #include 21 | #include 22 | 23 | using namespace std; 24 | 25 | 26 | namespace tars 27 | { 28 | 29 | TC_ThreadCond::TC_ThreadCond() 30 | { 31 | } 32 | 33 | TC_ThreadCond::~TC_ThreadCond() 34 | { 35 | } 36 | 37 | void TC_ThreadCond::signal() 38 | { 39 | _cond.notify_one(); 40 | } 41 | 42 | void TC_ThreadCond::broadcast() 43 | { 44 | _cond.notify_all(); 45 | } 46 | 47 | } 48 | 49 | --------------------------------------------------------------------------------