Pārlūkot izejas kodu

support http1, change file name same to taf

ruanshudong 4 gadi atpakaļ
vecāks
revīzija
6d5f517be7
100 mainītis faili ar 2353 papildinājumiem un 4511 dzēšanām
  1. 4 0
      CMakeLists.txt
  2. 14 5
      cmake/Common.cmake
  3. 1 1
      examples/AuthDemo/Client/main.cpp
  4. 43 43
      examples/CMakeLists.txt
  5. 1 1
      examples/CoroutineDemo/client/main.cpp
  6. 1 1
      examples/CustomDemo/CustomClient/main.cpp
  7. 30 41
      examples/HttpDemo/Http2Client/main.cpp
  8. 2 0
      examples/HttpDemo/Http2Server/Http2Imp.cpp
  9. 246 187
      examples/HttpDemo/HttpClient/main.cpp
  10. 7 7
      examples/HttpDemo/HttpServer/HttpImp.cpp
  11. 1 1
      examples/QuickStartDemo/HelloServer/Client/main.cpp
  12. 12 12
      examples/SSLDemo/Client/config.conf
  13. 1 1
      examples/SSLDemo/Client/main.cpp
  14. 12 12
      examples/SSLDemo/Server/config.conf
  15. 1 1
      examples/scripts/run-auth.bat
  16. 1 1
      examples/scripts/run-auth.sh
  17. 1 1
      examples/scripts/run-co.bat
  18. 1 1
      examples/scripts/run-co.sh
  19. 1 1
      examples/scripts/run-custom.bat
  20. 1 1
      examples/scripts/run-custom.sh
  21. 1 1
      examples/scripts/run-http.bat
  22. 4 2
      examples/scripts/run-http.sh
  23. 1 1
      examples/scripts/run-http2.bat
  24. 1 1
      examples/scripts/run-http2.sh
  25. 1 1
      examples/scripts/run-push.bat
  26. 1 1
      examples/scripts/run-push.sh
  27. 1 1
      examples/scripts/run-quick-start.bat
  28. 1 1
      examples/scripts/run-quick-start.sh
  29. 1 1
      examples/scripts/run-ssl.bat
  30. 1 1
      examples/scripts/run-ssl.sh
  31. 1 1
      examples/scripts/run-udp.bat
  32. 1 1
      examples/scripts/run-udp.sh
  33. 1 1
      servant/CMakeLists.txt
  34. 372 100
      servant/libservant/AdapterProxy.cpp
  35. 1 1
      servant/libservant/AdminServant.cpp
  36. 116 35
      servant/libservant/AppProtocol.cpp
  37. 68 35
      servant/libservant/Application.cpp
  38. 2 2
      servant/libservant/AsyncProcThread.cpp
  39. 1 1
      servant/libservant/CMakeLists.txt
  40. 44 19
      servant/libservant/Communicator.cpp
  41. 2 2
      servant/libservant/CommunicatorEpoll.cpp
  42. 1 1
      servant/libservant/CoroutineScheduler.cpp
  43. 1 1
      servant/libservant/EndpointInfo.cpp
  44. 29 4
      servant/libservant/EndpointManager.cpp
  45. 2 20
      servant/libservant/NetworkUtil.cpp
  46. 115 36
      servant/libservant/ObjectProxy.cpp
  47. 1 1
      servant/libservant/Servant.cpp
  48. 17 31
      servant/libservant/ServantHandle.cpp
  49. 251 55
      servant/libservant/ServantProxy.cpp
  50. 1 1
      servant/libservant/ServantProxyFactory.cpp
  51. 3 3
      servant/libservant/StatReport.cpp
  52. 0 213
      servant/libservant/TarsConfig.cpp
  53. 0 437
      servant/libservant/TarsCurrent.cpp
  54. 0 723
      servant/libservant/TarsLogger.cpp
  55. 0 116
      servant/libservant/TarsNodeF.cpp
  56. 0 132
      servant/libservant/TarsNotify.cpp
  57. 14 12
      servant/libservant/Transceiver.cpp
  58. 4 4
      servant/makefile/makefile.tars
  59. 64 18
      servant/servant/AdapterProxy.h
  60. 1 1
      servant/servant/AdminServant.h
  61. 2 2
      servant/servant/AppCache.h
  62. 2 0
      servant/servant/AppProtocol.h
  63. 23 11
      servant/servant/Application.h
  64. 27 11
      servant/servant/Communicator.h
  65. 4 7
      servant/servant/CommunicatorEpoll.h
  66. 19 7
      servant/servant/EndpointManager.h
  67. 12 4
      servant/servant/Global.h
  68. 9 59
      servant/servant/Message.h
  69. 1 1
      servant/servant/NotifyObserver.h
  70. 70 16
      servant/servant/ObjectProxy.h
  71. 5 5
      servant/servant/PropertyReport.h
  72. 2 2
      servant/servant/Servant.h
  73. 9 15
      servant/servant/ServantHandle.h
  74. 4 4
      servant/servant/ServantHelper.h
  75. 146 41
      servant/servant/ServantProxy.h
  76. 5 0
      servant/servant/StatReport.h
  77. 0 154
      servant/servant/TarsConfig.h
  78. 0 72
      servant/servant/TarsCookie.h
  79. 0 330
      servant/servant/TarsCurrent.h
  80. 0 893
      servant/servant/TarsLogger.h
  81. 0 80
      servant/servant/TarsNodeF.h
  82. 0 101
      servant/servant/TarsNotify.h
  83. 2 2
      servant/servant/Transceiver.h
  84. 4 4
      tools/tars2node/gen_server_ts.cpp
  85. 18 18
      tools/tarsparse/tars.lex.cpp
  86. 132 132
      tools/tarsparse/tars.tab.cpp
  87. 2 2
      util/include/util/tc_autoptr.h
  88. 12 12
      util/include/util/tc_common.h
  89. 6 6
      util/include/util/tc_epoll_server.h
  90. 1 2
      util/include/util/tc_ex.h
  91. 173 111
      util/include/util/tc_http.h
  92. 5 4
      util/include/util/tc_http2.h
  93. 19 18
      util/include/util/tc_logger.h
  94. 11 5
      util/include/util/tc_network_buffer.h
  95. 1 1
      util/include/util/tc_openssl.h
  96. 39 0
      util/include/util/tc_platform.h
  97. 72 37
      util/include/util/tc_singleton.h
  98. 2 1
      util/include/util/tc_spin_lock.h
  99. 5 4
      util/include/util/tc_thread_mutex.h
  100. 2 1
      util/include/util/tc_thread_rwlock.h

+ 4 - 0
CMakeLists.txt

@@ -18,6 +18,10 @@ if("${TARS_CPP_COMMON}" STREQUAL "")
 
 endif()
 
+set(CLEAR_INCLUDE "clear-install.cmake")
+FILE(WRITE ${CLEAR_INCLUDE} "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_INSTALL_PREFIX}/include)\n")
+install(SCRIPT ${CLEAR_INCLUDE})
+
 #-------------------------------------------------------------------
 
 include_directories(${PROJECT_SOURCE_DIR}/util/include)

+ 14 - 5
cmake/Common.cmake

@@ -21,11 +21,18 @@ foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
     set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/bin)
 endforeach()   
 
-set(_USE_OPENTRACKING $ENV{_USE_OPENTRACKING})
-if(_USE_OPENTRACKING)
-set(OPENTRACKING_INC "/usr/local/include")
-add_definitions(-D_USE_OPENTRACKING=${_USE_OPENTRACKING})
-endif()
+option(TARS_OPENTRACKING "option for open tracking" OFF)
+
+if (TARS_OPENTRACKING)
+    add_definitions(-DTARS_OPENTRACKING=1)
+    set(OPENTRACKING_INC "/usr/local/include")
+endif ()
+
+# set(TARS_OPENTRACKING $ENV{TARS_OPENTRACKING})
+# if(TARS_OPENTRACKING)
+# set(OPENTRACKING_INC "/usr/local/include")
+# add_definitions(-D_USE_OPENTRACKING=${TARS_OPENTRACKING})
+# endif()
 
 #-------------------------------------------------------------
 
@@ -88,5 +95,7 @@ message("PLATFORM:                  ${PLATFORM}")
 message("CMAKE_INSTALL_PREFIX:      ${CMAKE_INSTALL_PREFIX}")
 message("BIN:                       ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") 
 message("TARS2CPP:                  ${TARS2CPP}") 
+message("TARS_OPENTRACKING:         ${TARS_OPENTRACKING}") 
+
 #-------------------------------------------------------------
 

+ 1 - 1
examples/AuthDemo/Client/main.cpp

@@ -153,7 +153,7 @@ int main(int argc, char *argv[])
         conf.parseFile(option.getValue("config"));
 	    _comm->setProperty(conf);
 
-//        TarsRollLogger::getInstance()->logger()->setLogLevel(6);
+//        LocalRollLogger::getInstance()->logger()->setLogLevel(6);
 
         _comm->setProperty("sendqueuelimit", "1000000");
         _comm->setProperty("asyncqueuecap", "1000000");

+ 43 - 43
examples/CMakeLists.txt

@@ -14,7 +14,7 @@ add_subdirectory(QuickStartDemo)
 add_subdirectory(StressDemo)
 add_subdirectory(UdpDemo)
 
-set(WORKING_DIRECTORY ${tars-cpp_SOURCE_DIR})
+set(WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
 
 if(WIN32)
 
@@ -22,28 +22,28 @@ if(WIN32)
             WORKING_DIRECTORY ${WORKING_DIRECTORY}
             DEPENDS QuickStartDemo QuickStartDemoClient
             USES_TERMINAL
-            COMMAND examples/scripts/run-quick-start.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND ../examples/scripts/run-quick-start.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
             COMMENT "call quick start")
 
     add_custom_target(run-http
             WORKING_DIRECTORY ${WORKING_DIRECTORY}
             DEPENDS HttpServer HttpClient
             USES_TERMINAL
-            COMMAND examples/scripts/run-http.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND ../examples/scripts/run-http.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
             COMMENT "call run http")
 
     add_custom_target(run-auth
             WORKING_DIRECTORY ${WORKING_DIRECTORY}
             DEPENDS AuthServer AuthClient
             USES_TERMINAL
-            COMMAND examples/scripts/run-auth.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND ../examples/scripts/run-auth.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
             COMMENT "call run auth")
 
     add_custom_target(run-udp
             WORKING_DIRECTORY ${WORKING_DIRECTORY}
             DEPENDS UdpServer UdpClient
             USES_TERMINAL
-            COMMAND examples/scripts/run-udp.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND ../examples/scripts/run-udp.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
             COMMENT "call run udp")
 
     if(TARS_HTTP2)
@@ -51,7 +51,7 @@ if(WIN32)
                 WORKING_DIRECTORY ${WORKING_DIRECTORY}
                 DEPENDS Http2Server Http2Client
                 USES_TERMINAL
-                COMMAND examples/scripts/run-http2.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+                COMMAND ../examples/scripts/run-http2.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
                 COMMENT "call run http2")
     endif()
 
@@ -60,7 +60,7 @@ if(WIN32)
                 WORKING_DIRECTORY ${WORKING_DIRECTORY}
                 DEPENDS SSLServer SSLClient
                 USES_TERMINAL
-                COMMAND examples/scripts/run-ssl.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+                COMMAND ../examples/scripts/run-ssl.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
                 COMMENT "call run ssl")
     endif()
 
@@ -68,21 +68,21 @@ if(WIN32)
             WORKING_DIRECTORY ${WORKING_DIRECTORY}
             DEPENDS CoroutineDemoAServer CoroutineDemoBServer CoroutineDemoClient testCoro testParallelCoro
             USES_TERMINAL
-            COMMAND examples/scripts/run-co.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND ../examples/scripts/run-co.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
             COMMENT "call run co")
 
     add_custom_target(run-custom
             WORKING_DIRECTORY ${WORKING_DIRECTORY}
             DEPENDS CustomServer CustomClient
             USES_TERMINAL
-            COMMAND examples/scripts/run-custom.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND ../examples/scripts/run-custom.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
             COMMENT "call run custom")
 
     add_custom_target(run-push
             WORKING_DIRECTORY ${WORKING_DIRECTORY}
             DEPENDS PushServer PushClient
             USES_TERMINAL
-            COMMAND examples/scripts/run-push.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND ../examples/scripts/run-push.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
             COMMENT "call run push")
 
     if(TARS_SSL)
@@ -90,23 +90,23 @@ if(WIN32)
                 WORKING_DIRECTORY ${WORKING_DIRECTORY}
                 DEPENDS QuickStartDemo QuickStartDemoClient HttpServer HttpClient AuthServer AuthClient  SSLServer SSLClient CoroutineDemoAServer CoroutineDemoBServer CoroutineDemoClient testCoro testParallelCoro PushServer PushClient
                 USES_TERMINAL
-                COMMAND examples/scripts/run-quick-start.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-                COMMAND examples/scripts/run-http.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-                COMMAND examples/scripts/run-co.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-                COMMAND examples/scripts/run-push.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-                COMMAND examples/scripts/run-auth.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-                COMMAND examples/scripts/run-ssl.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+                COMMAND ../examples/scripts/run-quick-start.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+                COMMAND ../examples/scripts/run-http.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+                COMMAND ../examples/scripts/run-co.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+                COMMAND ../examples/scripts/run-push.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+                COMMAND ../examples/scripts/run-auth.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+                COMMAND ../examples/scripts/run-ssl.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
                 COMMENT "call run all")
     else()
         add_custom_target(run-all
                 WORKING_DIRECTORY ${WORKING_DIRECTORY}
                 USES_TERMINAL
                 DEPENDS QuickStartDemo QuickStartDemoClient HttpServer HttpClient AuthServer AuthClient CoroutineDemoAServer CoroutineDemoBServer CoroutineDemoClient testCoro testParallelCoro PushServer PushClient
-                COMMAND examples/scripts/run-quick-start.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-                COMMAND examples/scripts/run-http.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-                COMMAND examples/scripts/run-co.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-                COMMAND examples/scripts/run-push.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-                COMMAND examples/scripts/run-auth.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+                COMMAND ../examples/scripts/run-quick-start.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+                COMMAND ../examples/scripts/run-http.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+                COMMAND ../examples/scripts/run-co.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+                COMMAND ../examples/scripts/run-push.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+                COMMAND ../examples/scripts/run-auth.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
                 COMMENT "call run all")
     endif()
 
@@ -114,39 +114,39 @@ if(WIN32)
     add_custom_target(run-kill
             WORKING_DIRECTORY ${WORKING_DIRECTORY}
             USES_TERMINAL
-            COMMAND examples/scripts/run-kill.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND ../examples/scripts/run-kill.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
             COMMENT "call run kill")
 else(WIN32)
 
     add_custom_target(run-quick-start
         WORKING_DIRECTORY ${WORKING_DIRECTORY}
         DEPENDS QuickStartDemo QuickStartDemoClient
-        COMMAND sh examples/scripts/run-quick-start.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+        COMMAND sh ../examples/scripts/run-quick-start.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
         COMMENT "call quick start")
 
     add_custom_target(run-http
             WORKING_DIRECTORY ${WORKING_DIRECTORY}
             DEPENDS HttpServer HttpClient
-            COMMAND sh examples/scripts/run-http.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND sh ../examples/scripts/run-http.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
             COMMENT "call run http")
 
     add_custom_target(run-udp
             WORKING_DIRECTORY ${WORKING_DIRECTORY}
             DEPENDS UdpServer UdpClient
-            COMMAND sh examples/scripts/run-udp.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND sh ../examples/scripts/run-udp.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
             COMMENT "call run udp")
 
     add_custom_target(run-auth
             WORKING_DIRECTORY ${WORKING_DIRECTORY}
             DEPENDS AuthServer AuthClient
-            COMMAND sh examples/scripts/run-auth.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND sh ../examples/scripts/run-auth.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
             COMMENT "call run auth")
 
     if(TARS_HTTP2)
     add_custom_target(run-http2
         WORKING_DIRECTORY ${WORKING_DIRECTORY}
         DEPENDS Http2Server Http2Client
-        COMMAND sh examples/scripts/run-http2.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+        COMMAND sh ../examples/scripts/run-http2.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
         COMMENT "call run http2")
     endif()
 
@@ -154,53 +154,53 @@ else(WIN32)
     add_custom_target(run-ssl
         WORKING_DIRECTORY ${WORKING_DIRECTORY}
         DEPENDS SSLServer SSLClient
-        COMMAND sh examples/scripts/run-ssl.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+        COMMAND sh ../examples/scripts/run-ssl.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
         COMMENT "call run ssl")
     endif()
 
     add_custom_target(run-co
         WORKING_DIRECTORY ${WORKING_DIRECTORY}
         DEPENDS CoroutineDemoAServer CoroutineDemoBServer CoroutineDemoClient testCoro testParallelCoro
-        COMMAND sh examples/scripts/run-co.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+        COMMAND sh ../examples/scripts/run-co.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
         COMMENT "call run co")
 
     add_custom_target(run-custom
         WORKING_DIRECTORY ${WORKING_DIRECTORY}
         DEPENDS CustomServer CustomClient
-        COMMAND sh examples/scripts/run-custom.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+        COMMAND sh ../examples/scripts/run-custom.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
         COMMENT "call run custom")
 
     add_custom_target(run-push
         WORKING_DIRECTORY ${WORKING_DIRECTORY}
         DEPENDS PushServer PushClient
-        COMMAND sh examples/scripts/run-push.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+        COMMAND sh ../examples/scripts/run-push.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
         COMMENT "call run push")
 
     if(TARS_SSL)
     add_custom_target(run-all
         WORKING_DIRECTORY ${WORKING_DIRECTORY}
         DEPENDS QuickStartDemo QuickStartDemoClient HttpServer HttpClient AuthServer AuthClient  SSLServer SSLClient CoroutineDemoAServer CoroutineDemoBServer CoroutineDemoClient testCoro testParallelCoro PushServer PushClient
-        COMMAND sh examples/scripts/run-quick-start.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-        COMMAND sh examples/scripts/run-http.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-        COMMAND sh examples/scripts/run-co.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-        COMMAND sh examples/scripts/run-push.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-        COMMAND sh examples/scripts/run-auth.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-        COMMAND sh examples/scripts/run-ssl.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+        COMMAND sh ../examples/scripts/run-quick-start.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+        COMMAND sh ../examples/scripts/run-http.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+        COMMAND sh ../examples/scripts/run-co.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+        COMMAND sh ../examples/scripts/run-push.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+        COMMAND sh ../examples/scripts/run-auth.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+        COMMAND sh ../examples/scripts/run-ssl.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
         COMMENT "call run all")
     else()
     add_custom_target(run-all
             WORKING_DIRECTORY ${WORKING_DIRECTORY}
             DEPENDS QuickStartDemo QuickStartDemoClient HttpServer HttpClient AuthServer AuthClient CoroutineDemoAServer CoroutineDemoBServer CoroutineDemoClient testCoro testParallelCoro PushServer PushClient
-            COMMAND sh examples/scripts/run-quick-start.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-            COMMAND sh examples/scripts/run-http.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-            COMMAND sh examples/scripts/run-co.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-            COMMAND sh examples/scripts/run-push.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
-            COMMAND sh examples/scripts/run-auth.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND sh ../examples/scripts/run-quick-start.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND sh ../examples/scripts/run-http.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND sh ../examples/scripts/run-co.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND sh ../examples/scripts/run-push.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND sh ../examples/scripts/run-auth.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
             COMMENT "call run all")
     endif()
 
     add_custom_target(run-kill
             WORKING_DIRECTORY ${WORKING_DIRECTORY}
-            COMMAND sh examples/scripts/run-kill.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
+            COMMAND sh ../examples/scripts/run-kill.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
             COMMENT "call run kill")
 endif(WIN32)

+ 1 - 1
examples/CoroutineDemo/client/main.cpp

@@ -188,7 +188,7 @@ int main(int argc, char *argv[])
 
 		param.pPrx = _comm->stringToProxy<BServantPrx>(coroObj);
 
-//        TarsRollLogger::getInstance()->logger()->setLogLevel(6);
+//        LocalRollLogger::getInstance()->logger()->setLogLevel(6);
 
 		_comm->setProperty("sendqueuelimit", "1000000");
 		_comm->setProperty("asyncqueuecap", "1000000");

+ 1 - 1
examples/CustomDemo/CustomClient/main.cpp

@@ -198,7 +198,7 @@ int main(int argc, char *argv[])
 
 		param.servantPrx = _comm->stringToProxy<ServantPrx>(sObjName);
 
-//        TarsRollLogger::getInstance()->logger()->setLogLevel(6);
+//        LocalRollLogger::getInstance()->logger()->setLogLevel(6);
 		ProxyProtocol prot;
 		prot.requestFunc = customRequest;
 		prot.responseFunc = customResponse;

+ 30 - 41
examples/HttpDemo/Http2Client/main.cpp

@@ -45,25 +45,26 @@ void syncRpc2(int c)
 {
 	int64_t t = TC_Common::now2us();
 
-    std::map<std::string, std::string> header;
-    header[":authority"] = "domain.com";
-    header[":scheme"] = "http";
-    // header[":method"] = "POST";
-
-    std::map<std::string, std::string> rheader;
     //发起远程调用
     for (int i = 0; i < c; ++i)
     {
-        string rbody;
+	    shared_ptr<TC_HttpResponse> rsp;
+	    shared_ptr<TC_HttpRequest> req = std::make_shared<TC_HttpRequest>();
+	    req->setPostRequest("http://domain.com/hello", string("helloworld-") + TC_Common::tostr(i), true);
+
+	    try
+	    {
+		    param.servant2Prx->http_call("hello", req, rsp);
+	    }
+	    catch (exception & e)
+	    {
+		    cout << "exception:" << e.what() << endl;
+	    }
+
+	    assert(req->getContent() == rsp->getContent());
+	    assert(req.use_count() == 1);
+	    assert(rsp.use_count() == 1);
 
-        try
-        {
-		    param.servant2Prx->http_call("POST", "/", header, "helloworld", rheader, rbody);
-        }
-        catch(exception& e)
-        {
-            cout << "exception:" << e.what() << endl;
-        }
         ++callback_count;
     }
 
@@ -71,30 +72,22 @@ void syncRpc2(int c)
     cout << "syncRpc2 total:" << cost << "us, avg:" << 1.*cost/c << "us" << endl;
 }
 
-
 struct TestHttpCallback : public HttpCallback
 {
-	TestHttpCallback(int64_t t, int i, int c) : start(t), cur(i), count(c)
+	TestHttpCallback(const string &buff) : _buff(buff)
 	{
 
 	}
 
-	virtual int onHttpResponse(const std::map<std::string, std::string>& requestHeaders ,
-	                           const std::map<std::string, std::string>& responseHeaders ,
-	                           const std::vector<char>& rspBody)
+	virtual int onHttpResponse(const shared_ptr<TC_HttpResponse> &rsp)
 	{
 		callback_count++;
 
-		if(cur == count-1)
-		{
-			int64_t cost = TC_Common::now2us() - start;
-			cout << "onHttpResponse count:" << count << ", " << cost << " us, avg:" << 1.*cost/count << "us" << endl;
-		}
+		assert(_buff == rsp->getContent());
 
 		return 0;
 	}
-	virtual int onHttpResponseException(const std::map<std::string, std::string>& requestHeaders,
-	                                    int expCode)
+	virtual int onHttpResponseException(int expCode)
 	{
 		cout << "onHttpResponseException expCode:" << expCode  << endl;
 
@@ -103,27 +96,26 @@ struct TestHttpCallback : public HttpCallback
 		return 0;
 	}
 
-	int64_t start;
-	int     cur;
-	int     count;
+	string _buff;
 };
 
 void asyncRpc2(int c)
 {
 	int64_t t = TC_Common::now2us();
 
-    std::map<std::string, std::string> header;
-    header[":authority"] = "domain.com";
-    header[":scheme"] = "http";
-
 	//发起远程调用
 	for (int i = 0; i < c; ++i)
 	{
-		HttpCallbackPtr p = new TestHttpCallback(t, i, c);
+		shared_ptr<TC_HttpRequest> req = std::make_shared<TC_HttpRequest>();
+
+		string buff = string("helloworld-") + TC_Common::tostr(i);
+		req->setPostRequest("http://domain.com/hello", buff, true);
+
+		HttpCallbackPtr p = new TestHttpCallback(buff);
 
 		try
 		{
-			param.servant2Prx->http_call_async("POST", "/", header, "helloworld", p);
+			param.servant2Prx->http_call_async("hello", req, p);
 		}
 		catch(exception& e)
 		{
@@ -140,6 +132,7 @@ void asyncRpc2(int c)
 	cout << "asyncRpc2 send:" << cost << "us, avg:" << 1.*cost/c << "us" << endl;
 }
 
+
 int main(int argc, char *argv[])
 {
     try
@@ -173,11 +166,7 @@ int main(int argc, char *argv[])
 	    param.servant2Prx->tars_connect_timeout(5000);
         param.servant2Prx->tars_async_timeout(60*1000);
 
-        ProxyProtocol proto;
-
-        proto.requestFunc = ProxyProtocol::http2Request;
-        proto.responseFunc = ProxyProtocol::http2Response;
-        param.servant2Prx->tars_set_protocol(proto);
+        param.servant2Prx->tars_set_protocol(ServantProxy::PROTOCOL_HTTP2);
 
         int64_t start = TC_Common::now2us();
 

+ 2 - 0
examples/HttpDemo/Http2Server/Http2Imp.cpp

@@ -57,6 +57,8 @@ int Http2Imp::doRequest(TarsCurrentPtr current, vector<char> &buffer)
 		{
 			cout << "encodeResponse error:" << session->getErrMsg() << endl;
 		}
+//		cout << context->request.getContent() << endl;
+		
 		buffer.insert(buffer.end(), data.begin(), data.end());
 	}
 

+ 246 - 187
examples/HttpDemo/HttpClient/main.cpp

@@ -1,38 +1,23 @@
-/**
- * Tencent is pleased to support the open source community by making Tars available.
- *
- * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
- *
- * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 
- * in compliance with the License. You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- *
- * Unless required by applicable law or agreed to in writing, software distributed 
- * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
- * specific language governing permissions and limitations under the License.
- */
+
 
 #include <iostream>
 #include "util/tc_http.h"
-#include "util/tc_option.h"
 #include "util/tc_common.h"
 #include "util/tc_clientsocket.h"
 #include "util/tc_thread_pool.h"
-#include "tup/Tars.h"
-#include "tup/tup.h"
+// #include "tup/tup.h"
 #include "util/tc_timeprovider.h"
 #include "servant/Application.h"
+
 using namespace std;
 using namespace tars;
-using namespace tup;
-
+// using namespace wup;
 
 Communicator* _comm;
 
-//static string httpObj = "TestApp.HttpServer.httpObj@tcp -h 127.0.0.1 -p 8081";
-static string httpObj = "TestApp.HttpServer.httpObj@tcp -h 134.175.105.92 -p 8081";
+//static string httpObj = "TestApp.HttpServer.httpObj@tcp -h 127.0.0.1 -p 8081:tcp -h 127.0.0.1 -p 8082:tcp -h 127.0.0.1 -p 8083";
+static string httpObj = "TestApp.HttpServer.httpObj@tcp -h 127.0.0.1 -p 8081";
+//static string httpObj = "TestApp.HttpServer.httpObj@tcp -h 134.175.105.92 -p 8081";
 
 struct Param
 {
@@ -46,198 +31,272 @@ struct Param
 Param param;
 std::atomic<int> callback_count(0);
 
-
 void httpCall(int excut_num)
 {
-    int64_t _iTime = TC_TimeProvider::getInstance()->getNowMs();
+	int64_t _iTime = TC_TimeProvider::getInstance()->getNowMs();
 
-  //  string sServer1("http://134.175.105.92:8081/");
-    string sServer1("http://127.0.0.1:8081/");
+	//  string sServer1("http://134.175.105.92:8081/");
+	string sServer1("http://127.0.0.1:8081/");
 
-    TC_HttpRequest stHttpReq;
-    stHttpReq.setCacheControl("no-cache");
+	TC_HttpRequest stHttpReq;
+	stHttpReq.setCacheControl("no-cache");
 //    stHttpReq.setGetRequest(sServer1);
 
-    TC_TCPClient client ;
- //   client.init("127.0.0.1", 8081, 3000);
-    client.init("127.0.0.1", 8082, 3000);
-
-    int iRet = 0;
-
-    for (int i = 0; i<excut_num; i++)
-    {
-        TC_HttpResponse stHttpRsp;
-
-        stHttpReq.setPostRequest(sServer1, TC_Common::tostr(i), true);
-        iRet = stHttpReq.doRequest(stHttpRsp, 3000);
-    //    iRet = stHttpReq.doRequest(client,stHttpRsp);
-        
-        if (iRet != 0)
-        {
-            cout <<"pthread id: " << TC_Thread::CURRENT_THREADID() << ", iRet:" << iRet <<endl;
-        }
-        
-        ++callback_count;
-    }
-    cout <<  "httpCall, succ:" << param.count << "/" << excut_num << ", " << TC_TimeProvider::getInstance()->getNowMs() - _iTime <<"(ms)"<<endl;
+	TC_TCPClient client ;
+	//   client.init("127.0.0.1", 8081, 3000);
+	client.init("127.0.0.1", 8082, 3000);
+
+	int iRet = 0;
+
+	for (int i = 0; i<excut_num; i++)
+	{
+		TC_HttpResponse stHttpRsp;
+
+		stHttpReq.setPostRequest(sServer1, TC_Common::tostr(i), true);
+		iRet = stHttpReq.doRequest(stHttpRsp, 3000);
+		//    iRet = stHttpReq.doRequest(client,stHttpRsp);
+
+		if (iRet != 0)
+		{
+			cout <<"pthread id: " << TC_Thread::CURRENT_THREADID() << ", iRet:" << iRet <<endl;
+		}
+
+		++callback_count;
+	}
+	cout <<  "httpCall, succ:" << param.count << "/" << excut_num << ", " << TC_TimeProvider::getInstance()->getNowMs() - _iTime <<"(ms)"<<endl;
+}
+
+void syncRpc(int c)
+{
+	int64_t t = TC_Common::now2us();
+
+	//发起远程调用
+	for (int i = 0; i < c; ++i)
+	{
+		string buff = string("helloworld-") + TC_Common::tostr(i);
+		shared_ptr<TC_HttpRequest> req = std::make_shared<TC_HttpRequest>();
+		req->setPostRequest("http://tars.com/hello", buff, true);
+//		req->setHeader("Connection", "keep-alive");
+
+		shared_ptr<TC_HttpResponse> rsp;
+
+		try
+		{
+			param.servantPrx->tars_hash(i)->http_call("hello", req, rsp);
+			assert(req->getContent() == rsp->getContent());
+		}
+		catch(exception& e)
+		{
+			cout << "exception:" << e.what() << endl;
+		}
+
+//		sleep(1);
+//		assert(req.use_count() == 1);
+//		assert(rsp.use_count() == 1);
+		++callback_count;
+	}
+
+	int64_t cost = TC_Common::now2us() - t;
+	cout << "syncCall total:" << cost << "us, avg:" << 1.*cost/c << "us" << endl;
 }
 
 struct TestHttpCallback : public HttpCallback
 {
-    TestHttpCallback(int64_t t, int i, int c) : start(t), cur(i), count(c)
-    {
-
-    }
-
-    virtual int onHttpResponse(const std::map<std::string, std::string>& requestHeaders ,
-                               const std::map<std::string, std::string>& responseHeaders ,
-                               const std::vector<char>& rspBody)
-    {
-	    callback_count++;
-
-        if(cur == count-1)
-        {
-            int64_t cost = TC_Common::now2us() - start;
-            cout << "onHttpResponse count:" << count << ", " << cost << " us, avg:" << 1.*cost/count << "us" << endl;
-        }
-
-        return 0;
-    }
-    virtual int onHttpResponseException(const std::map<std::string, std::string>& requestHeaders,
-                                        int expCode)
-    {
-        cout << "onHttpResponseException expCode:" << expCode  << endl;
-
-	    callback_count++;
-
-        return 0;
-    }
-
-    int64_t start;
-    int     cur;
-    int     count;
+	TestHttpCallback(const string &buff) : _buff(buff)
+	{
+
+	}
+
+	virtual int onHttpResponse(const shared_ptr<TC_HttpResponse> &rsp)
+	{
+		callback_count++;
+
+		assert(_buff == rsp->getContent());
+
+		return 0;
+	}
+	virtual int onHttpResponseException(int expCode)
+	{
+		cout << "onHttpResponseException expCode:" << expCode  << endl;
+
+		callback_count++;
+
+		return 0;
+	}
+
+	string _buff;
 };
 
-void syncRpc(int c)
+void asyncRpc(int c)
 {
 	int64_t t = TC_Common::now2us();
 
-    std::map<std::string, std::string> header;
-
-    std::map<std::string, std::string> rheader;
-    //发起远程调用
-    for (int i = 0; i < c; ++i)
-    {
-        string rbody;
-
-        try
-        {
-	        param.servantPrx->http_call("GET", "/", header, "helloworld", rheader, rbody);
-        }
-        catch(exception& e)
-        {
-            cout << "exception:" << e.what() << endl;
-        }
-        ++callback_count;
-    }
-
-    int64_t cost = TC_Common::now2us() - t;
-    cout << "syncCall total:" << cost << "us, avg:" << 1.*cost/c << "us" << endl;
+	//发起远程调用
+	for (int i = 0; i < c; ++i)
+	{
+		shared_ptr<TC_HttpRequest> req = std::make_shared<TC_HttpRequest>();
+
+		string buff = string("helloworld-") + TC_Common::tostr(i);
+		req->setPostRequest("http://tars.com/hello", buff, true);
+//		req->setHeader("Connection", "keep-alive");
+
+		HttpCallbackPtr p = new TestHttpCallback(buff);
+
+		try
+		{
+			param.servantPrx->http_call_async("hello", req, p);
+		}
+		catch(exception& e)
+		{
+			cout << "exception:" << e.what() << endl;
+		}
+
+		if(i % 500 == 0)
+		{
+			TC_Common::msleep(100);
+		}
+	}
+
+	int64_t cost = TC_Common::now2us() - t;
+	cout << "asyncRpc2 send:" << cost << "us, avg:" << 1.*cost/c << "us" << endl;
+}
+
+
+void asyncRpcCallback(int c)
+{
+	int64_t t = TC_Common::now2us();
+
+	_comm->setServantCustomCallback(param.servantPrx->tars_name(), [](ReqMessagePtr msg) {
+		msg->callback->dispatch(msg);
+	});
+
+	//发起远程调用
+	for (int i = 0; i < c; ++i)
+	{
+		shared_ptr<TC_HttpRequest> req = std::make_shared<TC_HttpRequest>();
+
+		string buff = string("helloworld-") + TC_Common::tostr(i);
+		req->setPostRequest("http://tars.com/hello", buff, true);
+//		req->setHeader("Connection", "keep-alive");
+
+		HttpCallbackPtr p = new TestHttpCallback(buff);
+
+		try
+		{
+			param.servantPrx->http_call_async("hello", req, p);
+		}
+		catch(exception& e)
+		{
+			cout << "exception:" << e.what() << endl;
+		}
+
+		if(i % 500 == 0)
+		{
+			TC_Common::msleep(100);
+		}
+	}
+
+	int64_t cost = TC_Common::now2us() - t;
+	cout << "asyncRpc2 send:" << cost << "us, avg:" << 1.*cost/c << "us" << endl;
 }
 
 int main(int argc, char *argv[])
 {
-    try
-    {
-        if (argc < 4)
-        {
-	        cout << "Usage:" << argv[0] << "--count=1000 --call=[basehttp|synchttp] --thread=1" << endl;
+	try
+	{
+		if (argc < 4)
+		{
+			cout << "Usage:" << argv[0] << "--count=1000 --call=[base|sync|async|callback] --thread=1" << endl;
 
-	        return 0;
-        }
+			return 0;
+		}
 
-	    TC_Option option;
-        option.decode(argc, argv);
+		TC_Option option;
+		option.decode(argc, argv);
 
 		param.count = TC_Common::strto<int>(option.getValue("count"));
-	    if(param.count <= 0) param.count = 1000;
-	    param.call = option.getValue("call");
-	    if(param.call.empty()) param.call = "sync";
-	    param.thread = TC_Common::strto<int>(option.getValue("thread"));
-	    if(param.thread <= 0) param.thread = 1;
-/*
+		if(param.count <= 0) param.count = 1000;
+		param.call = option.getValue("call");
+		if(param.call.empty()) param.call = "sync";
+		param.thread = TC_Common::strto<int>(option.getValue("thread"));
+		if(param.thread <= 0) param.thread = 1;
+
         _comm = new Communicator();
 
-//         TarsRollLogger::getInstance()->logger()->setLogLevel(6);
+ //      LocalRollLogger::getInstance()->logger()->setLogLevel(6);
 
         _comm->setProperty("sendqueuelimit", "1000000");
         _comm->setProperty("asyncqueuecap", "1000000");
 
-	    param.servantPrx = _comm->stringToProxy<ServantPrx>(httpObj);
-
-	    param.servantPrx->tars_connect_timeout(5000);
-        param.servantPrx->tars_async_timeout(60*1000);
-
-        ProxyProtocol proto;
-        proto.requestFunc = ProxyProtocol::http1Request;
-        proto.responseFunc = ProxyProtocol::http1Response;
-        param.servantPrx->tars_set_protocol(proto);
-        */
-        int64_t start = TC_Common::now2us();
-
-        std::function<void(int)> func;
-
-        if (param.call == "basehttp")
-        {
-            func = httpCall;
-        }
-        else if (param.call == "synchttp")
-        {
-            func = syncRpc;
-        }
-        // else if(param.call == "asynchttp")
-        // {
-        // 	func = asyncRpc;
-        // }
-        else
-        {
-        	cout << "no func, exits" << endl;
-        	exit(0);
-        }
-
-	    vector<std::thread*> vt;
-        for(int i = 0 ; i< param.thread; i++)
-        {
-            vt.push_back(new std::thread(func, param.count));
-        }
-
-        std::thread print([&]{while(callback_count != param.count * param.thread) {
-	        cout << "Http:" << param.call << ": ----------finish count:" << callback_count << endl;
-	        std::this_thread::sleep_for(std::chrono::seconds(1));
-        };});
-
-        for(size_t i = 0 ; i< vt.size(); i++)
-        {
-            vt[i]->join();
-            delete vt[i];
-        }
-
-        cout << "(pid:" << std::this_thread::get_id() << ")"
-             << "(count:" << param.count << ")"
-             << "(use ms:" << (TC_Common::now2us() - start)/1000 << ")"
-             << endl;
-
-	    while(callback_count != param.count * param.thread) {
-		    std::this_thread::sleep_for(std::chrono::seconds(1));
-	    }
-	    print.join();
-	    cout << "----------finish count:" << callback_count << endl;
-    }
-    catch(exception &ex)
-    {
-        cout << ex.what() << endl;
-    }
-    cout << "main return." << endl;
-
-    return 0;
+		param.servantPrx = _comm->stringToProxy<ServantPrx>(httpObj);
+
+		int64_t start = TC_Common::now2us();
+
+		std::function<void(int)> func;
+
+		if (param.call == "base")
+		{
+			func = httpCall;
+		}
+		else if (param.call == "sync")
+		{
+			func = syncRpc;
+		}
+		else if(param.call == "async")
+		{
+		    func = asyncRpc;
+		}
+		else if(param.call == "callback")
+		{
+			func = asyncRpcCallback;
+		}
+		else
+		{
+			cout << "no func, exits" << endl;
+			exit(0);
+		}
+
+		param.servantPrx->tars_connect_timeout(5000);
+		param.servantPrx->tars_async_timeout(60*1000);
+
+		param.servantPrx->tars_set_protocol(ServantProxy::PROTOCOL_HTTP1, 3);
+
+		vector<std::thread*> vt;
+		for(int i = 0 ; i< param.thread; i++)
+		{
+			vt.push_back(new std::thread(func, param.count));
+		}
+
+		std::thread print([&]{while(callback_count != param.count * param.thread) {
+			cout << "Http:" << param.call << ": ----------finish count:" << callback_count << endl;
+			std::this_thread::sleep_for(std::chrono::seconds(1));
+		};});
+
+		for(size_t i = 0 ; i< vt.size(); i++)
+		{
+			vt[i]->join();
+			delete vt[i];
+		}
+
+		cout << "(pid:" << std::this_thread::get_id() << ")"
+		     << "(count:" << param.count << ")"
+		     << "(use ms:" << (TC_Common::now2us() - start)/1000 << ")"
+		     << endl;
+
+		while(callback_count != param.count * param.thread) {
+			std::this_thread::sleep_for(std::chrono::seconds(1));
+		}
+		print.join();
+		cout << "----------finish count:" << callback_count << endl;
+
+		delete _comm;
+		_comm = NULL;
+	}
+	catch(exception &ex)
+	{
+		cout << ex.what() << endl;
+	}
+	cout << "main return." << endl;
+
+	return 0;
 }

+ 7 - 7
examples/HttpDemo/HttpServer/HttpImp.cpp

@@ -35,17 +35,17 @@ void HttpImp::destroy()
 
 int HttpImp::doRequest(TarsCurrentPtr current, vector<char> &buffer)
 {
-    TC_HttpRequest request; 
+    TC_HttpRequest request;
+
     vector<char> v = current->getRequestBuffer();
-    string sBuf;
-    sBuf.assign(v.data(),v.size());
 
-    request.decode(sBuf);
-  //  cout << request.getContent() << endl;
+    request.decode(current->getRequestBuffer());
+
     TC_HttpResponse rsp;
-    string s="hello";
+    string s=request.getContent();
     rsp.setResponse(s.c_str(),s.size());
+    rsp.setHeader("Connection", request.getHeader("Connection"));
     rsp.encode(buffer);
-   
+    
     return 0;
 }

+ 1 - 1
examples/QuickStartDemo/HelloServer/Client/main.cpp

@@ -300,7 +300,7 @@ int main(int argc, char *argv[])
 
 	    _comm->setProperty("netthread", TC_Common::tostr(param.netthread));
 
-//        TarsRollLogger::getInstance()->logger()->setLogLevel(6);
+//        LocalRollLogger::getInstance()->logger()->setLogLevel(6);
 
 	    param.pPrx = _comm->stringToProxy<HelloPrx>(helloObj);
 

+ 12 - 12
examples/SSLDemo/Client/config.conf

@@ -23,28 +23,28 @@
         #module name
         modulename                  = TestApp.SSLClient
         #server crt
-        ca                          = ./examples/SSLDemo/certs/server.crt
+        ca                          = ../examples/SSLDemo/certs/server.crt
         #can be empty
-        cert                        = ./examples/SSLDemo/certs/client.crt
+        cert                        = ../examples/SSLDemo/certs/client.crt
         #can be empty
-        key                         = ./examples/SSLDemo/certs/client.key
+        key                         = ../examples/SSLDemo/certs/client.key
 
         <TestApp.SSLServer.SSL1Obj>
             #server crt
-            ca                      = ./examples/SSLDemo/certs/server1.crt
+            ca                      = ../examples/SSLDemo/certs/server1.crt
             #can be empty
-        #    cert                    = ./examples/SSLDemo/certs/client1.crt
+        #    cert                    = ../examples/SSLDemo/certs/client1.crt
             #can be empty
-        #    key                     = ./examples/SSLDemo/certs/client1.key
+        #    key                     = ../examples/SSLDemo/certs/client1.key
         </TestApp.SSLServer.SSL1Obj>
 
         <TestApp.SSLServer.SSL2Obj>
             #server crt
-            ca                      = ./examples/SSLDemo/certs/server1.crt
+            ca                      = ../examples/SSLDemo/certs/server1.crt
             #can be empty
-            cert                    = ./examples/SSLDemo/certs/client1.crt
+            cert                    = ../examples/SSLDemo/certs/client1.crt
             #can be empty
-            key                     = ./examples/SSLDemo/certs/client1.key
+            key                     = ../examples/SSLDemo/certs/client1.key
         </TestApp.SSLServer.SSL2Obj>
 
         <TestApp.SSLServer.SSL3Obj>
@@ -53,11 +53,11 @@
             #auth secret key
             secretkey               = 123456
             #server crt
-            ca                      = ./examples/SSLDemo/certs/server1.crt
+            ca                      = ../examples/SSLDemo/certs/server1.crt
             #can be empty
-            cert                    = ./examples/SSLDemo/certs/client1.crt
+            cert                    = ../examples/SSLDemo/certs/client1.crt
             #can be empty
-            key                     = ./examples/SSLDemo/certs/client1.key
+            key                     = ../examples/SSLDemo/certs/client1.key
         </TestApp.SSLServer.SSL3Obj>
     </client>
   </application>

+ 1 - 1
examples/SSLDemo/Client/main.cpp

@@ -162,7 +162,7 @@ int main(int argc, char *argv[])
         conf.parseFile(option.getValue("config"));
 	    _comm->setProperty(conf);
 
-//        TarsRollLogger::getInstance()->logger()->setLogLevel(6);
+//        LocalRollLogger::getInstance()->logger()->setLogLevel(6);
 
         _comm->setProperty("sendqueuelimit", "1000000");
         _comm->setProperty("asyncqueuecap", "1000000");

+ 12 - 12
examples/SSLDemo/Server/config.conf

@@ -52,9 +52,9 @@
 #       log     = tars.tarslog.LogObj
 
         #client crt, it can be empty when verifyclient is 0
-        ca          = ./examples/SSLDemo/certs/client.crt
-        cert        = ./examples/SSLDemo/certs/server.crt
-        key         = ./examples/SSLDemo/certs/server.key
+        ca          = ../examples/SSLDemo/certs/client.crt
+        cert        = ../examples/SSLDemo/certs/server.crt
+        key         = ../examples/SSLDemo/certs/server.key
         #default is 0
         verifyclient = 1
 
@@ -90,9 +90,9 @@
             queuecap = 1000000
             #tars protocol
 	        protocol = tars
-        #    ca          = ./examples/SSLDemo/certs/client1.crt
-            cert        = ./examples/SSLDemo/certs/server1.crt
-            key         = ./examples/SSLDemo/certs/server1.key
+        #    ca          = ../examples/SSLDemo/certs/client1.crt
+            cert        = ../examples/SSLDemo/certs/server1.crt
+            key         = ../examples/SSLDemo/certs/server1.key
             #default is 0
             verifyclient = 0
         </Hello1Adapter>
@@ -112,9 +112,9 @@
             queuecap = 1000000
             #tars protocol
 	        protocol = tars
-            ca          = ./examples/SSLDemo/certs/client1.crt
-            cert        = ./examples/SSLDemo/certs/server1.crt
-            key         = ./examples/SSLDemo/certs/server1.key
+            ca          = ../examples/SSLDemo/certs/client1.crt
+            cert        = ../examples/SSLDemo/certs/server1.crt
+            key         = ../examples/SSLDemo/certs/server1.key
             #default is 0
             verifyclient = 1
         </Hello2Adapter>
@@ -138,9 +138,9 @@
             accesskey               = tars-test-user
             #auth secret key
             secretkey               = 123456
-            ca          = ./examples/SSLDemo/certs/client1.crt
-            cert        = ./examples/SSLDemo/certs/server1.crt
-            key         = ./examples/SSLDemo/certs/server1.key
+            ca          = ../examples/SSLDemo/certs/client1.crt
+            cert        = ../examples/SSLDemo/certs/server1.crt
+            key         = ../examples/SSLDemo/certs/server1.key
             #default is 0
             verifyclient = 1
         </Hello3Adapter>

+ 1 - 1
examples/scripts/run-auth.bat

@@ -2,7 +2,7 @@
 echo "run-auth.bat"
 
 set EXE_PATH=%1
-set SRC_PATH=%2
+set SRC_PATH=%2\\..
 
 echo %EXE_PATH% %SRC_PATH%
 

+ 1 - 1
examples/scripts/run-auth.sh

@@ -3,7 +3,7 @@
 echo "run-auth.sh"
 
 EXE_PATH=$1
-SRC_PATH=$2
+SRC_PATH=$2/..
 
 echo ${EXE_PATH} ${SRC_PATH}
 

+ 1 - 1
examples/scripts/run-co.bat

@@ -2,7 +2,7 @@
 echo "run-co.bat"
 
 set EXE_PATH=%1
-set SRC_PATH=%2
+set SRC_PATH=%2\\..
 
 echo %EXE_PATH% %SRC_PATH%
 

+ 1 - 1
examples/scripts/run-co.sh

@@ -3,7 +3,7 @@
 echo "run-co.sh"
 
 EXE_PATH=$1
-SRC_PATH=$2
+SRC_PATH=$2/..
 
 echo ${EXE_PATH} ${SRC_PATH}
 

+ 1 - 1
examples/scripts/run-custom.bat

@@ -2,7 +2,7 @@
 echo "run-push.bat"
 
 set EXE_PATH=%1
-set SRC_PATH=%2
+set SRC_PATH=%2\\..
 
 echo %EXE_PATH% %SRC_PATH%
 

+ 1 - 1
examples/scripts/run-custom.sh

@@ -3,7 +3,7 @@
 echo "run-custom.sh"
 
 EXE_PATH=$1
-SRC_PATH=$2
+SRC_PATH=$2/..
 
 echo ${EXE_PATH} ${SRC_PATH}
 

+ 1 - 1
examples/scripts/run-http.bat

@@ -2,7 +2,7 @@
 echo "run-http.bat"
 
 set EXE_PATH=%1
-set SRC_PATH=%2
+set SRC_PATH=%2\\..
 
 echo %EXE_PATH% %SRC_PATH%
 

+ 4 - 2
examples/scripts/run-http.sh

@@ -3,7 +3,7 @@
 echo "run-http.sh"
 
 EXE_PATH=$1
-SRC_PATH=$2
+SRC_PATH=$2/..
 
 echo ${EXE_PATH} ${SRC_PATH}
 
@@ -18,7 +18,9 @@ sleep 1
 
 echo "client: ${EXE_PATH}/HttpClient"
 
-${EXE_PATH}/HttpClient --count=10000 --thread=2 --call=basehttp
+${EXE_PATH}/HttpClient --count=10000 --thread=2 --call=base
+${EXE_PATH}/HttpClient --count=10000 --thread=2 --call=sync
+${EXE_PATH}/HttpClient --count=10000 --thread=2 --call=async
 #${EXE_PATH}/HttpClient --count=10000 --thread=2 --call=synchttp
 
 sleep 1

+ 1 - 1
examples/scripts/run-http2.bat

@@ -2,7 +2,7 @@
 echo "run-http2.bat"
 
 set EXE_PATH=%1
-set SRC_PATH=%2
+set SRC_PATH=%2\\..
 
 echo %EXE_PATH% %SRC_PATH%
 

+ 1 - 1
examples/scripts/run-http2.sh

@@ -2,7 +2,7 @@
 
 echo "run-http2.sh"
 EXE_PATH=$1
-SRC_PATH=$2
+SRC_PATH=$2/..
 
 echo ${EXE_PATH} ${SRC_PATH}
 

+ 1 - 1
examples/scripts/run-push.bat

@@ -2,7 +2,7 @@
 echo "run-push.bat"
 
 set EXE_PATH=%1
-set SRC_PATH=%2
+set SRC_PATH=%2\\..
 
 echo %EXE_PATH% %SRC_PATH%
 

+ 1 - 1
examples/scripts/run-push.sh

@@ -2,7 +2,7 @@
 
 echo "run-co.sh"
 EXE_PATH=$1
-SRC_PATH=$2
+SRC_PATH=$2/..
 
 echo ${EXE_PATH} ${SRC_PATH}
 

+ 1 - 1
examples/scripts/run-quick-start.bat

@@ -2,7 +2,7 @@
 echo "run-quick-start.bat"
 
 set EXE_PATH=%1
-set SRC_PATH=%2
+set SRC_PATH=%2\\..
 
 echo %EXE_PATH% %SRC_PATH%
 

+ 1 - 1
examples/scripts/run-quick-start.sh

@@ -2,7 +2,7 @@
 
 echo "run-quick-start.sh"
 EXE_PATH=$1
-SRC_PATH=$2
+SRC_PATH=$2/..
 
 echo ${EXE_PATH} ${SRC_PATH}
 

+ 1 - 1
examples/scripts/run-ssl.bat

@@ -2,7 +2,7 @@
 echo "run-ssl.bat"
 
 set EXE_PATH=%1
-set SRC_PATH=%2
+set SRC_PATH=%2\\..
 
 echo %EXE_PATH% %SRC_PATH%
 

+ 1 - 1
examples/scripts/run-ssl.sh

@@ -2,7 +2,7 @@
 
 echo "run-ssl.sh"
 EXE_PATH=$1
-SRC_PATH=$2
+SRC_PATH=$2/..
 
 echo ${EXE_PATH} ${SRC_PATH}
 

+ 1 - 1
examples/scripts/run-udp.bat

@@ -2,7 +2,7 @@
 echo "run-auth.bat"
 
 set EXE_PATH=%1
-set SRC_PATH=%2
+set SRC_PATH=%2\\..
 
 echo %EXE_PATH% %SRC_PATH%
 

+ 1 - 1
examples/scripts/run-udp.sh

@@ -3,7 +3,7 @@
 echo "run-auth.sh"
 
 EXE_PATH=$1
-SRC_PATH=$2
+SRC_PATH=$2/..
 
 echo ${EXE_PATH} ${SRC_PATH}
 

+ 1 - 1
servant/CMakeLists.txt

@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.2)
 
 project(servant)
 
-if(_USE_OPENTRACKING)
+if(TARS_OPENTRACKING)
 include_directories(${util_SOURCE_DIR}/include ${OPENTRACKING_INC})
 else()
 include_directories(${util_SOURCE_DIR}/include)

+ 372 - 100
servant/libservant/AdapterProxy.cpp

@@ -20,13 +20,13 @@
 #include "servant/Application.h"
 #include "servant/AdminF.h"
 #include "servant/AppCache.h"
-#include "servant/TarsLogger.h"
+#include "servant/RemoteLogger.h"
 #include "tup/tup.h"
 #include "servant/StatF.h"
 #include "servant/StatReport.h"
 #include "util/tc_http2.h"
 // #include "util/tc_http2clientmgr.h"
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
 #include "servant/text_map_carrier.h"
 #endif
 
@@ -50,11 +50,11 @@ AdapterProxy::AdapterProxy(ObjectProxy * pObjectProxy,const EndpointInfo &ep,Com
 , _connTimeout(false)
 , _connExc(false)
 , _connExcCnt(0)
-, _staticWeight(0)
+//, _staticWeight(0)
 , _timeoutLogFlag(false)
 , _noSendQueueLimit(1000)
-, _maxSampleCount(1000)
-, _sampleRate(0)
+//, _maxSampleCount(1000)
+//, _sampleRate(0)
 , _id((++_idGen))
 {
     _timeoutQueue.reset(new TC_TimeoutQueueNew<ReqMessage*>());
@@ -64,10 +64,10 @@ AdapterProxy::AdapterProxy(ObjectProxy * pObjectProxy,const EndpointInfo &ep,Com
         _noSendQueueLimit = pObjectProxy->getCommunicatorEpoll()->getNoSendQueueLimit();
     }
 
-    if(_communicator)
-    {
-        _timeoutLogFlag = _communicator->getTimeoutLogFlag();
-    }
+    // if(_communicator)
+    // {
+    //     _timeoutLogFlag = pObjectProxy->getCommunicatorEpoll()->getTimeoutLogFlag();
+    // }
 
     if (ep.isTcp())
     {
@@ -92,7 +92,6 @@ AdapterProxy::~AdapterProxy()
 //	adapterProxy->checkActive(true);
 //	return adapterProxy;
 //}
-
 string AdapterProxy::getSlaveName(const string& sSlaveName)
 {
     string::size_type pos = sSlaveName.find(".");
@@ -110,66 +109,113 @@ string AdapterProxy::getSlaveName(const string& sSlaveName)
 
 void AdapterProxy::initStatHead()
 {
-    vector <string> v;
-    if(!ClientConfig::SetDivision.empty() &&
-        StatReport::divison2SetInfo(ClientConfig::SetDivision, v)) //主调(client)启用set
-    {
-        _statHead.masterName = StatReport::trimAndLimitStr(ClientConfig::ModuleName + "." + v[0] + v[1] + v[2] + "@" + ClientConfig::TarsVersion, StatReport::MAX_MASTER_NAME_LEN);
-    }
-    else
-    {
-        _statHead.masterName = StatReport::trimAndLimitStr(ClientConfig::ModuleName + "@" + ClientConfig::TarsVersion, StatReport::MAX_MASTER_NAME_LEN);
-    }
-    
-    const string sSlaveName = getSlaveName(_objectProxy->name());
-    string sSlaveSet = _endpoint.setDivision();
-    if(!sSlaveSet.empty() &&
-        StatReport::divison2SetInfo(sSlaveSet, v)) //被调启用set
-    {
-        _statHead.slaveSetName  = v[0];
-        _statHead.slaveSetArea  = v[1];
-        _statHead.slaveSetID    = v[2];
-        _statHead.slaveName     = StatReport::trimAndLimitStr(sSlaveName + "." + v[0] + v[1] + v[2], StatReport::MAX_MASTER_NAME_LEN);
-    }
-    else
-    {
-        _statHead.slaveName = StatReport::trimAndLimitStr(sSlaveName, StatReport::MAX_MASTER_NAME_LEN);
-    }
+	vector <string> v;
+	if(!ClientConfig::SetDivision.empty() &&
+		StatReport::divison2SetInfo(ClientConfig::SetDivision, v)) //主调(client)启用set
+	{
+		_statHead.masterName = StatReport::trimAndLimitStr(ClientConfig::ModuleName + "." + v[0] + v[1] + v[2] + "@" + ClientConfig::TarsVersion, StatReport::MAX_MASTER_NAME_LEN);
+	}
+	else
+	{
+		_statHead.masterName = StatReport::trimAndLimitStr(ClientConfig::ModuleName + "@" + ClientConfig::TarsVersion, StatReport::MAX_MASTER_NAME_LEN);
+	}
+
+	const string sSlaveName = getSlaveName(_objectProxy->name());
+	string sSlaveSet = _endpoint.setDivision();
+	if(!sSlaveSet.empty() &&
+		StatReport::divison2SetInfo(sSlaveSet, v)) //被调启用set
+	{
+		_statHead.slaveSetName  = v[0];
+		_statHead.slaveSetArea  = v[1];
+		_statHead.slaveSetID    = v[2];
+		_statHead.slaveName     = StatReport::trimAndLimitStr(sSlaveName + "." + v[0] + v[1] + v[2], StatReport::MAX_MASTER_NAME_LEN);
+	}
+	else
+	{
+		_statHead.slaveName = StatReport::trimAndLimitStr(sSlaveName, StatReport::MAX_MASTER_NAME_LEN);
+	}
+
+	_statHead.slaveIp      = StatReport::trimAndLimitStr(_endpoint.host(), StatReport::MAX_MASTER_IP_LEN);
+	_statHead.slavePort    = _endpoint.port();
+	_statHead.returnValue  = 0;
+}
 
-    _statHead.slaveIp      = StatReport::trimAndLimitStr(_endpoint.host(), StatReport::MAX_MASTER_IP_LEN);
-    _statHead.slavePort    = _endpoint.port();
-    _statHead.returnValue  = 0;
+//bool AdapterProxy::invoke_sync(ReqMessage * msg)
+//{
+//	if(!_trans->hasConnected()) {
+//		TLOGTARS("[TARS][AdapterProxy::invoke_sync " << _objectProxy->name() << ", " << _endpoint.desc() << "]" << endl);
+//		return false;
+//	}
+//
+//	//生成requestid
+//	//taf调用 而且 不是单向调用
+//	if (!msg->bFromRpc)
+//	{
+//		// msg->request.iRequestId = _objectProxy->generateId();
+//		msg->request.iRequestId = _timeoutQueue->generateId();
+//	}
+//
+//	msg->sReqData->setBuffer(_objectProxy->getProxyProtocol().requestFunc(msg->request, _trans));
+//
+//	msg->response = std::make_shared<ResponsePacket>();
+//
+//	//这里得加锁
+//	std::lock_guard<std::mutex> lock(_mutex);
+//
+//	_trans->sendRecv(msg);
+//
+//	return true;
+//}
+
+void AdapterProxy::onConnect()
+{
+	_objectProxy->onConnect(this);
 }
 
-int AdapterProxy::invoke(ReqMessage * msg)
+int AdapterProxy::invoke_connection_serial(ReqMessage * msg)
 {
-    assert(_trans != NULL);
+	assert(msg->eType != ReqMessage::ONE_WAY);
 
-    TLOGTARS("[TARS][AdapterProxy::invoke objname:" << _objectProxy->name() << ",desc:" << _endpoint.desc() << endl);
+	msg->sReqData->setBuffer(_objectProxy->getProxyProtocol().requestFunc(msg->request, _trans.get()));
 
-    //未发链表有长度限制
-    if(_timeoutQueue->getSendListSize() >= _noSendQueueLimit)
-    {
-        TLOGERROR("[TARS][AdapterProxy::invoke fail,ReqInfoQueue.size > " << _noSendQueueLimit << ",objname:" << _objectProxy->name() <<",desc:"<< _endpoint.desc() << endl);
-        msg->eStatus = ReqMessage::REQ_EXC;
+	msg->request.iRequestId = _timeoutQueue->generateId();
 
-        finishInvoke(msg);
+	if(!_requestMsg && _timeoutQueue->sendListEmpty() && _trans->sendRequest(msg->sReqData) != Transceiver::eRetError)
+	{
+		TLOGTARS("[TARS][AdapterProxy::invoke push (send) obj: " << _objectProxy->name() << ", desc:" << _endpoint.desc() << ", id: " << msg->request.iRequestId << endl);
 
-        return 0;
-    }
+		_requestMsg = msg;
 
-    //生成requestid
-    //tars调用 而且 不是单向调用
-    if(!msg->bFromRpc)
-    {
-        msg->request.iRequestId = _timeoutQueue->generateId();
-    }
+		bool bFlag = _timeoutQueue->push(msg, msg->request.iRequestId, msg->request.iTimeout + msg->iBeginTime);
+		if (!bFlag)
+		{
+			TLOGERROR("[TARS][AdapterProxy::invoke fail1 : insert timeout queue fail,queue size:" << _timeoutQueue->size() << ",id: " << msg->request.iRequestId << "," << _objectProxy->name() << ", " << _endpoint.desc() << "]" << endl);
+			msg->eStatus = ReqMessage::REQ_EXC;
 
-#ifdef _USE_OPENTRACKING
-    startTrack(msg);
-#endif
+			finishInvoke(msg);
+		}
+	}
+	else
+	{
+		TLOGTARS("[TARS][AdapterProxy::invoke push (no send) " << _objectProxy->name() << ", " << _endpoint.desc() << ",id " << msg->request.iRequestId << endl);
+
+		//之前还没有数据没发送 或者 请求发送失败了, 进队列
+		bool bFlag = _timeoutQueue->push(msg, msg->request.iRequestId, msg->request.iTimeout + msg->iBeginTime, false);
+		if (!bFlag)
+		{
+			TLOGERROR("[TARS][AdapterProxy::invoke fail2 : insert timeout queue fail,queue size:" << _timeoutQueue->size() << ", id: " << msg->request.iRequestId << ", " << _objectProxy->name() << ", " << _endpoint.desc() << "]" << endl);
+			msg->eStatus = ReqMessage::REQ_EXC;
 
-    msg->sReqData->setBuffer(_objectProxy->getProxyProtocol().requestFunc(msg->request, _trans.get()));
+			finishInvoke(msg);
+		}
+	}
+
+	return 0;
+}
+
+int AdapterProxy::invoke_connection_parallel(ReqMessage * msg)
+{
+	msg->sReqData->setBuffer(_objectProxy->getProxyProtocol().requestFunc(msg->request, _trans.get()));
 
 //	TLOGERROR("[TARS][AdapterProxy::invoke insert timeout queue fail, queue size:" << _timeoutQueue->size() << ", id:" << msg->request.iRequestId << ", obj:" <<_objectProxy->name() << ", desc:" << _endpoint.desc() <<endl);
 
@@ -181,7 +227,7 @@ int AdapterProxy::invoke(ReqMessage * msg)
         //请求发送成功了,单向调用直接返回
         if(msg->eType == ReqMessage::ONE_WAY)
         {
-        #ifdef _USE_OPENTRACKING
+        #ifdef TARS_OPENTRACKING
             finishTrack(msg);
         #endif
 
@@ -218,24 +264,121 @@ int AdapterProxy::invoke(ReqMessage * msg)
         }
     }
 
-#ifdef _USE_OPENTRACKING
-    if(msg->eType == ReqMessage::ONE_WAY)
+	return 0;
+}
+
+int AdapterProxy::invoke(ReqMessage * msg)
+{
+    assert(_trans != NULL);
+
+    TLOGTARS("[TARS][AdapterProxy::invoke " << _objectProxy->name() << ", " << _endpoint.desc() << "]" << endl);
+
+    //未发链表有长度限制
+    if (_timeoutQueue->getSendListSize() >= _noSendQueueLimit)
     {
-        finishTrack(msg);
+        TLOGERROR("[TARS][AdapterProxy::invoke fail,ReqInfoQueue.size>" << _noSendQueueLimit << "," << _objectProxy->name() << "," << _endpoint.desc() << "]" << endl);
+        msg->eStatus = ReqMessage::REQ_EXC;
+
+        finishInvoke(msg);
+        return 0;
     }
-#endif
-    return 0;
+
+    //生成requestid
+    //taf调用 而且 不是单向调用
+    if (!msg->bFromRpc)
+    {
+        msg->request.iRequestId = _timeoutQueue->generateId();
+    }
+
+    if(_objectProxy->getServantProxy()->tars_connection_serial() > 0)
+    {
+	    invoke_connection_serial(msg);
+    }
+	else
+	{
+	    invoke_connection_parallel(msg);
+    }
+//
+//    msg->sReqData->setBuffer(_objectProxy->getProxyProtocol().requestFunc(msg->request, _trans.get()));
+//
+//	//当前队列是空的, 且是连接复用模式, 交给连接发送数据
+//    //连接连上 buffer不为空  发送数据成功
+//    if (_timeoutQueue->sendListEmpty() && _trans->sendRequest(msg->sReqData) != Transceiver::eRetError)
+//    {
+//        TLOGTARS("[TARS][AdapterProxy::invoke push (send) obj: " << _objectProxy->name() << ", desc:" << _endpoint.desc() << ", id: " << msg->request.iRequestId << endl);
+//
+//        //请求发送成功了 处理采样
+//        //这个请求发送成功了。单向调用直接返回
+//        if (msg->eType == ReqMessage::ONE_WAY)
+//        {
+//            delete msg;
+//            msg = NULL;
+//
+//            return 0;
+//        }
+//
+//        bool bFlag = _timeoutQueue->push(msg, msg->request.iRequestId, msg->request.iTimeout + msg->iBeginTime);
+//        if (!bFlag)
+//        {
+//            TLOGERROR("[TARS][AdapterProxy::invoke fail1 : insert timeout queue fail,queue size:" << _timeoutQueue->size() << ",id: " << msg->request.iRequestId << "," << _objectProxy->name() << ", " << _endpoint.desc() << "]" << endl);
+//            msg->eStatus = ReqMessage::REQ_EXC;
+//
+//            finishInvoke(msg);
+//        }
+//    }
+//    else
+//    {
+//        TLOGTARS("[TARS][AdapterProxy::invoke push (no send) " << _objectProxy->name() << ", " << _endpoint.desc() << ",id " << msg->request.iRequestId << endl);
+//
+//        //之前还没有数据没发送 或者 请求发送失败了, 进队列
+//        bool bFlag = _timeoutQueue->push(msg, msg->request.iRequestId, msg->request.iTimeout + msg->iBeginTime, false);
+//        if (!bFlag)
+//        {
+//            TLOGERROR("[TARS][AdapterProxy::invoke fail2 : insert timeout queue fail,queue size:" << _timeoutQueue->size() << ", id: " << msg->request.iRequestId << ", " << _objectProxy->name() << ", " << _endpoint.desc() << "]" << endl);
+//            msg->eStatus = ReqMessage::REQ_EXC;
+//
+//            finishInvoke(msg);
+//        }
+//    }
+
+	return 0;
 }
 
-void AdapterProxy::doInvoke()
+void AdapterProxy::doInvoke_serial()
 {
-    while(!_timeoutQueue->sendListEmpty())
-    {
-        ReqMessage * msg = NULL;
+	assert(_requestMsg == NULL);
+
+	if(!_timeoutQueue->sendListEmpty())
+	{
+		ReqMessage * msg = NULL;
+
+		_timeoutQueue->getSend(msg);
+
+		int iRet = _trans->sendRequest(msg->sReqData);
+
+		//发送失败 返回
+		if (iRet == Transceiver::eRetError)
+		{
+			TLOGTARS("[TARS][AdapterProxy::doInvoke sendRequest failed, obj:" << _objectProxy->name() << ",desc:" << _endpoint.desc() << ",id:" << msg->request.iRequestId << ", ret:" << iRet << endl);
+			return;
+		}
 
-        _timeoutQueue->getSend(msg);
+		//送send 队列中清掉, 但是保留在定时队列中
+		_timeoutQueue->popSend(false);
 
-        int iRet = _trans->sendRequest(msg->sReqData);
+		_requestMsg = msg;
+	}
+}
+
+void AdapterProxy::doInvoke_parallel()
+{
+	while(!_timeoutQueue->sendListEmpty())
+	{
+		ReqMessage * msg = NULL;
+
+		_timeoutQueue->getSend(msg);
+
+		int iRet = _trans->sendRequest(msg->sReqData);
 
         //发送失败 返回
         if(iRet == Transceiver::eRetError)
@@ -243,7 +386,6 @@ void AdapterProxy::doInvoke()
             TLOGTARS("[TARS][AdapterProxy::doInvoke sendRequest failed, obj:" << _objectProxy->name() << ",desc:" << _endpoint.desc() << ",id:" << msg->request.iRequestId << ", ret:" << iRet << endl);
             return;
         }
-	    TLOGTARS("[TARS][AdapterProxy::doInvoke sendRequest obj:" << _objectProxy->name() << ",desc:" << _endpoint.desc() << ",id:" << msg->request.iRequestId << ",ret:" << iRet << endl);
 
         //请求发送成功了 处理采样
         //...
@@ -264,6 +406,20 @@ void AdapterProxy::doInvoke()
     }
 }
 
+void AdapterProxy::doInvoke(bool initInvoke)
+{
+	if(_objectProxy->getServantProxy()->tars_connection_serial() > 0)
+	{
+		if(initInvoke)
+		{
+			doInvoke_serial();
+		}
+	}
+	else
+	{
+		doInvoke_parallel();
+	}
+}
 
 void AdapterProxy::finishInvoke(bool bFail)
 {
@@ -375,7 +531,13 @@ int AdapterProxy::getConTimeout()
 
 bool AdapterProxy::checkActive(bool bForceConnect, bool onlyCheck)
 {
-    time_t now = TNOW;
+	if(onlyCheck)
+	{
+		return _trans->hasConnected();
+	}
+	else
+	{
+		time_t now = TNOW;
 
     TLOGTARS("[TARS][AdapterProxy::checkActive objname:" << _objectProxy->name() 
         << ",desc:" << _endpoint.desc() 
@@ -452,10 +614,11 @@ bool AdapterProxy::checkActive(bool bForceConnect, bool onlyCheck)
         }
     }
 
-    return _trans->hasConnected();
+		//已经建立连接了才返回
+		return _trans->hasConnected();
+	}
 }
 
-
 void AdapterProxy::setConTimeout(bool bConTimeout)
 {
     if(bConTimeout != _connTimeout)
@@ -469,24 +632,70 @@ void AdapterProxy::setConTimeout(bool bConTimeout)
     }
 }
 
+void AdapterProxy::onSetInactive()
+{
+	_activeStatus = false;
+
+	_nextRetryTime = TNOW + _objectProxy->checkTimeoutInfo().tryTimeInterval;
+
+	//需要关闭连接
+	_trans->close();
+}
+
 //屏蔽结点
 void AdapterProxy::setInactive()
 {
-    _activeStatus  = false;
+	onSetInactive();
+
+	_objectProxy->getServantProxy()->onSetInactive(_endpoint);
+
+    TLOGTARS("[TARS][AdapterProxy::setInactive, " << _objectProxy->name() << ", " << _endpoint.desc() << ", inactive]" << endl);
+}
+
+void AdapterProxy::finishInvoke_serial(shared_ptr<ResponsePacket> & rsp)
+{
+	TLOGTARS("[TARS][AdapterProxy::finishInvoke(ResponsePacket), " << _objectProxy->name() << ", " << _endpoint.desc() << ", id:" << rsp->iRequestId << "]" << endl);
+
+	if (!_requestMsg)
+	{
+		if(_timeoutLogFlag)
+		{
+			TLOGERROR("[TARS][AdapterProxy::finishInvoke(ResponsePacket),"
+				          << _objectProxy->name()
+				          << ",get req-ptr NULL,may be timeout,id:"
+				          << rsp->iRequestId << ",desc:" << _endpoint.desc() << "]" << endl);
+		}
+		return;
+	}
 
-    _nextRetryTime = TNOW + _objectProxy->checkTimeoutInfo().tryTimeInterval;
+	ReqMessage * msg = _requestMsg;
 
-    _trans->close();
+	//这里的队列中的发送链表中的数据可能已经在timeout的时候删除了,因此可能会core,在erase中要加判断
+	//获取请求信息
+	bool retErase = _timeoutQueue->erase(_requestMsg->request.iRequestId, msg);
 
-    TLOGTARS("[TARS][AdapterProxy::setInactive objname:" << _objectProxy->name() << ",desc:" << _endpoint.desc() << ",inactive" << endl);
+	assert(retErase);
+	assert(_requestMsg == msg);
+	assert(msg->eType != ReqMessage::ONE_WAY);
+	assert(msg->eStatus == ReqMessage::REQ_REQ);
+
+	_requestMsg = NULL;
+
+	msg->eStatus = ReqMessage::REQ_RSP;
+
+	msg->response = rsp;
+
+	finishInvoke(msg);
+
+	//检查连接状态
+	checkActive();
 }
 
-void AdapterProxy::finishInvoke(shared_ptr<ResponsePacket> & rsp)
+void AdapterProxy::finishInvoke_parallel(shared_ptr<ResponsePacket> & rsp)
 {
-//    TLOGTARS("[TARS][AdapterProxy::finishInvoke(ResponsePacket) obj:" << _objectProxy->name() << ", desc:" << _endpoint.desc()
-//        << ", id:" << rsp->iRequestId << endl);
+	TLOGTARS("[TARS][AdapterProxy::finishInvoke(ResponsePacket), " << _objectProxy->name() << ", " << _endpoint.desc() << ", id:" << rsp->iRequestId << "]" << endl);
 
-    ReqMessage * msg = NULL;
+	ReqMessage * msg = NULL;
 
     //requestid 为0 是push消息
     if(rsp->iRequestId == 0)
@@ -534,6 +743,70 @@ void AdapterProxy::finishInvoke(shared_ptr<ResponsePacket> & rsp)
     finishInvoke(msg);
 }
 
+void AdapterProxy::finishInvoke(shared_ptr<ResponsePacket> & rsp)
+{
+	TLOGTARS("[TARS][AdapterProxy::finishInvoke(ResponsePacket), " << _objectProxy->name() << ", " << _endpoint.desc() << ", id:" << rsp->iRequestId << "]" << endl);
+
+	if(_objectProxy->getServantProxy()->tars_connection_serial() > 0)
+	{
+		finishInvoke_serial(rsp);
+	}
+	else
+	{
+		finishInvoke_parallel(rsp);
+	}
+//
+//	ReqMessage * msg = NULL;
+//
+//    if (rsp->iRequestId == 0)
+//    {
+//        //requestid 为0 是push消息
+//        //
+//        //push callback is null
+//        if (!_objectProxy->getPushCallback())
+//        {
+//            TLOGERROR("[TARS][AdapterProxy::finishInvoke(ResponsePacket), request id is 0, pushcallback is null, " << _objectProxy->name() << ", " << _endpoint.desc() << "]" << endl);
+//            return;
+//        }
+//        msg = new ReqMessage();
+//        msg->eStatus = ReqMessage::REQ_RSP;
+//        msg->eType = ReqMessage::ASYNC_CALL;
+//        msg->bFromRpc = true;
+//        msg->bPush = true;
+//        msg->proxy = _objectProxy->getServantProxy();
+//        msg->pObjectProxy = _objectProxy;
+//        msg->adapter = this;
+//        msg->callback = _objectProxy->getPushCallback();
+//    }
+//    else
+//    {
+//        //这里的队列中的发送链表中的数据可能已经在timeout的时候删除了,因此可能会core,在erase中要加判断
+//        //获取请求信息
+//        bool retErase = _timeoutQueue->erase(rsp->iRequestId, msg);
+//
+//        //找不到此id信息
+//        if (!retErase)
+//        {
+//            if (_timeoutLogFlag)
+//            {
+//                TLOGERROR("[TARS][AdapterProxy::finishInvoke(ResponsePacket),"
+//                          << _objectProxy->name()
+//                          << ",get req-ptr NULL,may be timeout,id:"
+//                          << rsp->iRequestId << ",desc:" << _endpoint.desc() << "]" << endl);
+//            }
+//            return ;
+//        }
+//
+//        assert(msg->eStatus == ReqMessage::REQ_REQ);
+//
+//        msg->eStatus = ReqMessage::REQ_RSP;
+//    }
+//
+//    msg->response = rsp;
+//
+//    finishInvoke(msg);
+}
+
 void AdapterProxy::finishInvoke(ReqMessage * msg)
 {
     assert(msg->eStatus != ReqMessage::REQ_REQ);
@@ -543,7 +816,7 @@ void AdapterProxy::finishInvoke(ReqMessage * msg)
     << ", status:" << msg->eStatus
     << ", ret: " << msg->response->iRet << endl);
 
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
 	finishTrack(msg);
 #endif
 
@@ -595,16 +868,14 @@ void AdapterProxy::finishInvoke(ReqMessage * msg)
                 ReqMessagePtr msgPtr = msg;
                 try
                 {
-                    msg->callback->onDispatch(msgPtr);
+                    msg->callback->dispatch(msgPtr);
                 }
                 catch (exception & e)
                 {
-                    //FDLOG("taferror")<<"[TAF]AdapterProxy::finishInvoke(ReqMessage) exp:"<<e.what()<<" ,line:"<<__LINE__<<endl;
-                    TLOGERROR("[TAF]AdapterProxy::finishInvoke(ReqMessage) exp:" << e.what() << " ,line:" << __LINE__ << endl);
+                    TLOGERROR("[TARS]AdapterProxy::finishInvoke(ReqMessage) exp:" << e.what() << " ,line:" << __LINE__ << endl);
                 }
                 catch (...)
                 {
-                    //FDLOG("taferror")<<"[TAF]AdapterProxy::finishInvoke(ReqMessage) exp:unknown line:"<<__LINE__<<endl;
                     TLOGERROR("[TARS]AdapterProxy::finishInvoke(ReqMessage) exp:unknown line:|" << __LINE__ << endl);
                 }
             }
@@ -641,11 +912,6 @@ void AdapterProxy::finishInvoke(ReqMessage * msg)
     return;
 }
 
-//ObjectProxy * AdapterProxy::getObjProxy()
-//{
-//    return _objectProxy;
-//}
-
 void AdapterProxy::doTimeout()
 {
     ReqMessage * msg;
@@ -653,7 +919,14 @@ void AdapterProxy::doTimeout()
     {
         TLOGTARS("[TARS][AdapterProxy::doTimeout obj:" << _objectProxy->name() << ",desc:" << _endpoint.desc() << ",id " << msg->request.iRequestId << endl);
 
-        assert(msg->eStatus == ReqMessage::REQ_REQ);
+//        assert(msg->eStatus == ReqMessage::REQ_REQ);
+
+		if(msg == _requestMsg)
+		{
+			_requestMsg = NULL;
+			//timeout, close
+			_trans->close();
+		}
 
         msg->eStatus = ReqMessage::REQ_TIME;
 
@@ -677,7 +950,7 @@ void AdapterProxy::doTimeout()
 }
 
 
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
 void AdapterProxy::startTrack(ReqMessage * msg)
 {
     if(!_communicator->_traceManager)
@@ -784,7 +1057,7 @@ void AdapterProxy::stat(ReqMessage * msg)
         _statBody[msg->request.sFuncName] = body;
     }
 
-    if(LOG->isNeedLog(TarsRollLogger::INFO_LOG))
+    if(LOG->isNeedLog(LocalRollLogger::INFO_LOG))
     {
         ostringstream os;
         os.str("");
@@ -849,10 +1122,9 @@ void AdapterProxy::addConnExc(bool bExc)
     {
         if(!_connExc && _connExcCnt++ >= _objectProxy->checkTimeoutInfo().maxConnectExc)
         {
-            if(!_connExc)
-            {
-                TLOGERROR("[TARS][AdapterProxy::addConnExc desc:"<< _endpoint.desc() << ",connect exception status is true! (connect error)"<<endl);
-            }
+
+        	TLOGERROR("[TARS][AdapterProxy::addConnExc desc:"<< _endpoint.desc() << ",connect exception status is true! (connect error)"<<endl);
+            
             setInactive();
             _connExc = true;
         }

+ 1 - 1
servant/libservant/AdminServant.cpp

@@ -58,7 +58,7 @@ void AdminServant::shutdown(TarsCurrentPtr current)
 
 string AdminServant::notify(const string &command, TarsCurrentPtr current)
 {
-    TarsRemoteNotify::getInstance()->report("AdminServant::notify:" + command);
+    RemoteNotify::getInstance()->report("AdminServant::notify:" + command);
 
     return NotifyObserver::getInstance()->notify(command, current);
 }

+ 116 - 35
servant/libservant/AppProtocol.cpp

@@ -19,7 +19,7 @@
 #include "servant/AppProtocol.h"
 #include "servant/Transceiver.h"
 #include "servant/AdapterProxy.h"
-#include "servant/TarsLogger.h"
+#include "servant/RemoteLogger.h"
 #include "tup/Tars.h"
 #include <iostream>
 
@@ -60,64 +60,136 @@ vector<char> ProxyProtocol::tarsRequest(RequestPacket& request, Transceiver *)
 
 vector<char> ProxyProtocol::http1Request(tars::RequestPacket& request, Transceiver *trans)
 {
-	request.iRequestId = trans->getAdapterProxy()->getId();
+//	assert(trans->getAdapterProxy()->getObjProxy()->getServantProxy()->taf_connection_serial() > 0);
 
-    TC_HttpRequest httpRequest;
+//	request.iRequestId = trans->getAdapterProxy()->getId();
 
-    httpRequest.setRequest(request.sFuncName, request.sServantName, string(request.sBuffer.data(), request.sBuffer.size()), true);
+	shared_ptr<TC_HttpRequest> &data = *(shared_ptr<TC_HttpRequest>*)request.sBuffer.data();
 
-    vector<char> buffer;
+	vector<char> buffer;
 
-    httpRequest.encode(buffer);    
+	data->encode(buffer);
 
-    return buffer;
-}
-
-struct Http1Context
-{
-//    string buff;
+	data.reset();
 
-    TC_HttpResponse httpRsp;
-};
+	return buffer;
+}
 
 TC_NetWorkBuffer::PACKET_TYPE ProxyProtocol::http1Response(TC_NetWorkBuffer &in, ResponsePacket& rsp)
 {
-    Http1Context *context = (Http1Context*)(in.getContextData());
+	shared_ptr<TC_HttpResponse> *context = (shared_ptr<TC_HttpResponse>*)(in.getContextData());
 
-    if(context == NULL)
+    if(!context)
     {
-        context = new Http1Context();
+        context = new shared_ptr<TC_HttpResponse>();
+        *context = std::make_shared<TC_HttpResponse>();
         in.setContextData(context, [=]{ delete context; }); 
     }
 
-//    context->buff.append(in.getBuffersString());
-//    in.clearBuffers();
-
-    if(context->httpRsp.incrementDecode(in))
+    if((*context)->incrementDecode(in))
     {
-        rsp.iRequestId = ((Transceiver*)(in.getConnection()))->getAdapterProxy()->getId();
+	    rsp.sBuffer.resize(sizeof(shared_ptr<TC_HttpResponse>));
 
-        rsp.status["status"]  = context->httpRsp.getResponseHeaderLine();
-        for (const auto& kv : context->httpRsp.getHeaders())
-        {
-            rsp.status[kv.first] = kv.second; 
-        } 
+	    shared_ptr<TC_HttpResponse> &data = *(shared_ptr<TC_HttpResponse>*)rsp.sBuffer.data();
 
-        rsp.sBuffer.assign(context->httpRsp.getContent().begin(), context->httpRsp.getContent().end());
+	    data = *context;
 
-        delete context;
+	    if(!data->checkHeader("Connection", "keep-alive"))
+	    {
+		    Transceiver* session = (Transceiver*)(in.getConnection());
 
-        context = NULL;
+		    session->close();
+	    }
 
-        in.setContextData(NULL); 
+		(*context) = NULL;
+		delete context;
+		in.setContextData(NULL);
 
-        return TC_NetWorkBuffer::PACKET_FULL;
+	    return TC_NetWorkBuffer::PACKET_FULL;
 
     }
 
     return TC_NetWorkBuffer::PACKET_LESS;
 }
 
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+// vector<char> ProxyProtocol::httpJceRequest(taf::BasePacket& request, Transceiver *trans)
+// {
+// 	TC_HttpRequest httpRequest;
+
+// 	string uri;
+// 	if(trans->isSSL())
+// 		uri = "https://";
+// 	else
+// 		uri = "http://";
+
+// 	uri += trans->getEndpointInfo().getEndpoint().getHost();
+
+// 	vector<char> buff = tafRequest(request, trans);
+
+// 	for(auto it = request.context.begin(); it != request.context.end(); ++it)
+// 	{
+// 		if(it->second == ":path")
+// 		{
+// 			uri += "/" + it->second;
+// 		}
+// 		else
+// 		{
+// 			httpRequest.setHeader(it->first, it->second);
+// 		}
+// 	}
+
+// 	httpRequest.setPostRequest(uri, buff.data(), buff.size(), true);
+
+// 	vector<char> buffer;
+
+// 	httpRequest.encode(buffer);
+
+// 	return buffer;
+// }
+
+// TC_NetWorkBuffer::PACKET_TYPE ProxyProtocol::httpJceResponse(TC_NetWorkBuffer &in, BasePacket& rsp)
+// {
+// 	TC_HttpResponse *context = (TC_HttpResponse*)(in.getContextData());
+
+// 	if(!context)
+// 	{
+// 		context = new TC_HttpResponse();
+// 		in.setContextData(context, [=]{ delete context; });
+// 	}
+
+// 	if(context->incrementDecode(in))
+// 	{
+// 		if(context->getStatus() != 200)
+// 		{
+// 			rsp.iRet = taf::JCESERVERUNKNOWNERR;
+// 			rsp.sResultDesc = context->getContent();
+// 			return TC_NetWorkBuffer::PACKET_FULL;
+// 		}
+
+// 		JceInputStream<> is;
+// 		is.setBuffer(context->getContent().c_str() + 4, context->getContent().size() - 4);
+
+// 		rsp.readFrom(is);
+
+// 		if(!context->checkHeader("Connection", "keep-alive"))
+// 		{
+// 			Transceiver* session = (Transceiver*)(in.getConnection());
+
+// 			session->close();
+// 		}
+
+// 		context = NULL;
+// 		delete context;
+// 		in.setContextData(NULL);
+
+// 		return TC_NetWorkBuffer::PACKET_FULL;
+// 	}
+
+// 	return TC_NetWorkBuffer::PACKET_LESS;
+// }
+
 #if TARS_HTTP2
 
 // ENCODE function, called by network thread
@@ -133,7 +205,13 @@ vector<char> ProxyProtocol::http2Request(RequestPacket& request, Transceiver *tr
 		session->settings(3000);
 	}
 
-	request.iRequestId = session->submit(request.sFuncName, request.sServantName, request.context, request.sBuffer);
+	shared_ptr<TC_HttpRequest> *data = (shared_ptr<TC_HttpRequest>*)request.sBuffer.data();
+
+	request.iRequestId = session->submit(*(*data).get());
+
+	//这里把智能指针释放一次
+	(*data).reset();
+
 	if (request.iRequestId < 0)
 	{
 		TLOGERROR("[TARS]http2Request::Fatal submit error: " << session->getErrMsg() << endl);
@@ -156,8 +234,11 @@ TC_NetWorkBuffer::PACKET_TYPE ProxyProtocol::http2Response(TC_NetWorkBuffer &in,
 	if(flag == TC_NetWorkBuffer::PACKET_FULL)
 	{
 		rsp.iRequestId  = out.first;
-		out.second->getHeaders(rsp.status);
-		rsp.sBuffer.assign(out.second->getContent().begin(), out.second->getContent().end());
+
+		rsp.sBuffer.resize(sizeof(shared_ptr<TC_HttpResponse>));
+
+		//这里智能指针有一次+1, 后面要自己reset掉
+		*(shared_ptr<TC_HttpResponse>*)rsp.sBuffer.data() = out.second;
 	}
 
 	return flag;

+ 68 - 35
servant/libservant/Application.cpp

@@ -16,7 +16,7 @@
 
 #include "util/tc_option.h"
 #include "util/tc_common.h"
-#include "servant/TarsNodeF.h"
+#include "servant/KeepAliveNodeF.h"
 #include "servant/Application.h"
 #include "servant/AppProtocol.h"
 #include "servant/AdminServant.h"
@@ -95,6 +95,7 @@ std::string ServerConfig::CA;
 std::string ServerConfig::Cert;
 std::string ServerConfig::Key;
 bool ServerConfig::VerifyClient = false;
+std::string ServerConfig::Ciphers;
 #endif
 
 map<string, string> ServerConfig::Context;
@@ -198,7 +199,7 @@ void Application::waitForShutdown()
 
     destroyApp();
 
-    TarsRemoteNotify::getInstance()->report("stop");
+    RemoteNotify::getInstance()->report("stop");
 
 	std::this_thread::sleep_for(std::chrono::milliseconds(100)); //稍微休息一下, 让当前处理包能够回复
 
@@ -302,7 +303,7 @@ bool Application::cmdSetLogLevel(const string& command, const string& params, st
 
     string level = TC_Common::trim(params);
 
-    int ret = TarsRollLogger::getInstance()->logger()->setLogLevel(level);
+    int ret = LocalRollLogger::getInstance()->logger()->setLogLevel(level);
 
     if(ret == 0)
     {
@@ -372,13 +373,13 @@ bool Application::cmdEnableDayLog(const string& command, const string& params, s
 
     if(vParams[0] == "local")
     {
-        TarsTimeLogger::getInstance()->enableLocal(sFile,bEnable);
+        RemoteTimeLogger::getInstance()->enableLocal(sFile,bEnable);
         return true;
     }
 
     if(vParams[0] == "remote")
     {
-        TarsTimeLogger::getInstance()->enableRemote(sFile,bEnable);
+        RemoteTimeLogger::getInstance()->enableRemote(sFile,bEnable);
         return true;
     }
 
@@ -393,14 +394,14 @@ bool Application::cmdLoadConfig(const string& command, const string& params, str
 
     string filename = TC_Common::trim(params);
 
-    if (TarsRemoteConfig::getInstance()->addConfig(filename, result,false))
+    if (RemoteConfig::getInstance()->addConfig(filename, result,false))
     {
-        TarsRemoteNotify::getInstance()->report(result);
+        RemoteNotify::getInstance()->report(result);
 
         return true;
     }
 
-    TarsRemoteNotify::getInstance()->report(result);
+    RemoteNotify::getInstance()->report(result);
 
     return true;
 }
@@ -453,6 +454,33 @@ bool Application::cmdViewVersion(const string& command, const string& params, st
     return true;
 }
 
+bool Application::cmdViewBuildID(const string& command, const string& params, string& result)
+{
+    #define YEARSUF ((__DATE__ [9] - '0') * 10 + (__DATE__ [10] - '0'))
+
+    #define MONTH (__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? 0 : 5)  \
+        : __DATE__ [2] == 'b' ? 1 \
+        : __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 2 : 3) \
+        : __DATE__ [2] == 'y' ? 4 \
+        : __DATE__ [2] == 'l' ? 6 \
+        : __DATE__ [2] == 'g' ? 7 \
+        : __DATE__ [2] == 'p' ? 8 \
+        : __DATE__ [2] == 't' ? 9 \
+        : __DATE__ [2] == 'v' ? 10 : 11)
+
+    #define DAY ((__DATE__ [4] == ' ' ? 0 : __DATE__ [4] - '0') * 10 \
+        + (__DATE__ [5] - '0'))
+
+	#define TIMEINT ((((((__TIME__[0] - '0') * 10 + (__TIME__[1] - '0')) * 10 \
+        + (__TIME__[3] - '0')) * 10 + (__TIME__[4] - '0')) * 10 \
+        + (__TIME__[6] - '0')) * 10 + (__TIME__[7] - '0'))
+
+    char buildTime[50] = {0};
+    sprintf(buildTime, "%d.%02d%02d.%06d", YEARSUF, MONTH + 1, DAY, TIMEINT);
+    result = "$" + ServerConfig::Application + "." + ServerConfig::ServerName + "-" + string(buildTime) + "$";
+    return true;
+}
+
 bool Application::cmdLoadProperty(const string& command, const string& params, string& result)
 {
     try
@@ -472,15 +500,15 @@ bool Application::cmdLoadProperty(const string& command, const string& params, s
         //加载远程对象
         ServerConfig::Log = _conf.get("/tars/application/server<log>");
 
-        TarsTimeLogger::getInstance()->setLogInfo(_communicator, ServerConfig::Log, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath,setDivision());
+        RemoteTimeLogger::getInstance()->setLogInfo(_communicator, ServerConfig::Log, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath,setDivision());
 
         ServerConfig::Config = _conf.get("/tars/application/server<config>");
 
-        TarsRemoteConfig::getInstance()->setConfigInfo(_communicator, ServerConfig::Config, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::BasePath,setDivision(), 5);
+        RemoteConfig::getInstance()->setConfigInfo(_communicator, ServerConfig::Config, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::BasePath,setDivision(), 5);
 
         ServerConfig::Notify = _conf.get("/tars/application/server<notify>");
 
-        TarsRemoteNotify::getInstance()->setNotifyInfo(_communicator, ServerConfig::Notify, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LocalIp, setDivision());
+        RemoteNotify::getInstance()->setNotifyInfo(_communicator, ServerConfig::Notify, ServerConfig::Application, ServerConfig::ServerName, setDivision());
 
         result = "loaded config items:\r\n" + sResult +
                  "log=" + ServerConfig::Log + "\r\n" +
@@ -591,7 +619,7 @@ bool Application::cmdViewResource(const string& command, const string& params, s
 
 	ostringstream os;
 
-	os << _communicator->getResouresInfo() << endl;
+	os << _communicator->getResourcesInfo() << endl;
 
 	os << OUT_LINE << endl;
 
@@ -626,13 +654,13 @@ bool Application::addConfig(const string &filename)
 {
     string result;
 
-    if (TarsRemoteConfig::getInstance()->addConfig(filename, result, false))
+    if (RemoteConfig::getInstance()->addConfig(filename, result, false))
     {
-        TarsRemoteNotify::getInstance()->report(result);
+        RemoteNotify::getInstance()->report(result);
 
         return true;
     }
-    TarsRemoteNotify::getInstance()->report(result);
+    RemoteNotify::getInstance()->report(result);
 
     return true;
 }
@@ -642,15 +670,15 @@ bool Application::addAppConfig(const string &filename)
     string result = "";
 
     // true-只获取应用级别配置
-    if (TarsRemoteConfig::getInstance()->addConfig(filename, result, true))
+    if (RemoteConfig::getInstance()->addConfig(filename, result, true))
 
     {
-        TarsRemoteNotify::getInstance()->report(result);
+        RemoteNotify::getInstance()->report(result);
 
         return true;
     }
 
-    TarsRemoteNotify::getInstance()->report(result);
+    RemoteNotify::getInstance()->report(result);
 
     return true;
 }
@@ -723,7 +751,7 @@ void Application::main(const TC_Option &option)
             catch (exception & ex)
             {
                 keepActiving.detach();
-                TarsRemoteNotify::getInstance()->report("exit: " + string(ex.what()));
+                RemoteNotify::getInstance()->report("exit: " + string(ex.what()));
 	            std::this_thread::sleep_for(std::chrono::milliseconds(100)); //稍微休息一下, 让当前处理包能够回复
 
 	            cout << "[init exception]:" << ex.what() << endl;
@@ -749,6 +777,9 @@ void Application::main(const TC_Option &option)
         //查看编译的TARS版本
         TARS_ADD_ADMIN_CMD_PREFIX(TARS_CMD_VIEW_VERSION, Application::cmdViewVersion);
 
+        //查看服务buildid(编译时间)
+        TARS_ADD_ADMIN_CMD_PREFIX(TARS_CMD_VIEW_BID, Application::cmdViewBuildID);
+
         //加载配置文件中的属性信息
         TARS_ADD_ADMIN_CMD_PREFIX(TARS_CMD_LOAD_PROPERTY, Application::cmdLoadProperty);
 
@@ -777,7 +808,7 @@ void Application::main(const TC_Option &option)
         TARS_KEEPALIVE("");
 
         //发送给notify表示服务启动了
-        TarsRemoteNotify::getInstance()->report("restart");
+        RemoteNotify::getInstance()->report("restart");
 
         //ctrl + c能够完美结束服务
 #if TARGET_PLATFORM_LINUX || TARGET_PLATFORM_IOS
@@ -811,7 +842,7 @@ void Application::main(const TC_Option &option)
     {
         cout << "[main exception]:" << ex.what() << endl;
 
-        TarsRemoteNotify::getInstance()->report("exit: " + string(ex.what()));
+        RemoteNotify::getInstance()->report("exit: " + string(ex.what()));
 
 	    std::this_thread::sleep_for(std::chrono::milliseconds(100)); //稍微休息一下, 让当前处理包能够回复
 
@@ -819,7 +850,7 @@ void Application::main(const TC_Option &option)
     }
 
     //初始化完毕后, 日志再修改为异步
-    TarsRollLogger::getInstance()->sync(false);
+    LocalRollLogger::getInstance()->sync(false);
 }
 
 void Application::parseConfig(const TC_Option &op)
@@ -971,12 +1002,12 @@ void Application::outServer(ostream &os)
 	os << TC_Common::outfill("BackPacketLimit(backpacketlimit)")  << ServerConfig::BackPacketLimit<< endl;
 	os << TC_Common::outfill("BackPacketMin(backpacketmin)")  << ServerConfig::BackPacketMin<< endl;
 
-#if TAF_SSL
+#if TARS_SSL
 	cout << TC_Common::outfill("Ca(ca)")                    << ServerConfig::CA << endl;
 	cout << TC_Common::outfill("Cert(cert)")              << ServerConfig::Cert << endl;
 	cout << TC_Common::outfill("Key(key)")                  << ServerConfig::Key << endl;
 	cout << TC_Common::outfill("VerifyClient(verifyclient)")      << ServerConfig::VerifyClient << endl;
-//	cout << TC_Common::outfill("Ciphers(ciphers)")               << ServerConfig::Ciphers << endl;
+	cout << TC_Common::outfill("Ciphers(ciphers)")               << ServerConfig::Ciphers << endl;
 #endif
 
 }
@@ -1056,9 +1087,10 @@ void Application::initializeServer()
 	ServerConfig::Cert              = _conf.get("/tars/application/server<cert>");
 	ServerConfig::Key               = _conf.get("/tars/application/server<key>");
 	ServerConfig::VerifyClient      = _conf.get("/tars/application/server<verifyclient>","0")=="0"?false:true;
+	ServerConfig::Ciphers           = _conf.get("/tars/application/server<ciphers>");
 
 	if(!ServerConfig::Cert.empty()) {
-		_ctx = TC_OpenSSL::newCtx(ServerConfig::CA, ServerConfig::Cert, ServerConfig::Key, ServerConfig::VerifyClient);
+		_ctx = TC_OpenSSL::newCtx(ServerConfig::CA, ServerConfig::Cert, ServerConfig::Key, ServerConfig::VerifyClient, ServerConfig::Ciphers);
 
 		if (!_ctx) {
 			TLOGERROR("[TARS]load server ssl error, ca:" << ServerConfig::CA << endl);
@@ -1120,11 +1152,11 @@ void Application::initializeServer()
     ///////////////////////////////////////////////////////////////////////////////////////////////////
     //初始化本地Log
     cout << OUT_LINE << "\n" << TC_Common::outfill("[set roll logger] ") << "OK" << endl;
-    TarsRollLogger::getInstance()->setLogInfo(ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath, ServerConfig::LogSize, ServerConfig::LogNum, _communicator, ServerConfig::Log);
-    _epollServer->setLocalLogger(TarsRollLogger::getInstance()->logger());
+    LocalRollLogger::getInstance()->setLogInfo(ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath, ServerConfig::LogSize, ServerConfig::LogNum, _communicator, ServerConfig::Log);
+    _epollServer->setLocalLogger(LocalRollLogger::getInstance()->logger());
 
     //初始化是日志为同步
-    TarsRollLogger::getInstance()->sync(true);
+    LocalRollLogger::getInstance()->sync(true);
 
     //设置日志级别
     string level = AppCache::getInstance()->get("logLevel");
@@ -1135,28 +1167,28 @@ void Application::initializeServer()
 
 	ServerConfig::LogLevel = TC_Common::upper(level);
 
-	TarsRollLogger::getInstance()->logger()->setLogLevel(ServerConfig::LogLevel);
+	LocalRollLogger::getInstance()->logger()->setLogLevel(ServerConfig::LogLevel);
 
     ///////////////////////////////////////////////////////////////////////////////////////////////////
     //初始化到LogServer代理
     cout << OUT_LINE << "\n" << TC_Common::outfill("[set time logger] ") << "OK" << endl;
     bool bLogStatReport = (_conf.get("/tars/application/server<logstatreport>", "0") == "1") ? true : false;
-    TarsTimeLogger::getInstance()->setLogInfo(_communicator, ServerConfig::Log, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath, setDivision(), bLogStatReport);
+    RemoteTimeLogger::getInstance()->setLogInfo(_communicator, ServerConfig::Log, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath, setDivision(), bLogStatReport);
 
     ///////////////////////////////////////////////////////////////////////////////////////////////////
     //初始化到配置中心代理
     cout << OUT_LINE << "\n" << TC_Common::outfill("[set remote config] ") << "OK" << endl;
-    TarsRemoteConfig::getInstance()->setConfigInfo(_communicator, ServerConfig::Config, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::BasePath,setDivision());
+    RemoteConfig::getInstance()->setConfigInfo(_communicator, ServerConfig::Config, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::BasePath,setDivision());
 
     ///////////////////////////////////////////////////////////////////////////////////////////////////
     //初始化到信息中心代理
     cout << OUT_LINE << "\n" << TC_Common::outfill("[set remote notify] ") << "OK" << endl;
-    TarsRemoteNotify::getInstance()->setNotifyInfo(_communicator, ServerConfig::Notify, ServerConfig::Application, ServerConfig::ServerName, setDivision(), ServerConfig::LocalIp);
+    RemoteNotify::getInstance()->setNotifyInfo(_communicator, ServerConfig::Notify, ServerConfig::Application, ServerConfig::ServerName, setDivision());
 
     ///////////////////////////////////////////////////////////////////////////////////////////////////
     //初始化到Node的代理
     cout << OUT_LINE << "\n" << TC_Common::outfill("[set node proxy]") << "OK" << endl;
-    TarsNodeFHelper::getInstance()->setNodeInfo(_communicator, ServerConfig::Node, ServerConfig::Application, ServerConfig::ServerName);
+    KeepAliveNodeFHelper::getInstance()->setNodeInfo(_communicator, ServerConfig::Node, ServerConfig::Application, ServerConfig::ServerName);
 
     ///////////////////////////////////////////////////////////////////////////////////////////////////
     //初始化管理对象
@@ -1227,8 +1259,9 @@ void Application::setAdapter(TC_EpollServer::BindAdapterPtr& adapter, const stri
 		string key = _conf.get("/tars/application/server/" + name + "<key>");
 		bool verifyClient =
 			_conf.get("/tars/application/server/" + name + "<verifyclient>", "0") == "0" ? false : true;
+		string ciphers = _conf.get("/tars/application/server/" + name + "<ciphers>");
 
-		shared_ptr<TC_OpenSSL::CTX> ctx = TC_OpenSSL::newCtx(ca, cert, key, verifyClient);
+		shared_ptr<TC_OpenSSL::CTX> ctx = TC_OpenSSL::newCtx(ca, cert, key, verifyClient, ciphers);
 
 		if (!ctx) {
 			TLOGERROR("[TARS]load server ssl error, cert:" << cert << endl);
@@ -1340,7 +1373,7 @@ void Application::checkServantNameValid(const string& servant, const string& sPr
 
         os << "Servant '" << servant << "' error: must be start with '" << sPrefix << "'";
 
-        TarsRemoteNotify::getInstance()->report("exit:" + os.str());
+        RemoteNotify::getInstance()->report("exit:" + os.str());
 
 	    std::this_thread::sleep_for(std::chrono::milliseconds(100)); //稍微休息一下, 让当前处理包能够回复
 

+ 2 - 2
servant/libservant/AsyncProcThread.cpp

@@ -17,7 +17,7 @@
 #include "servant/AsyncProcThread.h"
 #include "servant/Communicator.h"
 #include "servant/StatReport.h"
-#include "servant/TarsLogger.h"
+#include "servant/RemoteLogger.h"
 
 namespace tars
 {
@@ -119,7 +119,7 @@ void AsyncProcThread::callback(ReqMessage * msg)
 	try
 	{
 		ReqMessagePtr msgPtr = msg;
-		msg->callback->onDispatch(msgPtr);
+		msg->callback->dispatch(msgPtr);
 	}
 	catch (exception& e)
 	{

+ 1 - 1
servant/libservant/CMakeLists.txt

@@ -1,4 +1,4 @@
-if(_USE_OPENTRACKING)
+if(TARS_OPENTRACKING)
 include_directories(${PROJECT_SOURCE_DIR} ${OPENTRACKING_INC})
 else()
 include_directories(${PROJECT_SOURCE_DIR})

+ 44 - 19
servant/libservant/Communicator.cpp

@@ -18,7 +18,7 @@
 #include "servant/Communicator.h"
 #include "servant/Application.h"
 #include "servant/StatReport.h"
-#include "servant/TarsLogger.h"
+#include "servant/RemoteLogger.h"
 
 namespace tars
 {
@@ -46,7 +46,7 @@ Communicator::Communicator()
 , _statReport(NULL)
 , _timeoutLogFlag(true)
 , _minTimeout(100)
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
 , _traceManager(NULL)
 #endif
 {
@@ -61,7 +61,7 @@ Communicator::Communicator(TC_Config& conf, const string& domain/* = CONFIG_ROOT
 : _initialized(false)
 , _terminating(false)
 , _timeoutLogFlag(true)
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
 , _traceManager(NULL)
 #endif
 {
@@ -120,6 +120,13 @@ string Communicator::getServantProperty(const string &sObj, const string& name)
 	return "";
 }
 
+void Communicator::setServantCustomCallback(const string &sObj, Communicator::custom_callback callback)
+{
+	TC_LockT<TC_SpinLock> lock(_callbackLock);
+
+	_callback[sObj] = callback;
+}
+
 #if TARS_SSL
 shared_ptr<TC_OpenSSL> Communicator::newClientSSL(const string & objName)
 {
@@ -131,6 +138,10 @@ shared_ptr<TC_OpenSSL> Communicator::newClientSSL(const string & objName)
 		return TC_OpenSSL::newSSL(it->second);
 	}
 
+	if(!_ctx) {
+		_ctx = TC_OpenSSL::newCtx("", "", "", false, "");
+	}
+
 	return TC_OpenSSL::newSSL(_ctx);
 }
 
@@ -161,11 +172,13 @@ void Communicator::setProperty(TC_Config& conf, const string& domain/* = CONFIG_
 			data["ca"]        = conf.get("/tars/application/client/" + auths[i] + "<ca>");
 			data["cert"]      = conf.get("/tars/application/client/" + auths[i] + "<cert>");
 			data["key"]       = conf.get("/tars/application/client/" + auths[i] + "<key>");
+			data["ciphers"]   = conf.get("/tars/application/client/" + auths[i] + "<ciphers>");
+
 #if TARS_SSL
 
 			if(!data["ca"].empty())
 			{
-				shared_ptr<TC_OpenSSL::CTX> ctx = TC_OpenSSL::newCtx( data["ca"], data["cert"], data["key"], false);
+				shared_ptr<TC_OpenSSL::CTX> ctx = TC_OpenSSL::newCtx( data["ca"], data["cert"], data["key"], false, data["ciphers"]);
 				if(!ctx)
 				{
 					TLOGERROR("[TARS]load obj:" << auths[i] << ", ssl error, ca:" << data["ca"] << endl);
@@ -244,9 +257,10 @@ void Communicator::initialize()
 	string ca   = getProperty("ca");
 	string cert = getProperty("cert");
 	string key  = getProperty("key");
+	string ciphers  = getProperty("ciphers");
 
 	if(!ca.empty()) {
-		_ctx = TC_OpenSSL::newCtx(ca, cert, key, false);
+		_ctx = TC_OpenSSL::newCtx(ca, cert, key, false, ciphers);
 
 		if(!_ctx)
 		{
@@ -317,9 +331,9 @@ void Communicator::initialize()
 
 	int iReportTimeout = TC_Common::strto<int>(getProperty("report-timeout", "5000"));
 
-	int iSampleRate = TC_Common::strto<int>(getProperty("sample-rate", "1000"));
+	// int iSampleRate = TC_Common::strto<int>(getProperty("sample-rate", "1000"));
 
-	int iMaxSampleCount = TC_Common::strto<int>(getProperty("max-sample-count", "100"));
+	// int iMaxSampleCount = TC_Common::strto<int>(getProperty("max-sample-count", "100"));
 
 	int iMaxReportSize = TC_Common::strto<int>(getProperty("max-report-size", "1400"));
 
@@ -343,9 +357,9 @@ void Communicator::initialize()
 	}
 
 	string sSetDivision = ClientConfig::SetOpen?ClientConfig::SetDivision:"";
-	_statReport->setReportInfo(statPrx, propertyPrx, ClientConfig::ModuleName, ClientConfig::LocalIp, sSetDivision, iReportInterval, iSampleRate, iMaxSampleCount, iMaxReportSize, iReportTimeout);
+	_statReport->setReportInfo(statPrx, propertyPrx, ClientConfig::ModuleName, ClientConfig::LocalIp, sSetDivision, iReportInterval, 0, 0, iMaxReportSize, iReportTimeout);
 
-#if _USE_OPENTRACKING
+#if TARS_OPENTRACKING
 	string collector_host = getProperty("collector_host", "");
     string collector_port = getProperty("collector_port", "");
     if(!collector_host.empty() && !collector_port.empty())
@@ -412,9 +426,9 @@ int Communicator::reloadProperty(string & sResult)
 
     int iReportTimeout = TC_Common::strto<int>(getProperty("report-timeout", "5000"));
 
-    int iSampleRate = TC_Common::strto<int>(getProperty("sample-rate", "1000"));
+    // int iSampleRate = TC_Common::strto<int>(getProperty("sample-rate", "1000"));
 
-    int iMaxSampleCount = TC_Common::strto<int>(getProperty("max-sample-count", "100"));
+    // int iMaxSampleCount = TC_Common::strto<int>(getProperty("max-sample-count", "100"));
 
     int iMaxReportSize = TC_Common::strto<int>(getProperty("max-report-size", "1400"));
 
@@ -437,15 +451,15 @@ int Communicator::reloadProperty(string & sResult)
     }
 
     string sSetDivision = ClientConfig::SetOpen?ClientConfig::SetDivision:"";
-    _statReport->setReportInfo(statPrx, propertyPrx, ClientConfig::ModuleName, ClientConfig::LocalIp, sSetDivision, iReportInterval, iSampleRate, iMaxSampleCount, iMaxReportSize, iReportTimeout);
+    _statReport->setReportInfo(statPrx, propertyPrx, ClientConfig::ModuleName, ClientConfig::LocalIp, sSetDivision, iReportInterval, 0, 0, iMaxReportSize, iReportTimeout);
 
     sResult = "locator=" + getProperty("locator", "") + "\r\n" +
         "stat=" + statObj + "\r\n" + "property=" + propertyObj + "\r\n" +
         "SetDivision=" + sSetDivision + "\r\n" +
         "report-interval=" + TC_Common::tostr(iReportInterval) + "\r\n" +
-        "report-timeout=" + TC_Common::tostr(iReportTimeout) + "\r\n" +
-        "sample-rate=" + TC_Common::tostr(iSampleRate) + "\r\n" +
-        "max-sample-count=" + TC_Common::tostr(iMaxSampleCount) + "\r\n";
+        "report-timeout=" + TC_Common::tostr(iReportTimeout) + "\r\n";
+        // "sample-rate=" + TC_Common::tostr(iSampleRate) + "\r\n" +
+        // "max-sample-count=" + TC_Common::tostr(iMaxSampleCount) + "\r\n";
 
     return 0;
 }
@@ -462,13 +476,13 @@ vector<TC_Endpoint> Communicator::getEndpoint4All(const string & objName)
     return pServantProxy->getEndpoint4All();
 }
 
-string Communicator::getResouresInfo()
+string Communicator::getResourcesInfo()
 {
 	ostringstream os;
 	for (size_t i = 0; i < _clientThreadNum; ++i)
 	{
 		os << OUT_LINE << endl;
-		os << _communicatorEpoll[i]->getResouresInfo();
+		os << _communicatorEpoll[i]->getResourcesInfo();
 	}
 	return os.str();
 }
@@ -542,8 +556,19 @@ void Communicator::terminate()
 
 void Communicator::pushAsyncThreadQueue(ReqMessage * msg)
 {
-    //先不考虑每个线程队列数目不一致的情况
-    _asyncThread[(_asyncSeq++)%_asyncThreadNum]->push_back(msg);
+	{
+		TC_LockT<TC_SpinLock> lock(_callbackLock);
+
+		auto it = _callback.find(msg->request.sServantName);
+		if (it != _callback.end()) {
+			ReqMessagePtr msgPtr = msg;
+			it->second(msgPtr);
+			return;
+		}
+	}
+
+	//先不考虑每个线程队列数目不一致的情况
+	_asyncThread[(_asyncSeq++) % _asyncThreadNum]->push_back(msg);
 }
 
 void Communicator::doStat()

+ 2 - 2
servant/libservant/CommunicatorEpoll.cpp

@@ -17,7 +17,7 @@
 #include "servant/CommunicatorEpoll.h"
 #include "servant/Communicator.h"
 #include "servant/Application.h"
-#include "servant/TarsLogger.h"
+#include "servant/RemoteLogger.h"
 #include "servant/StatReport.h"
 
 using namespace std;
@@ -388,7 +388,7 @@ void CommunicatorEpoll::reConnect(int64_t ms, Transceiver*p)
 	_reconnect[ms] = p;
 }
 
-string CommunicatorEpoll::getResouresInfo()
+string CommunicatorEpoll::getResourcesInfo()
 {
 	ostringstream desc;
 	desc << TC_Common::outfill("index") << _netThreadSeq << endl;

+ 1 - 1
servant/libservant/CoroutineScheduler.cpp

@@ -33,7 +33,7 @@
 #include <assert.h>
 #include "util/tc_timeprovider.h"
 
-#include "servant/TarsLogger.h"
+#include "servant/RemoteLogger.h"
 #include "servant/ServantHandle.h"
 
 namespace tars 

+ 1 - 1
servant/libservant/EndpointInfo.cpp

@@ -15,7 +15,7 @@
  */
 
 #include "servant/EndpointInfo.h"
-#include "servant/TarsLogger.h"
+#include "servant/RemoteLogger.h"
 #include "servant/NetworkUtil.h"
 #include "util/tc_socket.h"
 

+ 29 - 4
servant/libservant/EndpointManager.cpp

@@ -16,7 +16,7 @@
 #include "util/tc_port.h"
 #include "servant/EndpointManager.h"
 #include "servant/ObjectProxy.h"
-#include "servant/TarsLogger.h"
+#include "servant/RemoteLogger.h"
 #include "servant/AppCache.h"
 #include "servant/Application.h"
 #include "servant/StatReport.h"
@@ -34,6 +34,7 @@ QueryEpBase::QueryEpBase(Communicator * pComm, bool bFirstNetThread,bool bInterf
 , _locator("")
 , _valid(false)
 , _weightType(E_LOOP)
+, _rootServant(true)
 , _requestRegistry(false)
 , _requestTimeout(0)
 , _timeoutInterval(5*1000)
@@ -158,12 +159,19 @@ void QueryEpBase::setObjName(const string & sObjName)
     if (pos != string::npos)
     {
         //[直接连接]指定服务的IP和端口列表
-
         _objName = sObjName.substr(0,pos);
 
         sEndpoints = sObjName.substr(pos + 1);
 
-        _direct = true;
+	    pos = _objName.find_first_of("#");
+
+	    if(pos != string::npos)
+	    {
+		    _rootServant    = false;
+		    _objName        = _objName.substr(0, pos);
+	    }
+
+	    _direct = true;
 
         _valid = true;
     }
@@ -182,6 +190,13 @@ void QueryEpBase::setObjName(const string & sObjName)
             throw TarsRegistryException("locator is not valid,_locator:" + _locator);
         }
 
+	    pos = _objName.find_first_of("#");
+	    if(pos != string::npos)
+	    {
+		    _objName = _objName.substr(0, pos);
+	    }
+
+
         _queryFPrx = _communicator->stringToProxy<QueryFPrx>(_locator);
 
         string sLocatorKey = _locator;
@@ -378,6 +393,9 @@ void QueryEpBase::refreshReg(GetEndpointType type, const string & sName)
         //内部请求主控都是异步请求
         //接口请求主控第一次是同步请求
         bool bSync = (!_valid && _interfaceReq);
+	    //如果是异步且不是根servant(通过#1创建的servant, 不主动更新主控信息)
+        if(!bSync && !_rootServant)
+	        return;
         try
         {
             if(bSync)
@@ -704,7 +722,7 @@ EndpointManager::~EndpointManager()
     }
 }
 
-void EndpointManager::notifyEndpoints(const set<EndpointInfo> & active, const set<EndpointInfo> & inactive, bool bSync)
+void EndpointManager::updateEndpoints(const set<EndpointInfo> & active, const set<EndpointInfo> & inactive)
 {
     set<EndpointInfo>::const_iterator iter;
     map<string,AdapterProxy*>::iterator iterAdapter;
@@ -788,6 +806,13 @@ void EndpointManager::notifyEndpoints(const set<EndpointInfo> & active, const se
     _update = true;
 }
 
+void EndpointManager::notifyEndpoints(const set<EndpointInfo> & active,const set<EndpointInfo> & inactive,bool bNotify)
+{
+	updateEndpoints(active, inactive);
+
+    _objectProxy->onNotifyEndpoints(active, inactive);
+}
+
 void EndpointManager::doNotify()
 {
     _objectProxy->doInvoke();

+ 2 - 20
servant/libservant/NetworkUtil.cpp

@@ -42,6 +42,7 @@ int NetworkUtil::createSocket(bool udp, bool isLocal, bool isIpv6)
     {
         s.setTcpNoDelay();
 	    s.setKeepAlive();
+	    s.setNoCloseWait();
     }
     else
     {
@@ -58,25 +59,6 @@ void NetworkUtil::closeSocketNoThrow(int fd)
     TC_Port::closeSocket(fd);
 }
 
-//bool NetworkUtil::doConnect(int fd, const struct sockaddr& addr)
-//{
-//	bool bConnected = false;
-//
-//	int iRet = ::connect(fd, (struct sockaddr*)(&addr), int(sizeof(addr)));
-//
-//	if (iRet == 0)
-//	{
-//		bConnected  = true;
-//	}
-//	else if (!TC_Socket::isInProgress())
-//	{
-//        closeSocketNoThrow(fd);
-//        TARS_THROW_EXCEPTION_SYSCODE(TafNetConnectException, "NetworkUtil::doConnect error");
-//	}
-//
-//    return bConnected;
-//}
-
 bool NetworkUtil::doConnect(int fd, const struct sockaddr *addr, socklen_t len)
 {
 	bool bConnected = false;
@@ -90,7 +72,7 @@ bool NetworkUtil::doConnect(int fd, const struct sockaddr *addr, socklen_t len)
 	else if (!TC_Socket::isInProgress())
 	{
         closeSocketNoThrow(fd);
-        TARS_THROW_EXCEPTION_SYSCODE(TarsNetConnectException, "NetworkUtil::doConnect error");
+        THROW_EXCEPTION_SYSCODE(TarsNetConnectException, "NetworkUtil::doConnect error");
 	}
 
     return bConnected;

+ 115 - 36
servant/libservant/ObjectProxy.cpp

@@ -21,7 +21,7 @@
 #include "servant/AppCache.h"
 #include "util/tc_common.h"
 #include "util/tc_clientsocket.h"
-#include "servant/TarsLogger.h"
+#include "servant/RemoteLogger.h"
 
 namespace tars
 {
@@ -39,7 +39,8 @@ ObjectProxy::ObjectProxy(CommunicatorEpoll * pCommunicatorEpoll, const string &
 
     if(pos != string::npos)
     {
-        _name = sObjectProxyName.substr(0,pos);
+        _name       = sObjectProxyName.substr(0,pos);
+	    _address    = sObjectProxyName.substr(pos+1);
     }
     else
     {
@@ -53,9 +54,18 @@ ObjectProxy::ObjectProxy(CommunicatorEpoll * pCommunicatorEpoll, const string &
         }
     }
 
-    _proxyProtocol.requestFunc  = ProxyProtocol::tarsRequest;
+	pos = _name.find_first_of('#');
+
+	if(pos != string::npos)
+	{
+		_hash = _name.substr(pos+1);
+		_name = _name.substr(0,pos);
+	}
+
+    _proxyProtocol.requestFunc = ProxyProtocol::tarsRequest;
     _proxyProtocol.responseFunc = ProxyProtocol::tarsResponse;
 
+
     _endpointManger.reset(new EndpointManager(this, _communicatorEpoll->getCommunicator(), sObjectProxyName, pCommunicatorEpoll->isFirstNetThread(), setName));
 
 }
@@ -107,12 +117,6 @@ ServantProxyCallbackPtr ObjectProxy::getPushCallback()
     return _pushCallback;
 }
 
-//
-//const string& ObjectProxy::name() const
-//{
-//    return _name;
-//}
-
 void ObjectProxy::setProxyProtocol(const ProxyProtocol& protocol)
 {
     if(_hasSetProtocol)
@@ -149,7 +153,7 @@ vector<SocketOpt>& ObjectProxy::getSocketOpt()
 //
 //bool ObjectProxy::invoke_sync(ReqMessage * msg)
 //{
-//	TLOGTAF("[TAF][ObjectProxy::invoke_sync, " << _name << ", begin]" << endl);
+//	TLOGTARS("[TARS][ObjectProxy::invoke_sync, " << _name << ", begin]" << endl);
 //
 //	//选择一个远程服务的Adapter来调用
 //	AdapterProxy * pAdapterProxy = NULL;
@@ -198,42 +202,106 @@ void ObjectProxy::invoke(ReqMessage * msg)
     }
 
 	msg->adapter = pAdapterProxy;
-    pAdapterProxy->invoke(msg);
-}
 
-void ObjectProxy::doInvoke()
-{
-    TLOGTARS("[TARS][ObjectProxy::doInvoke, objname:" << _name << ", begin...]" << endl);
-
-    while(!_reqTimeoutQueue.empty())
+    //连接还没有建立, 暂时先放队列里面
+	if(!msg->adapter->getTransceiver()->hasConnected())
     {
-        TLOGTARS("[TARS][ObjectProxy::doInvoke, objname:" << _name << ", pop...]" << endl);
+        bool bRet = _reqTimeoutQueue.push(msg,msg->request.iTimeout+msg->iBeginTime);
 
-        ReqMessage * msg = NULL;
-        _reqTimeoutQueue.pop(msg);
+        assert(bRet);
 
-        assert(msg != NULL);
+        //把数据缓存在obj里面
+        TLOGTARS("[TARS][ObjectProxy::invoke, " << _name << ", select adapter proxy not connected (have not inovoke reg)]" << endl);
+        return;
+    }
 
-        //选择一个远程服务的Adapter来调用
-        AdapterProxy * pAdapterProxy = NULL;
-        _endpointManger->selectAdapterProxy(msg,pAdapterProxy, false);
+    pAdapterProxy->invoke(msg);
+}
 
-        if(!pAdapterProxy)
-        {
-            //这里肯定是请求过主控
-            TLOGERROR("[TARS][ObjectProxy::doInvoke, objname:" << _name << ", selectAdapterProxy is null]" << endl);
 
-            msg->response->iRet = TARSADAPTERNULL;
+void ObjectProxy::onConnect(AdapterProxy *adapterProxy)
+{
+	while(!_reqTimeoutQueue.empty())
+	{
+		TLOGTARS("[TARS][ObjectProxy::doInvoke, " << _name << ", pop...]" << endl);
+
+		ReqMessage * msg = NULL;
+		_reqTimeoutQueue.pop(msg);
+
+		assert(msg != NULL);
+
+		if(msg->adapter != NULL && msg->adapter != adapterProxy)
+		{
+			//选择一个远程服务的Adapter来调用
+			_endpointManger->selectAdapterProxy(msg, adapterProxy, false);
+
+			if (!adapterProxy)
+			{
+				//这里肯定是请求过主控
+				TLOGERROR("[TARS][ObjectProxy::doInvoke, " << _name << ", selectAdapterProxy is null]" << endl);
+				msg->response->iRet = TARSADAPTERNULL;
+				doInvokeException(msg);
+				return;
+			}
+
+			msg->adapter = adapterProxy;
+		}
+		else
+		{
+			msg->adapter = adapterProxy;
+		}
+
+		adapterProxy->invoke(msg);
+	}
+}
 
-            doInvokeException(msg);
+void ObjectProxy::onNotifyEndpoints(const set<EndpointInfo> & active,const set<EndpointInfo> & inactive)
+{
+	if(_servantProxy) {
+		_servantProxy->onNotifyEndpoints(active, inactive);
+	}
+}
 
-            return;
-        }
+void ObjectProxy::doInvoke()
+{
+    TLOGTARS("[TARS][ObjectProxy::doInvoke, objname:" << _name << ", begin...]" << endl);
 
-        msg->adapter = pAdapterProxy;
+    for(auto it = _reqTimeoutQueue.begin(); it != _reqTimeoutQueue.end(); ++it)
+	{
+		ReqMessage * msg = (*it).ptr;
 
-        pAdapterProxy->invoke(msg);
-    }
+		AdapterProxy* adapterProxy;
+
+		//选择一个远程服务的Adapter来调用, selectAdapterProxy会发起连接
+		_endpointManger->selectAdapterProxy(msg, adapterProxy, false);
+	}
+//
+//    while(!_reqTimeoutQueue.empty())
+//    {
+//        TLOGTARS("[TARS][ObjectProxy::doInvoke, " << _name << ", pop...]" << endl);
+//
+//        ReqMessage * msg = NULL;
+//        _reqTimeoutQueue.pop(msg);
+//
+//        assert(msg != NULL);
+//
+//	    AdapterProxy* adapterProxy;
+//
+//        //选择一个远程服务的Adapter来调用
+//        _endpointManger->selectAdapterProxy(msg, adapterProxy, false);
+//
+//        if (!adapterProxy) {
+//	        //这里肯定是请求过主控
+//	        TLOGERROR("[TARS][ObjectProxy::doInvoke, " << _name << ", selectAdapterProxy is null]" << endl);
+//	        msg->response->iRet = JCEADAPTERNULL;
+//	        doInvokeException(msg);
+//	        return;
+//        }
+//
+//        msg->adapter = adapterProxy;
+//
+//	    adapterProxy->invoke(msg);
+//    }
 }
 
 void ObjectProxy::doInvokeException(ReqMessage * msg)
@@ -280,7 +348,7 @@ void ObjectProxy::doInvokeException(ReqMessage * msg)
                 //比如获取endpoint
                 try
                 {
-                    msg->callback->onDispatch(msgPtr);
+                    msg->callback->dispatch(msgPtr);
                 }
                 catch(exception & e)
                 {
@@ -346,5 +414,16 @@ void ObjectProxy::mergeStat(map<StatMicMsgHead, StatMicMsgBody> & mStatMicMsg)
     }
 }
 
+void ObjectProxy::onSetInactive(const EndpointInfo& ep)
+{
+	const vector<AdapterProxy*> & vAdapterProxy = _endpointManger->getAdapters();
+	for(size_t iAdapter=0; iAdapter< vAdapterProxy.size();++iAdapter)
+	{
+		if(vAdapterProxy[iAdapter]->endpoint() == ep)
+		{
+			vAdapterProxy[iAdapter]->onSetInactive();
+		}
+	}
+}
 ////////////////////////////////////////////////////////////////////////////////////////////////
 }

+ 1 - 1
servant/libservant/Servant.cpp

@@ -18,7 +18,7 @@
 #include "servant/BaseF.h"
 #include "servant/Application.h"
 #include "servant/AppCache.h"
-#include "servant/TarsLogger.h"
+#include "servant/RemoteLogger.h"
 
 #include <cerrno>
 

+ 17 - 31
servant/libservant/ServantHandle.cpp

@@ -21,9 +21,9 @@
 #include "servant/ServantHelper.h"
 #include "servant/AppProtocol.h"
 #include "servant/BaseF.h"
-#include "servant/TarsNodeF.h"
-#include "servant/TarsCookie.h"
-#ifdef _USE_OPENTRACKING
+#include "servant/KeepAliveNodeF.h"
+#include "servant/Cookie.h"
+#ifdef TARS_OPENTRACKING
 #include "servant/text_map_carrier.h"
 #endif
 
@@ -352,7 +352,7 @@ void ServantHandle::initialize()
         TLOGERROR("[TARS]ServantHandle initialize createServant ret null, for adapter `" +_bindAdapter->getName() + "`" << endl);
 	    cerr << "[TARS]ServantHandle initialize createServant ret null, for adapter `" +_bindAdapter->getName() + "`" << endl;
 
-	    TarsRemoteNotify::getInstance()->report("initialize createServant error: no adapter:" + _bindAdapter->getName());
+	    RemoteNotify::getInstance()->report("initialize createServant error: no adapter:" + _bindAdapter->getName());
 
 	    TC_Common::msleep(100);
 
@@ -365,7 +365,7 @@ void ServantHandle::initialize()
     {
         TLOGERROR("[TARS]initialize error: no servant exists." << endl);
 
-        TarsRemoteNotify::getInstance()->report("initialize error: no servant exists.");
+        RemoteNotify::getInstance()->report("initialize error: no servant exists.");
 
         TC_Common::msleep(100);
 
@@ -386,7 +386,7 @@ void ServantHandle::initialize()
         {
             TLOGERROR("[TARS]initialize error:" << ex.what() << endl);
 
-            TarsRemoteNotify::getInstance()->report("initialize error:" + string(ex.what()));
+            RemoteNotify::getInstance()->report("initialize error:" + string(ex.what()));
 
 	        TC_Common::msleep(100);
 
@@ -396,7 +396,7 @@ void ServantHandle::initialize()
         {
             TLOGERROR("[TARS]initialize unknown exception error" << endl);
 
-            TarsRemoteNotify::getInstance()->report("initialize unknown exception error");
+            RemoteNotify::getInstance()->report("initialize unknown exception error");
 
 	        TC_Common::msleep(100);
 
@@ -434,7 +434,7 @@ void ServantHandle::heartbeat()
 
 TarsCurrentPtr ServantHandle::createCurrent(const shared_ptr<TC_EpollServer::RecvContext> &data)
 {
-    TarsCurrentPtr current = new TarsCurrent(this);
+    TarsCurrentPtr current = new Current(this);
 
     try
     {
@@ -478,7 +478,7 @@ TarsCurrentPtr ServantHandle::createCurrent(const shared_ptr<TC_EpollServer::Rec
 
 TarsCurrentPtr ServantHandle::createCloseCurrent(const shared_ptr<TC_EpollServer::RecvContext> &data)
 {
-    TarsCurrentPtr current = new TarsCurrent(this);
+    TarsCurrentPtr current = new Current(this);
 
     current->initializeClose(data);
     current->setReportStat(false);
@@ -580,7 +580,7 @@ void ServantHandle::handle(const shared_ptr<TC_EpollServer::RecvContext> &data)
 }
 
 
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
 void ServantHandle::processTracking(const TarsCurrentPtr &current)
 {
     if(!(Application::getCommunicator()->_traceManager))
@@ -686,21 +686,7 @@ bool ServantHandle::processDye(const TarsCurrentPtr &current, string& dyeingKey)
         return true;
     }
 
-//    //servant已经被染色, 开启染色日志
-//    if (ServantHelperManager::getInstance()->isDyeing())
-//    {
-//        map<string, string>::const_iterator dyeingKeyIt = current->getRequestStatus().find(ServantProxy::STATUS_GRID_KEY);
-//
-//        if (dyeingKeyIt != current->getRequestStatus().end() &&
-//            ServantHelperManager::getInstance()->isDyeingReq(dyeingKeyIt->second, current->getServantName(), current->getFuncName()))
-//        {
-//            TLOGTARS("[TARS] dyeing servant got a dyeing req, key:" << dyeingKeyIt->second << endl);
-//
-//            dyeingKey = dyeingKeyIt->second;
-//
-//            return true;
-//        }
-//    }
+
 
     return false;
 }
@@ -845,14 +831,14 @@ void ServantHandle::handleTarsProtocol(const TarsCurrentPtr &current)
 
     //处理cookie
     map<string, string> cookie;
-    TarsCookieOp cookieOp;
+    CookieOp cookieOp;
     if (processCookie(current, cookie))
     {
         cookieOp.setCookie(cookie);
         current->setCookie(cookie);
     }
 
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
     //处理tracking信息
     processTracking(current);
 #endif
@@ -861,7 +847,7 @@ void ServantHandle::handleTarsProtocol(const TarsCurrentPtr &current)
     if (sit == _servants.end())
     {
         current->sendResponse(TARSSERVERNOSERVANTERR);
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
         finishTracking(TARSSERVERNOSERVANTERR, current);
 #endif
         return;
@@ -913,9 +899,9 @@ void ServantHandle::handleTarsProtocol(const TarsCurrentPtr &current)
     //单向调用或者业务不需要同步返回
     if (current->isResponse())
     {
-        current->sendResponse(ret, buffer, TarsCurrent::TARS_STATUS(), sResultDesc);
+        current->sendResponse(ret, buffer, Current::TARS_STATUS(), sResultDesc);
     }
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
     finishTracking(ret, current);
 #endif
 }
@@ -947,7 +933,7 @@ void ServantHandle::handleNoTarsProtocol(const TarsCurrentPtr &current)
         TLOGERROR("[TARS]ServantHandle::handleNoTarsProtocol unknown error" << endl);
     }
 
-    if (current->isResponse())
+    if (current->isResponse() && !buffer.empty())
     {
         current->sendResponse((const char*)buffer.data(), buffer.size());
     }

+ 251 - 55
servant/libservant/ServantProxy.cpp

@@ -19,7 +19,7 @@
 #include "servant/StatReport.h"
 #include "servant/Application.h"
 #include "servant/BaseF.h"
-#include "servant/TarsLogger.h"
+#include "servant/RemoteLogger.h"
 #include "servant/Message.h"
 #include "servant/EndpointManager.h"
 
@@ -49,7 +49,7 @@ SeqManager::SeqManager(uint16_t iNum)
     for(uint16_t i=0;i<(uint16_t)iNum;i++)
     {
         _p[i].free = true;
-        _p[i].next = i+1;
+        _p[i].next = i + 1;
     }
     _p[iNum-1].next = MAX_UNSIGN_SHORT;
     _num = iNum;
@@ -155,12 +155,20 @@ ServantProxyThreadData * ServantProxyThreadData::getData()
     return g_sp.get();
 }
 
-///////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////
+
 ServantProxyCallback::ServantProxyCallback()
 : _bNetThreadProcess(false)
 {
 }
 
+int ServantProxyCallback::dispatch(ReqMessagePtr msg)
+{
+	return onDispatch(msg);
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////
+
 int HttpServantProxyCallback::onDispatch(ReqMessagePtr msg)
 {
     if (msg->response->iRet != TARSSERVERSUCCESS)
@@ -178,12 +186,23 @@ HttpServantProxyCallback::HttpServantProxyCallback(const HttpCallbackPtr& cb) :
 
 int HttpServantProxyCallback::onDispatchException(const RequestPacket &request, const ResponsePacket &response)
 {
-   return _httpCb->onHttpResponseException(request.context, response.iRet);
+	if(_httpCb)
+        return _httpCb->onHttpResponseException(response.iRet);
+
+	return 0;
 }
 
 int HttpServantProxyCallback::onDispatchResponse(const RequestPacket &request, const ResponsePacket &response)
 {
-    return _httpCb->onHttpResponse(request.context, response.status, response.sBuffer);
+	assert(response.sBuffer.size() == sizeof(shared_ptr<TC_HttpResponse>));
+
+	shared_ptr<TC_HttpResponse> rsp = *(shared_ptr<TC_HttpResponse>*)(response.sBuffer.data());
+
+
+	if(_httpCb)
+	    return _httpCb->onHttpResponse(rsp);
+
+	return 0;
 }
 
 ///////////////////////////////////////////////////////////////
@@ -212,7 +231,7 @@ void coroWhenAll(const CoroParallelBasePtr &ptr)
     for(size_t i = 0; i < vMsg.size(); ++i)
     {
         ReqMessagePtr msgPtr = vMsg[i];
-        vMsg[i]->callback->onDispatch(msgPtr);
+        vMsg[i]->callback->dispatch(msgPtr);
     }
 }
 
@@ -233,7 +252,7 @@ string ServantProxy::STATUS_SETNAME_VALUE = "STATUS_SETNAME_VALUE";
 
 string ServantProxy::STATUS_TRACK_KEY     = "STATUS_TRACK_KEY";
 
-string ServantProxy::STATUS_COOKIE        = "STATUS_COOKIE";
+// string ServantProxy::STATUS_COOKIE        = "STATUS_COOKIE";
 
 
 ////////////////////////////////////
@@ -291,6 +310,16 @@ string ServantProxy::tars_name() const
     return "NULL";
 }
 
+string ServantProxy::tars_full_name() const
+{
+	if (_objectProxyNum >= 1 && (*_objectProxy != NULL))
+	{
+		return (*_objectProxy)->name() +"#" + (*_objectProxy)->hash() + "@" + (*_objectProxy)->address();
+	}
+	return "NULL";
+}
+
+
 void ServantProxy::tars_reconnect(int second)
 {
 	if (_objectProxyNum >= 1 && (*_objectProxy != NULL))
@@ -356,17 +385,68 @@ int ServantProxy::tars_async_timeout() const
     return _asyncTimeout;
 }
 
+void ServantProxy::tars_connection_serial(int connectionSerial)
+{
+	assert(!_rootPrx);
+	_connectionSerial = connectionSerial;
+}
+
+int ServantProxy::tars_connection_serial() const
+{
+	if(_rootPrx) {
+		return _rootPrx->tars_connection_serial();
+	}
+
+	return _connectionSerial;
+}
 
-void ServantProxy::tars_set_protocol(const ProxyProtocol& protocol)
+void ServantProxy::tars_set_protocol(SERVANT_PROTOCOL protocol, int connectionSerial)
+{
+	ProxyProtocol proto;
+
+	switch(protocol)
+	{
+		case PROTOCOL_HTTP1:
+			proto.requestFunc   = ProxyProtocol::http1Request;
+			proto.responseFunc  = ProxyProtocol::http1Response;
+
+			if(connectionSerial <= 0)
+				connectionSerial = DEFAULT_CONNECTION_SERIAL;
+			break;
+#if TARS_HTTP2
+		case PROTOCOL_HTTP2:
+			proto.requestFunc   = ProxyProtocol::http2Request;
+			proto.responseFunc  = ProxyProtocol::http2Response;
+            connectionSerial    = 0;
+			break;
+#endif
+		case PROTOCOL_TARS:
+		default:
+			proto.requestFunc   = ProxyProtocol::tarsRequest;
+			proto.responseFunc  = ProxyProtocol::tarsResponse;
+			break;
+	}
+	tars_set_protocol(proto, connectionSerial);
+}
+
+void ServantProxy::tars_set_protocol(const ProxyProtocol& protocol, int connectionSerial)
 {
     TC_LockT<TC_ThreadMutex> lock(*this);
 
-    for(size_t i = 0;i < _objectProxyNum; ++i)
+    for (size_t i = 0; i < _objectProxyNum; ++i)
     {
         (*(_objectProxy + i))->setProxyProtocol(protocol);
     }
+
+	_connectionSerial = connectionSerial;
 }
 
+ProxyProtocol ServantProxy::tars_get_protocol()
+{
+	TC_LockT<TC_ThreadMutex> lock(*this);
+
+	return (*(_objectProxy + 0))->getProxyProtocol();
+}
 
 void ServantProxy::tars_set_sockopt(int level, int optname, const void * optval, SOCKET_LEN_TYPE optlen)
 {
@@ -518,7 +598,7 @@ void ServantProxy::tars_set_push_callback(const ServantProxyCallbackPtr & cb)
 //            }
 //            else
 //            {
-//                TLOGERROR("[TAF][ServantProxy::invoke_async use coroutine's callback not set CoroParallelBasePtr]" << endl);
+//                TLOGERROR("[TARS][ServantProxy::invoke_async use coroutine's callback not set CoroParallelBasePtr]" << endl);
 //                delete msg;
 //                msg = NULL;
 //                throw TarsUseCoroException("ServantProxy::invoke_async use coroutine's callback not set CoroParallelBasePtr");
@@ -526,7 +606,7 @@ void ServantProxy::tars_set_push_callback(const ServantProxyCallbackPtr & cb)
 //        }
 //        else
 //        {
-//            TLOGERROR("[TAF][ServantProxy::invoke coroutine mode invoke not open]" << endl);
+//            TLOGERROR("[TARS][ServantProxy::invoke coroutine mode invoke not open]" << endl);
 //            delete msg;
 //            msg = NULL;
 //            throw TarsUseCoroException("coroutine mode invoke not open");
@@ -537,7 +617,7 @@ void ServantProxy::tars_set_push_callback(const ServantProxyCallbackPtr & cb)
 //	bool bEmpty;
 //	if (!pReqQ->push_back(msg, bEmpty))
 //	{
-//		TLOGERROR("[TAF][ServantProxy::invoke_async msgQueue push_back error num:" << pSptd->_netSeq << "]" << endl);
+//		TLOGERROR("[TARS][ServantProxy::invoke_async msgQueue push_back error num:" << pSptd->_netSeq << "]" << endl);
 //		msg->pObjectProxy->getCommunicatorEpoll()->notify(pSptd->_reqQNo, pReqQ);
 //		delete msg;
 //		throw TarsClientQueueException("client queue full");
@@ -575,7 +655,7 @@ void ServantProxy::invoke(ReqMessage * msg, bool bCoroAsync)
 
     msg->cookie       = pSptd->_cookie;
 
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
     msg->trackInfoMap = pSptd->_trackInfoMap;
 #endif
 
@@ -784,8 +864,7 @@ void ServantProxy::tars_invoke_async(char  cPacketType,
     checkDye(msg->request);
 
     checkCookie(msg->request);
-
-    invoke(msg, bCoro);
+	servant_invoke(msg, bCoro);
 }
 
 shared_ptr<ResponsePacket> ServantProxy::tars_invoke(char  cPacketType,
@@ -842,13 +921,13 @@ void ServantProxy::rpc_call(uint32_t iRequestId,
 
     msg->init(ReqMessage::SYNC_CALL);
     msg->bFromRpc = true;
-	msg->request.sFuncName = sFuncName;
-
+	msg->request.sServantName = (*_objectProxy)->name();
+    msg->request.sFuncName = sFuncName;
     msg->request.iRequestId  = iRequestId;
 
     msg->request.sBuffer.assign(buff, buff + len);
 
-    invoke(msg);
+	servant_invoke(msg, false);
 
     rsp = *msg->response.get();
 
@@ -866,66 +945,183 @@ void ServantProxy::rpc_call_async(uint32_t iRequestId,
     ReqMessage * msg = new ReqMessage();
 
     msg->init(callback?ReqMessage::ASYNC_CALL:ReqMessage::ONE_WAY);
-	msg->request.sFuncName = sFuncName;
+
     msg->bFromRpc = true;
     msg->callback = callback;
+	msg->request.sServantName = (*_objectProxy)->name();
+	msg->request.sFuncName = sFuncName;
 
     msg->request.iRequestId = iRequestId;
 
     msg->request.sBuffer.assign(buff, buff + len);
 
-    invoke(msg, bCoro);
+	servant_invoke(msg, bCoro);
 }
 
-void ServantProxy::http_call(const std::string& method,
-                              const std::string& uri,
-                              const std::map<std::string, std::string>& headers,
-                              const std::string& body,
-                              std::map<std::string, std::string>& rheaders,
-                              std::string& rbody)
+ServantPrx ServantProxy::getServantPrx(ReqMessage *msg)
 {
-    ReqMessage* msg = new ReqMessage();
+	if(_connectionSerial <= 0)
+		return this;
 
-    msg->init(ReqMessage::SYNC_CALL);
+	if(_servantId == 0)
+	{
+		std::lock_guard<std::mutex> m(_servantMutex);
+
+		if(_servantId == 0)
+		{
+			if(_servantList.empty())
+			{
+				for(int i = 0; i < _connectionSerial; ++i)
+				{
+					string obj = tars_name() + "#" + TC_Common::tostr(i);
+					if (!(*_objectProxy)->address().empty())
+					{
+						obj += "@" + (*_objectProxy)->address();
+					}
+
+					ServantPrx prx = _communicator->stringToProxy<ServantPrx>(obj);
+					prx->tars_set_protocol(tars_get_protocol());
+					prx->_rootPrx = this;
+
+					_servantList.push_back(prx);
+				}
+			}
+			++_servantId;
+		}
+	}
 
-    msg->bFromRpc = true;
-    msg->request.sServantName = uri;
-    msg->request.sFuncName = method;
-    // 使用下面两个字段保存头部和包体
-    msg->request.context = headers;
+	return _servantList[(_servantId++) % _servantList.size()];
+}
 
-    msg->request.sBuffer.assign(body.begin(), body.end());
+void ServantProxy::onNotifyEndpoints(const set<EndpointInfo> & active,const set<EndpointInfo> & inactive)
+{
+	if(_rootPrx)
+	{
+		for (size_t i = 0; i < _rootPrx->_servantList.size(); i++)
+		{
+			_rootPrx->_servantList[i]->onNotifyEndpoints(active, inactive);
+		}
+	}
+	else
+	{
+		for (size_t i = 0; i < _objectProxyNum; ++i)
+		{
+			_objectProxy[i]->getEndpointManager()->updateEndpoints(active, inactive);
+		}
+	}
+}
 
-    invoke(msg);
+void ServantProxy::onSetInactive(const EndpointInfo& ep)
+{
+	if(!_rootPrx)
+		return;
 
-    rheaders.swap(msg->response->status);
-    rbody.assign(msg->response->sBuffer.begin(), msg->response->sBuffer.end());
+	for (size_t i = 0; i < _rootPrx->_servantList.size(); i++)
+	{
+		ServantPrx &prx = _rootPrx->_servantList[i];
 
-    delete msg;
-    msg = NULL;
+		for (size_t i = 0; i < prx->_objectProxyNum; ++i)
+		{
+			prx->_objectProxy[i]->onSetInactive(ep);
+		}
+	}
 }
 
-void ServantProxy::http_call_async(const std::string& method,
-                                   const std::string& uri,
-                                   const std::map<std::string, std::string>& headers,
-                                    const std::string& body,
-                                    const HttpCallbackPtr &cb)
+int ServantProxy::servant_invoke(ReqMessage *msg, bool bCoroAsync)
 {
-    ReqMessage * msg = new ReqMessage();
+	ServantPrx prx = getServantPrx(msg);
 
-    msg->init(ReqMessage::ASYNC_CALL);
+	if(msg->callback)
+	{
+		msg->callback->setServantPrx(prx);
+	}
 
-    msg->bFromRpc = true;
-	msg->request.sServantName = uri;
-	msg->request.sFuncName = method;
-    // 使用下面两个字段保存头部和包体
-    msg->request.context = headers;
-    msg->request.sBuffer.assign(body.begin(), body.end());
+	prx->invoke(msg, bCoroAsync);
 
-    ServantProxyCallbackPtr callback = new HttpServantProxyCallback(cb);
-    msg->callback = callback;
+	return 0;
+}
 
-    invoke(msg);
+void ServantProxy::http_call(const string &funcName, shared_ptr<TC_HttpRequest> &request, shared_ptr<TC_HttpResponse> &response)
+{
+	// if(_connectionSerial <= 0) {
+	// 	_connectionSerial = DEFAULT_CONNECTION_SERIAL;
+	// }
+
+	ReqMessage* msg = new ReqMessage();
+
+	msg->init(ReqMessage::SYNC_CALL);
+
+	msg->bFromRpc = true;
+
+	msg->request.sServantName = (*_objectProxy)->name();
+	msg->request.sFuncName = funcName;
+
+	msg->request.sBuffer.resize(sizeof(shared_ptr<TC_HttpRequest>));
+
+	msg->deconstructor = [msg] {
+		shared_ptr<TC_HttpRequest> & data = *(shared_ptr<TC_HttpRequest> *) (msg->request.sBuffer.data());
+		data.reset();
+
+		if(!msg->response->sBuffer.empty())
+		{
+			shared_ptr<TC_HttpResponse> & rsp = *(shared_ptr<TC_HttpResponse> *) (msg->response->sBuffer.data());
+			//主动reset一次
+			rsp.reset();
+
+			msg->response->sBuffer.clear();
+		}
+	};
+
+	shared_ptr<TC_HttpRequest> & data = *(shared_ptr<TC_HttpRequest> *) (msg->request.sBuffer.data());
+
+	data = request;
+
+	servant_invoke(msg, false);
+
+	response = *(shared_ptr<TC_HttpResponse>*)(msg->response->sBuffer.data());
+
+	delete msg;
+	msg = NULL;
+}
+
+void ServantProxy::http_call_async(const string &funcName, shared_ptr<TC_HttpRequest> &request, const HttpCallbackPtr &cb, bool bCoro)
+{
+	// if(_connectionSerial <= 0) {
+	// 	_connectionSerial = DEFAULT_CONNECTION_SERIAL;
+	// }
+
+	ReqMessage* msg = new ReqMessage();
+
+	msg->init(ReqMessage::ASYNC_CALL);
+
+	msg->bFromRpc = true;
+
+	msg->request.sServantName = (*_objectProxy)->name();
+	msg->request.sFuncName = funcName;
+
+	msg->request.sBuffer.resize(sizeof(shared_ptr<TC_HttpRequest>));
+
+	msg->deconstructor = [msg] {
+		shared_ptr<TC_HttpRequest> & data = *(shared_ptr<TC_HttpRequest> *) (msg->request.sBuffer.data());
+		data.reset();
+
+		if(!msg->response->sBuffer.empty())
+		{
+			shared_ptr<TC_HttpResponse> & rsp = *(shared_ptr<TC_HttpResponse> *) (msg->response->sBuffer.data());
+			//主动reset一次
+			rsp.reset();
+
+			msg->response->sBuffer.clear();
+		}
+	};
+
+	*(shared_ptr<TC_HttpRequest>*)(msg->request.sBuffer.data()) = request;
+
+	ServantProxyCallbackPtr callback = new HttpServantProxyCallback(cb);
+
+	msg->callback = callback;
+
+	servant_invoke(msg, bCoro);
 }
 
 //选取一个网络线程对应的信息

+ 1 - 1
servant/libservant/ServantProxyFactory.cpp

@@ -15,7 +15,7 @@
  */
 
 #include "servant/ServantProxyFactory.h"
-#include "servant/TarsLogger.h"
+#include "servant/RemoteLogger.h"
 
 namespace tars
 {

+ 3 - 3
servant/libservant/StatReport.cpp

@@ -17,7 +17,7 @@
 #include "servant/StatReport.h"
 #include "util/tc_common.h"
 #include "util/tc_timeprovider.h"
-#include "servant/TarsLogger.h"
+#include "servant/RemoteLogger.h"
 #include "servant/Communicator.h"
 #include "servant/Application.h"
 #include <iostream>
@@ -485,7 +485,7 @@ int StatReport::reportMicMsg(MapStatMicMsg& msg,bool bFromClient)
            }
 
            mTemp[head] = it->second;
-           if(LOG->isNeedLog(TarsRollLogger::INFO_LOG))
+           if(LOG->isNeedLog(LocalRollLogger::INFO_LOG))
            {
                ostringstream os;
                os.str("");
@@ -607,7 +607,7 @@ int StatReport::reportPropMsg()
                    }
                }
                mStatMsg[head]  = body;
-               if(LOG->isNeedLog(TarsRollLogger::INFO_LOG))
+               if(LOG->isNeedLog(LocalRollLogger::INFO_LOG))
                {
                       ostringstream os;
                    os.str("");

+ 0 - 213
servant/libservant/TarsConfig.cpp

@@ -1,213 +0,0 @@
-/**
- * Tencent is pleased to support the open source community by making Tars available.
- *
- * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
- *
- * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 
- * in compliance with the License. You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- *
- * Unless required by applicable law or agreed to in writing, software distributed 
- * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
- * specific language governing permissions and limitations under the License.
- */
-
-#include "servant/TarsConfig.h"
-#include "util/tc_file.h"
-#include "servant/Communicator.h"
-#include "servant/TarsNotify.h"
-#include "servant/Application.h"
-#include <fstream>
-
-namespace tars
-{
-
-int TarsRemoteConfig::setConfigInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string& basePath,const string& setdivision, int maxBakNum)
-{
-    _comm           = comm;
-    if(!obj.empty())
-    {
-        _configPrx      = _comm->stringToProxy<ConfigPrx>(obj);
-    }
-    _app           = app;
-    _serverName    = serverName;
-    _basePath      = basePath;
-    _maxBakNum     = maxBakNum;
-    _setdivision   = setdivision;
-    return 0;
-}
-
-bool TarsRemoteConfig::addConfig(const string & sFileName, string &buffer, bool bAppConfigOnly)
-{
-    TC_LockT<TC_ThreadMutex> lock(_mutex);
-
-    try
-    {
-        string sFullFileName = _basePath + FILE_SEP + sFileName;
-
-        string newFile = getRemoteFile(sFileName, bAppConfigOnly);
-
-        if (newFile.empty() || !TC_File::isFileExist(newFile))//拉取不到配置中心的配置文件
-        {
-            if(!TC_File::isFileExist(newFile)) //获取本地配置成功,返回成功,但需要告警一下。
-            {
-                buffer = "[fail] get remote config:" + sFileName + "fail,use the local config.";
-
-                return true;
-            }
-            throw runtime_error("access file error:" + newFile);
-        }
-
-        if (TC_File::load2str(newFile) != TC_File::load2str(sFullFileName))
-        {
-            for (int i = _maxBakNum - 1; i >= 1; --i)
-            {
-                if (TC_File::isFileExist(index2file(sFullFileName, i)))
-                {
-                    localRename(index2file(sFullFileName, i), index2file(sFullFileName, i+1));
-                }
-            }
-
-            if (TC_File::isFileExist(sFullFileName))
-            {
-                localRename(sFullFileName, index2file(sFullFileName, 1));
-            }
-        }
-
-        localRename(newFile, sFullFileName);
-
-		assert(TC_File::isFileExist(sFullFileName));
-        //assert(!access(sFullFileName.c_str(), R_OK));
-
-        buffer = "[succ] get remote config:" + sFileName;
-
-        return true;
-    }
-    catch (std::exception& e)
-    {
-        buffer = "[fail] get remote config '" + sFileName + "' error:" + string(e.what());
-    }
-    catch (...)
-    {
-        buffer = "[fail] get remote config '" + sFileName + "' unknown error";
-    }
-
-    return false;
-}
-
-string TarsRemoteConfig::getRemoteFile(const string &sFileName, bool bAppConfigOnly)
-{
-    if (_configPrx)
-    {
-       string stream;
-       int ret = -1;
-       for(int i = 0; i < 2;i++)
-       {
-           try
-           {
-                if(_setdivision.empty())
-                {
-                    ret = _configPrx->loadConfig(_app, (bAppConfigOnly ? "" : _serverName), sFileName, stream, ServerConfig::Context);
-                }
-                else
-                {
-                    struct ConfigInfo confInfo;
-                    confInfo.appname     = _app;
-                    confInfo.servername  = (bAppConfigOnly ? "" : _serverName);
-                    confInfo.filename    = sFileName;
-                    confInfo.bAppOnly    = bAppConfigOnly;
-                    confInfo.setdivision = _setdivision;
-                    ret = _configPrx->loadConfigByInfo(confInfo,stream, ServerConfig::Context);
-                }
-                
-                break;
-           }catch(std::exception& e){
-            //
-           }catch (...){
-            //
-           }
-       }
-       
-       if (ret != 0 || stream.empty())
-       {
-           throw runtime_error("remote config file is empty:" + sFileName);
-       }
-
-
-        string newFile = _basePath + "/" + sFileName + "." + TC_Common::tostr(time(NULL));
-
-        std::ofstream out(newFile.c_str());
-        
-        string result;
-        if (out)
-        {
-            out << stream;//如果硬盘满了,是否能写入成功需要进行判断。
-            out.flush();
-            if(out.bad()) 
-            {
-                out.close();
-                result = "[fail] copy stream to disk error." ;
-                TarsRemoteNotify::getInstance()->report(result);
-                return "";
-            }
-            else
-            {
-                out.close();
-                return newFile;
-            }
-        }
-    }
-    return "";
-}
-
-string TarsRemoteConfig::index2file(const string & sFullFileName, int index)
-{
-    return   sFullFileName + "." + TC_Common::tostr(index) + ".bak";
-}
-
-void TarsRemoteConfig::localRename(const string& oldFile, const string& newFile)
-{
-#if TARGET_PLATFORM_WINDOWS
-	//by goodenpei,windows下面先remove后rename,否则rename会失败
-	if (TC_File::isFileExist(oldFile) && TC_File::isFileExist(newFile))
-	{
-		::remove(newFile.c_str());
-	}
-#endif
-    if (::rename(oldFile.c_str(), newFile.c_str()) != 0)
-    {
-        throw runtime_error("rename file error:" + oldFile + "->" + newFile);
-    }
-}
-
-string TarsRemoteConfig::recoverSysConfig(const string & sFullFileName)
-{
-    try
-    {
-        for (int i = 1; i <= _maxBakNum; ++i)
-        {
-            if (TC_File::isFileExist(index2file(sFullFileName, i)))
-            {
-                localRename(index2file(sFullFileName, i), sFullFileName);
-
-                return "[succ] recover file:" + index2file(sFullFileName, i);
-            }
-        }
-    }
-    catch (std::exception& e)
-    {
-        return "[fail] recover config error:" + string(e.what());
-    }
-    catch (...)
-    {
-        return "[fail] recover config error";
-    }
-
-    return "[fail] no backup file.";
-}
-
-}
-
-

+ 0 - 437
servant/libservant/TarsCurrent.cpp

@@ -1,437 +0,0 @@
-/**
- * Tencent is pleased to support the open source community by making Tars available.
- *
- * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
- *
- * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 
- * in compliance with the License. You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- *
- * Unless required by applicable law or agreed to in writing, software distributed 
- * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
- * specific language governing permissions and limitations under the License.
- */
-
-#include "servant/TarsCurrent.h"
-#include "servant/ServantHandle.h"
-#include "servant/BaseF.h"
-#include "servant/Application.h"
-#include "tup/tup.h"
-#include <cerrno>
-
-namespace tars
-{
-//////////////////////////////////////////////////////////////////
-TarsCurrent::TarsCurrent(ServantHandle *pServantHandle)
-: _servantHandle(pServantHandle)
-// , _bindAdapter(NULL)
-// , _uid(0)
-// , _ip("NULL")
-// , _port(0)
-// , _fd(-1)
-, _response(true)
-// , _begintime(0)
-, _ret(0)
-, _reportStat(true)
-// , _closeType(-1)
-{
-}
-
-TarsCurrent::~TarsCurrent()
-{
-    //TUP调用或单向调用,从服务端上报调用信息
-    if(_reportStat)
-    {
-        if(_request.iVersion == TUPVERSION )
-        {
-            reportToStat("tup_client");
-        }
-        else if(_request.cPacketType == TARSONEWAY)
-        {
-            reportToStat("one_way_client");
-        }
-        else if(!_data->adapter()->isTarsProtocol() && ServerConfig::ReportFlow)
-        {
-            //非tars客户端 从服务端上报调用信息
-            reportToStat("not_tars_client");
-        }
-    }
-}
-
-const string &TarsCurrent::getHostName() const
-{
-	auto it = _request.context.find("node_name");
-	if(it != _request.context.end())
-	{
-		return it->second;
-	}
-	return _data->ip();
-
-}
-
-const string &TarsCurrent::getIp() const
-{
-	return _data->ip();
-}
-
-int TarsCurrent::getPort() const
-{
-    return _data->port();
-    // return _port;
-}
-
-uint32_t TarsCurrent::getUId() const
-{
-    return _data->uid();
-    // return _uid;
-}
-
-string TarsCurrent::getServantName() const
-{
-    return _request.sServantName;
-}
-
-short TarsCurrent::getRequestVersion() const
-{
-    return _request.iVersion;
-}
-
-map<string, string>& TarsCurrent::getContext()
-{
-    return _request.context;
-}
-
-const map<string, string>& TarsCurrent::getRequestStatus() const
-{
-    return _request.status;
-}
-
-string TarsCurrent::getFuncName() const
-{
-    return _request.sFuncName;
-}
-
-uint32_t TarsCurrent::getRequestId() const
-{
-    return _request.iRequestId;
-}
-
-char TarsCurrent::getPacketType() const
-{
-    return _request.cPacketType;
-}
-
-tars::Int32 TarsCurrent::getMessageType() const
-{
-    return _request.iMessageType;
-}
-
-struct timeval TarsCurrent::getRecvTime() const
-{
-    timeval tm;
-    tm.tv_sec  = _data->recvTimeStamp()/1000;
-    tm.tv_usec = (_data->recvTimeStamp()%1000)*1000;
-
-    return tm;
-}
-
-void TarsCurrent::setReportStat(bool bReport)
-{
-    _reportStat = bReport;
-}
-
-const vector<char>& TarsCurrent::getRequestBuffer() const
-{
-	if (_data->adapter()->isTarsProtocol())
-	{
-		return _request.sBuffer;
-	}
-	else
-	{
-		return _data->buffer();
-	}
-
-    // return _request.sBuffer;
-}
-
-bool TarsCurrent::isResponse() const
-{
-    return _response;
-}
-
-void TarsCurrent::setCloseType(int type)
-{
-    _data->setCloseType(type);
-}
-
-int TarsCurrent::getCloseType() const
-{
-    return _data->closeType();
-}
-
-void TarsCurrent::initialize(const shared_ptr<TC_EpollServer::RecvContext> &data)
-// void TarsCurrent::initialize(const TC_EpollServer::tagRecvData &stRecvData)
-{
-	_data = data;
-
-    _request.sServantName = ServantHelperManager::getInstance()->getAdapterServant(_data->adapter()->getName());
-
-    if (_data->adapter()->isTarsProtocol())
-    {
-        initialize(_data->buffer());
-    }
-    // initialize(stRecvData, begintime);
-}
-
-
-void TarsCurrent::initializeClose(const shared_ptr<TC_EpollServer::RecvContext> &data)
-{
-	_data = data;
-
-    _request.sServantName = ServantHelperManager::getInstance()->getAdapterServant(_data->adapter()->getName());
-
-}
-
-void TarsCurrent::initialize(const vector<char>& sRecvBuffer)
-{
-    TarsInputStream<BufferReader> is;
-
-    is.setBuffer(sRecvBuffer.data(), sRecvBuffer.size());
-
-    _request.readFrom(is);
-}
-
-// void TarsCurrent::initialize(const TC_EpollServer::tagRecvData &stRecvData, int64_t beginTime)
-// {
-//      _ip         = stRecvData.ip;
-
-//     _port        = stRecvData.port;
-
-//     _uid         = stRecvData.uid;
-
-//     _fd          = stRecvData.fd;
-
-//     _bindAdapter = stRecvData.adapter.get();
-
-//     _begintime   = beginTime;
-
-//     _request.sServantName = ServantHelperManager::getInstance()->getAdapterServant(stRecvData.adapter->getName());
-
-//     if (_bindAdapter->isTarsProtocol())
-//     {
-//         initialize(stRecvData.buffer);
-//     }
-//     else
-//     {
-//         _request.sBuffer.reserve(stRecvData.buffer.length());
-
-//         _request.sBuffer.resize(stRecvData.buffer.length());
-
-//         ::memcpy(&_request.sBuffer[0], stRecvData.buffer.c_str(), stRecvData.buffer.length());
-//     }
-// }
-
-// void TarsCurrent::initializeClose(const TC_EpollServer::tagRecvData &stRecvData)
-// {
-//     _ip   = stRecvData.ip;
-
-//     _port = stRecvData.port;
-
-//     _uid  = stRecvData.uid;
-
-//     _fd   = stRecvData.fd;
-
-//     _bindAdapter = stRecvData.adapter.get();
-
-//     _request.sServantName = ServantHelperManager::getInstance()->getAdapterServant(stRecvData.adapter->getName());
-
-//     _begintime = TNOWMS;
-// }
-
-// void TarsCurrent::initialize(const string &sRecvBuffer)
-// {
-//     TarsInputStream<BufferReader> is;
-
-//     is.setBuffer(sRecvBuffer.c_str(), sRecvBuffer.length());
-
-//     _request.readFrom(is);
-// }
-
-void TarsCurrent::sendResponse(const char* buff, uint32_t len)
-{
-    // _servantHandle->sendResponse(_uid, string(buff, len), _ip, _port, _fd);
-	shared_ptr<TC_EpollServer::SendContext> send = _data->createSendContext();
-	send->buffer()->assign(buff, len);
-	_servantHandle->sendResponse(send);
-}
-
-
-void TarsCurrent::sendResponse(int iRet, const vector<char> &buff)
-{
-	//单向调用不需要返回
-	if (_request.cPacketType == TARSONEWAY)
-	{
-		return;
-	}
-
-	// ResponsePacket response;
-	// response.sBuffer = buff;
-	sendResponse(iRet, buff, TARS_STATUS(), "");
-}
-
-void TarsCurrent::sendResponse(int iRet)
-{
-	// ResponsePacket response;
-	sendResponse(iRet, vector<char>(), TARS_STATUS(), "");
-}
-
-void TarsCurrent::sendResponse(int iRet, tars::TarsOutputStream<tars::BufferWriterVector>& os)
-{
-	// ResponsePacket response;
-	// os.swap(response.sBuffer);
-	sendResponse(iRet, os.getByteBuffer(), TARS_STATUS(), "");
-}
-
-void TarsCurrent::sendResponse(int iRet, tup::UniAttribute<tars::BufferWriterVector, tars::BufferReader>& attr)
-{
-	ResponsePacket response;
-	attr.encode(response.sBuffer);
-	sendResponse(iRet, response.sBuffer, TARS_STATUS(), "");
-}
-
-void TarsCurrent::sendResponse(int iRet, const vector<char> &buffer,  const map<string, string>& status, const string & sResultDesc)
-{
-    _ret = iRet;
-
-    //单向调用不需要返回
-    if (_request.cPacketType == TARSONEWAY)
-    {
-        return;
-    }
-
-	shared_ptr<TC_EpollServer::SendContext> send = _data->createSendContext();
-
-	tars::Int32 iHeaderLen = 0;
-
-	TarsOutputStream<BufferWriterVector> os;
-
-	//先预留4个字节长度
-	os.writeBuf((const char *)&iHeaderLen, sizeof(iHeaderLen));
-
-    if (_request.iVersion != TUPVERSION)
-    {
-        ResponsePacket response;
-
-        response.iRequestId     = _request.iRequestId;
-        response.iMessageType   = _request.iMessageType;
-		response.cPacketType    = TARSNORMAL;
-
-        response.iVersion       = _request.iVersion;
-        response.status         = status;
-        response.sBuffer        = std::move(buffer);
-        response.sResultDesc    = sResultDesc;
-        response.context        = _responseContext;
-        response.iRet           = iRet;
-
-        TLOGTARS("[TARS]TarsCurrent::sendResponse :"
-                   << response.iMessageType << "|"
-                   << _request.sServantName << "|"
-                   << _request.sFuncName << "|"
-                   << response.iRequestId << endl);
-
-        response.writeTo(os);
-    }
-    else
-    {
-        //tup回应包用请求包的结构(这里和新版本TAF是有区别的)
-        RequestPacket response;
-
-        response.iRequestId     = _request.iRequestId;
-        response.iMessageType   = _request.iMessageType;
-		response.cPacketType    = TARSNORMAL;
-
-        response.iVersion       = _request.iVersion;
-        response.status         = status;
-        response.context        = _responseContext;
-        response.sBuffer        = std::move(buffer);
-        response.sServantName   = _request.sServantName;
-        response.sFuncName      = _request.sFuncName;
-
-        //异常的情况下buffer可能为空,要保证有一个空UniAttribute的编码内容
-        if(response.sBuffer.size() == 0)
-        {
-            tup::UniAttribute<> tarsAttr;
-            tarsAttr.setVersion(_request.iVersion);
-            tarsAttr.encode(response.sBuffer);
-        }
-        //iRet为0时,不记录在status里面,节省空间
-        if(iRet != 0)
-        {
-            response.status[ServantProxy::STATUS_RESULT_CODE] = TC_Common::tostr(iRet);
-        }
-        //sResultDesc为空时,不记录在status里面,节省空间
-        if(!sResultDesc.empty())
-        {
-            response.status[ServantProxy::STATUS_RESULT_DESC] = sResultDesc;
-        }
-
-        TLOGTARS("[TARS]TarsCurrent::sendResponse :"
-                   << response.iMessageType << "|"
-                   << _request.sServantName << "|"
-                   << _request.sFuncName << "|"
-                   << response.iRequestId << endl);
-
-        response.writeTo(os);
-    }
-
-	assert(os.getLength() >= 4);
-
-	iHeaderLen = htonl((int)(os.getLength()));
-
-	memcpy(os.getByteBuffer().data(), (const char *)&iHeaderLen, sizeof(iHeaderLen));
-
-	send->buffer()->swap(os.getByteBuffer());
-
-	_servantHandle->sendResponse(send);
-
-}
-
-
-void TarsCurrent::close()
-{
-    if (_servantHandle)
-    {
-        _servantHandle->close(_data);
-    }
-}
-
-ServantHandle* TarsCurrent::getServantHandle()
-{
-    return _servantHandle;
-}
-
-TC_EpollServer::BindAdapter* TarsCurrent::getBindAdapter()
-{
-    return _data->adapter().get();
-}
-
-void TarsCurrent::reportToStat(const string& sObj)
-{
-    StatReport* stat = Application::getCommunicator()->getStatReport();
-
-    if(stat && stat->getStatPrx())
-    {
-        // int64_t endtime = TNOWMS;
-        // int sptime = endtime - _begintime;
-
-        //被调上报自己的set信息,set信息在setReportInfo设置
-        // stat->report(sObj, "" , _request.sServantName, _data->ip(), 0, _request.sFuncName, (StatReport::StatResult)_ret, TNOWMS - _data->recvTimeStamp(), 0);
-
-        stat->report(sObj, "", _request.sFuncName, _data->ip(), 0, (StatReport::StatResult)_ret, TNOWMS - _data->recvTimeStamp(), 0, false);
-    }
-}
-
-////////////////////////////////////////////////////////////////////////////
-}

+ 0 - 723
servant/libservant/TarsLogger.cpp

@@ -1,723 +0,0 @@
-/**
- * Tencent is pleased to support the open source community by making Tars available.
- *
- * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
- *
- * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 
- * in compliance with the License. You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- *
- * Unless required by applicable law or agreed to in writing, software distributed 
- * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
- * specific language governing permissions and limitations under the License.
- */
-
-#include "servant/TarsLogger.h"
-#include "servant/Communicator.h"
-#include "servant/Application.h"
-
-namespace tars
-{
-
-int RollWriteT::_dyeingThread = 0;
-int TimeWriteT::_dyeing = 0;
-
-/////////////////////////////////////////////////////////////////////////////////////
-
-RollWriteT::RollWriteT():_dyeingRollLogger(NULL), _maxSize(10000), _maxNum(1), _logPrx(NULL)
-{
-}
-
-RollWriteT::~RollWriteT()
-{
-    if(_dyeingRollLogger)
-    {
-        delete _dyeingRollLogger;
-    }
-}
-
-void RollWriteT::operator()(ostream &of, const deque<pair<size_t, string> > &ds)
-{
-    vector<string> vRemoteDyeing;
-
-    deque<pair<size_t, string> >::const_iterator it = ds.begin();
-    while(it != ds.end())
-    {
-        of << it->second;
-
-        //染色线程id不存在
-        if(it->first != 0)
-        {
-            if(!_dyeingRollLogger)
-            {
-                string sDyeingDir = _logPath;
-                sDyeingDir += "/";
-                sDyeingDir += DYEING_DIR;
-                sDyeingDir += "/";
-
-                string sDyeingFile = sDyeingDir;
-                sDyeingFile += DYEING_FILE;
-
-                TC_File::makeDirRecursive(sDyeingDir);
-
-                //初始化染色循环日志
-                _dyeingRollLogger = new TC_RollLogger();
-
-                _dyeingRollLogger->init(sDyeingFile, _maxSize, _maxNum);
-                _dyeingRollLogger->modFlag(TC_DayLogger::HAS_TIME, false);
-                _dyeingRollLogger->modFlag(TC_DayLogger::HAS_TIME|TC_DayLogger::HAS_LEVEL|TC_DayLogger::HAS_PID, true);
-                _dyeingRollLogger->setLogLevel("DEBUG");
-            }
-
-            _dyeingRollLogger->roll(make_pair(it->first, _app + "." + _server + "|" + it->second ));
-
-            vRemoteDyeing.push_back(_app + "." + _server + "|" + it->second);
-        }
-
-        ++it;
-    }
-    of.flush();
-
-    if(_logPrx && vRemoteDyeing.size() > 0)
-    {
-        try
-        {
-            _logPrx->logger(DYEING_DIR, DYEING_FILE, "roll", "%Y%m%d", vRemoteDyeing, ServerConfig::Context);
-        }
-        catch(exception &ex)
-        {
-            TLOGERROR("[TARS] dyeing log write to remote log server error:" << ex.what() << endl);
-        }
-    }
-}
-
-void RollWriteT::setDyeingLogInfo(const string &sApp, const string &sServer, const string & sLogPath, int iMaxSize, int iMaxNum, const CommunicatorPtr &comm, const string &sLogObj)
-{
-    _app     = sApp;
-    _server  = sServer;
-    _logPath = sLogPath;
-    _maxSize = iMaxSize;
-    _maxNum  = iMaxNum;
-
-    if(comm && !sLogObj.empty())
-    {
-        _logPrx = comm->stringToProxy<LogPrx>(sLogObj);
-        //单独设置超时时间
-        _logPrx->tars_timeout(3000);
-    }
-}
-
-
-/////////////////////////////////////////////////////////////////////////////////////
-
-void TarsRollLogger::setLogInfo(const string &sApp, const string &sServer, const string &sLogpath, int iMaxSize, int iMaxNum, const CommunicatorPtr &comm, const string &sLogObj)
-{
-    _app       = sApp;
-    _server    = sServer;
-    _logpath   = sLogpath;
-
-    //生成目录
-    TC_File::makeDirRecursive(_logpath + "/" + _app + "/" + _server);
-
-    _local.start(1);
-
-    //初始化本地循环日志
-    _logger.init(_logpath + "/" + _app + "/" + _server + "/" + _app + "." + _server, iMaxSize, iMaxNum);
-    _logger.modFlag(TC_DayLogger::HAS_TIME, false);
-    _logger.modFlag(TC_DayLogger::HAS_TIME|TC_DayLogger::HAS_LEVEL|TC_DayLogger::HAS_PID, true);
-
-    //设置为异步
-    sync(false);
-
-
-    //设置染色日志信息
-    _logger.getWriteT().setDyeingLogInfo(sApp, sServer, sLogpath, iMaxSize, iMaxNum, comm, sLogObj);
-
-}
-
-
-void TarsRollLogger::sync(bool bSync)
-{
-    if(bSync)
-    {
-        _logger.unSetupThread();
-    }
-    else
-    {
-        _logger.setupThread(&_local);
-    }
-}
-
-void TarsRollLogger::enableDyeing(bool bEnable, const string& sDyeingKey/* = ""*/)
-{
-    _logger.getRoll()->enableDyeing(bEnable, sDyeingKey);
-}
-
-/////////////////////////////////////////////////////////////////////////////////////
-
-TarsLoggerThread::TarsLoggerThread()
-{
-    _local.start(1);
-    _remote.start(1);
-}
-
-TarsLoggerThread::~TarsLoggerThread()
-{
-    //先刷新本地日志
-    _local.flush();
-
-    //再刷新远程日志, 保证不会丢日志
-    _remote.flush();
-}
-
-TC_LoggerThreadGroup* TarsLoggerThread::local()
-{
-    return &_local;
-}
-
-TC_LoggerThreadGroup* TarsLoggerThread::remote()
-{
-    return &_remote;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////
-RemoteTimeWriteT::RemoteTimeWriteT():_timeWrite(NULL)
-{
-}
-
-RemoteTimeWriteT::~RemoteTimeWriteT()
-{
-}
-
-void RemoteTimeWriteT::setTimeWriteT(TimeWriteT *pTimeWrite)
-{
-    _timeWrite = pTimeWrite;
-}
-
-void RemoteTimeWriteT::operator()(ostream &of, const deque<pair<size_t, string> > &buffer)
-{
-    const static uint32_t len = 2000;
-
-    //写远程日志
-    if(_timeWrite->_logPrx && !buffer.empty())
-    {
-        //大于50w条, 直接抛弃掉,否则容易导致内存泄漏
-        if(buffer.size() > 500000)
-        {
-            _timeWrite->writeError(buffer);
-            return;
-        }
-
-        vector<string> v;
-        v.reserve(len);
-
-        deque<pair<size_t, string> >::const_iterator it = buffer.begin();
-        while(it != buffer.end())
-        {
-            v.push_back(it->second);
-
-            ++it;
-
-            //每次最多同步len条
-            if(v.size() >= len)
-            {
-                sync2remote(v);
-                v.clear();
-                v.reserve(len);
-            }
-        }
-
-        if(v.size() > 0)
-        {
-            sync2remote(v);
-        }
-    }
-}
-
-void RemoteTimeWriteT::sync2remote(const vector<string> &v)
-{
-    try
-    {
-        //此处传递set信息到远程logserver
-        LogInfo stInfo;
-        stInfo.appname           = _timeWrite->_app;
-        stInfo.servername        = _timeWrite->_server;
-        stInfo.sFilename         = _timeWrite->_file;
-        stInfo.sFormat           = _timeWrite->_format;
-        stInfo.setdivision       = _timeWrite->_setDivision;
-        stInfo.bHasSufix         = _timeWrite->_hasSufix;
-        stInfo.bHasAppNamePrefix = _timeWrite->_hasAppNamePrefix;
-        stInfo.sConcatStr        = _timeWrite->_concatStr;
-        stInfo.bHasSquareBracket = _timeWrite->_hasSquareBracket;
-        stInfo.sSepar            = _timeWrite->_separ;
-        stInfo.sLogType          = _timeWrite->_logType;
-
-        _timeWrite->_logPrx->loggerbyInfo(stInfo,v, ServerConfig::Context);
-
-        if (_timeWrite->_reportSuccPtr)
-        {
-            _timeWrite->_reportSuccPtr->report(v.size());
-        }
-    }
-    catch(exception &ex)
-    {
-        TLOGERROR("[TARS] write to remote log server error:" << ex.what() << ": buffer size:" << v.size() << endl);
-        _timeWrite->writeError(v);
-        if (_timeWrite->_reportFailPtr)
-        {
-            _timeWrite->_reportFailPtr->report(v.size());
-        }
-    }
-}
-
-void RemoteTimeWriteT::sync2remoteDyeing(const vector<string> &v)
-{
-    try
-    {
-        _timeWrite->_logPrx->logger(DYEING_DIR, DYEING_FILE, "", _timeWrite->_format, v, ServerConfig::Context);
-    }
-    catch(exception &ex)
-    {
-        TLOGERROR("[TARS] write dyeing log to remote log server error:" << ex.what() << ": buffer size:" << v.size() << endl);
-        _timeWrite->writeError(v);
-    }
-}
-/////////////////////////////////////////////////////////////////////////////////////
-//
-TimeWriteT::~TimeWriteT()
-{
-    if(_remoteTimeLogger)
-    {
-        delete _remoteTimeLogger;
-    }
-}
-
-TimeWriteT::TimeWriteT() : _remoteTimeLogger(NULL), _local(true), _remote(true), _dyeingTimeLogger(NULL),_setDivision(""),
-    _hasSufix(true),_hasAppNamePrefix(true),_concatStr("_"),_separ("|"),_hasSquareBracket(false),_logType("")
-{
-}
-
-void TimeWriteT::setLogInfo(const LogPrx &logPrx, const string &sApp, const string &sServer, const string &sFile, const string &sLogpath, const string &sFormat, const string& setdivision, const string& sLogType, const PropertyReportPtr &reportSuccPtr, const PropertyReportPtr &reportFailPtr)
-{
-    _logPrx      = logPrx;
-    _app         = sApp;
-    _server      = sServer;
-    _format      = sFormat;
-    _file        = sFile;
-    _setDivision = setdivision;
-    _logType     = sLogType;
-    _reportSuccPtr = reportSuccPtr;
-    _reportFailPtr = reportFailPtr;
-
-    string sAppSrvName = _hasAppNamePrefix?(_app + "." + _server):"";
-
-    _filePath = sLogpath + "/" + _app + "/" + _server + "/" + sAppSrvName;
-    if(!_file.empty())
-    {
-        _filePath += (_hasAppNamePrefix?_concatStr:"") + sFile;
-    }
-
-    string sDyeingDir = sLogpath;
-    sDyeingDir += "/";
-    sDyeingDir += DYEING_DIR;
-    sDyeingDir += "/";
-
-    _dyeingFilePath = sDyeingDir;
-
-    _remoteTimeLogger = new RemoteTimeLogger();
-    _remoteTimeLogger->init(_filePath, _format,_hasSufix,_concatStr,NULL,true);
-    _remoteTimeLogger->modFlag(0xffff, false);
-    _remoteTimeLogger->setSeparator(_separ);
-    _remoteTimeLogger->enableSqareWrapper(_hasSquareBracket);
-    _remoteTimeLogger->setupThread(TarsLoggerThread::getInstance()->remote());
-    _remoteTimeLogger->getWriteT().setTimeWriteT(this);
-
-    if(!_local)
-    {
-        initError();
-    }
-}
-
-void TimeWriteT::initDyeingLog()
-{
-    TC_File::makeDirRecursive(_dyeingFilePath);
-
-    string sDyeingFile = _dyeingFilePath;
-    sDyeingFile += "/";
-    sDyeingFile += DYEING_FILE;
-
-    _dyeingTimeLogger = new DyeingTimeLogger();
-    _dyeingTimeLogger->init(sDyeingFile, _format);
-    _dyeingTimeLogger->modFlag(0xffff, false);
-}
-
-void TimeWriteT::setLogPrx(const LogPrx &logPrx)
-{
-    _logPrx     = logPrx;
-}
-
-void TimeWriteT::initError()
-{
-    //远程错误日志
-    _logger.init(_filePath + ".remote.error", _format);
-    _logger.modFlag(0xffff, false);
-}
-
-void TimeWriteT::enableLocal(bool bEnable)
-{
-    _local = bEnable;
-    if(!_local)
-    {
-        initError();
-    }
-}
-
-void TimeWriteT::operator()(ostream &of, const deque<pair<size_t, string> > &buffer)
-{
-
-    if(_local && of && !buffer.empty())
-    {
-        try
-        {
-            _wt(of, buffer);
-        }
-        catch(...)
-        {
-        }
-    }
-
-    if(_remote && _remoteTimeLogger && !buffer.empty())
-    {
-        deque<pair<size_t, string> >::const_iterator it = buffer.begin();
-        while(it != buffer.end())
-        {
-            _remoteTimeLogger->any() << it->second;
-            ++it;
-        }
-    }
-
-    vector<string> vDyeingLog;
-    deque<pair<size_t, string> >::const_iterator it = buffer.begin();
-    while(it != buffer.end())
-    {
-        if(it->first != 0)
-        {
-            if(!_dyeingTimeLogger)
-            {
-                initDyeingLog();
-            }
-            _dyeingTimeLogger->any() << _app << "." << _server << "|" << it->second;
-
-            vDyeingLog.push_back(_app + "." + _server + "|" + it->second);
-        }
-        ++it;
-    }
-    if(_logPrx && !vDyeingLog.empty())
-    {
-        try
-        {
-            _logPrx->logger(DYEING_DIR, DYEING_FILE, "day", "%Y%m%d", vDyeingLog, ServerConfig::Context);
-        }
-        catch(exception &ex)
-        {
-            TLOGERROR("[TARS] dyeing log write to remote log server error:" << ex.what() << endl);
-        }
-    }
-}
-
-void TimeWriteT::writeError(const vector<string> &buffer)
-{
-    if(!_local)
-    {
-        for(size_t i = 0; i < buffer.size(); i++)
-        {
-            _logger.any() << buffer[i];
-        }
-    }
-
-    //告警
-    string sInfo = _app + "." + _server + "|";
-    sInfo += ServerConfig::LocalIp + "|sync log to remote tarslog error";
-    FDLOG("tarserror") << sInfo <<endl;
-    //TARS_NOTIFY_ERROR(sInfo);
-}
-
-void TimeWriteT::writeError(const deque<pair<size_t, string> > &buffer)
-{
-    if(!_local)
-    {
-        deque<pair<size_t, string> >::const_iterator it = buffer.begin();
-        while(it != buffer.end())
-        {
-            _logger.any() << it->second;
-            ++it;
-        }
-    }
-
-    //告警
-    string sInfo = _app + "." + _server + "|";
-    sInfo += ServerConfig::LocalIp + "|sync log to remote tarslog error(buffer.size>500000)";
-    FDLOG("tarserror") << sInfo <<endl;
-    //TARS_NOTIFY_ERROR(sInfo);
-
-}
-
-/////////////////////////////////////////////////////////////////////////////////////
-
-TarsTimeLogger::TarsTimeLogger() : _defaultLogger(NULL),_hasSufix(true),_hasAppNamePrefix(true),_concatStr("_"),_separ("|"),_hasSquareBracket(false),_local(true),_remote(true)
-{
-}
-
-TarsTimeLogger::~TarsTimeLogger()
-{
-    if(_defaultLogger != NULL)
-    {
-        delete _defaultLogger;
-    }
-
-    map<string, TimeLogger*>::iterator it = _loggers.begin();
-    while(it != _loggers.end())
-    {
-        delete it->second;
-        ++it;
-    }
-    _loggers.clear();
-}
-
-void TarsTimeLogger::initTimeLogger(TimeLogger *pTimeLogger, const string &sFile, const string &sFormat,const TarsLogTypePtr& logTypePtr)
-{
-    string sAppSrvName = _hasAppNamePrefix?(_app + "." + _server):"";
-    string sFilePath   = _logpath + "/" + _app + "/" + _server + "/" + sAppSrvName;
-
-    if(!sFile.empty())
-    {
-        sFilePath += (_hasAppNamePrefix?_concatStr:"") + sFile;
-    }
-
-    //本地日志格式
-    pTimeLogger->init(sFilePath, sFormat,_hasSufix,_concatStr,logTypePtr,!_local);
-    pTimeLogger->modFlag(0xffff, false);
-    pTimeLogger->modFlag(TC_DayLogger::HAS_TIME, true);
-    pTimeLogger->setSeparator(_separ);
-    pTimeLogger->enableSqareWrapper(_hasSquareBracket);
-    pTimeLogger->setupThread(TarsLoggerThread::getInstance()->local());
-
-    //远程日志格式
-    pTimeLogger->getWriteT().enableSufix(_hasSufix);
-    pTimeLogger->getWriteT().enablePrefix(_hasAppNamePrefix);
-    pTimeLogger->getWriteT().setFileNameConcatStr(_concatStr);
-    pTimeLogger->getWriteT().setSeparator(_separ);
-    pTimeLogger->getWriteT().enableSqareWrapper(_hasSquareBracket);
-    pTimeLogger->getWriteT().enableLocal(_local);
-    pTimeLogger->getWriteT().enableRemote(_remote);
-
-    string sLogType = "";
-    if(logTypePtr)
-    {
-        sLogType = logTypePtr->toString();
-    }
-    
-    PropertyReportPtr reportSuccPtr = NULL;
-    PropertyReportPtr reportFailPtr = NULL;
-    if (_remote && _logStatReport)
-    {
-        string sKey   = _app + "." + _server + "." + sFile;
-        reportSuccPtr = _comm->getStatReport()->createPropertyReport(sKey + "_log_send_succ", PropertyReport::sum());
-        reportFailPtr = _comm->getStatReport()->createPropertyReport(sKey + "_log_send_fail", PropertyReport::sum());
-    }
-
-    pTimeLogger->getWriteT().setLogInfo(_logPrx, _app, _server, sFile, _logpath, sFormat, _setDivision, sLogType, reportSuccPtr, reportFailPtr);
-}
-
-void TarsTimeLogger::initTimeLogger(TimeLogger *pTimeLogger,const string &sApp, const string &sServer, const string &sFile, const string &sFormat,const TarsLogTypePtr& logTypePtr)
-{
-    string sAppSrvName = _hasAppNamePrefix?(sApp + "." + sServer):"";
-    string sFilePath = _logpath + "/" + sApp + "/" + sServer + "/" + sAppSrvName;
-
-    if(!sFile.empty())
-    {
-        sFilePath += (_hasAppNamePrefix?_concatStr:"") + sFile;
-
-    }
-
-    //本地日志格式
-    pTimeLogger->init(sFilePath,sFormat,_hasSufix,_concatStr,logTypePtr,!_local);
-    pTimeLogger->modFlag(0xffff, false);
-    pTimeLogger->modFlag(TC_DayLogger::HAS_TIME, true);
-    pTimeLogger->setSeparator(_separ);
-    pTimeLogger->enableSqareWrapper(_hasSquareBracket);
-    pTimeLogger->setupThread(TarsLoggerThread::getInstance()->local());
-
-    //远程日志格式
-    pTimeLogger->getWriteT().enableSufix(_hasSufix);
-    pTimeLogger->getWriteT().enablePrefix(_hasAppNamePrefix);
-    pTimeLogger->getWriteT().setFileNameConcatStr(_concatStr);
-    pTimeLogger->getWriteT().setSeparator(_separ);
-    pTimeLogger->getWriteT().enableSqareWrapper(_hasSquareBracket);
-    pTimeLogger->getWriteT().enableLocal(_local);
-    pTimeLogger->getWriteT().enableRemote(_remote);
-    string sLogType = "";
-    if(logTypePtr)
-    {
-        sLogType = logTypePtr->toString();
-    }
-
-    PropertyReportPtr reportSuccPtr = NULL;
-    PropertyReportPtr reportFailPtr = NULL;
-    if (_remote && _logStatReport)
-    {
-        string sKey   = _app + "." + _server + "." + sFile;
-        reportSuccPtr = _comm->getStatReport()->createPropertyReport(sKey + "_log_send_succ", PropertyReport::sum());
-        reportFailPtr = _comm->getStatReport()->createPropertyReport(sKey + "_log_send_fail", PropertyReport::sum());
-    }
-
-    pTimeLogger->getWriteT().setLogInfo(_logPrx, sApp, sServer, sFile, _logpath, sFormat, _setDivision, sLogType, reportSuccPtr, reportFailPtr);
-}
-
-void TarsTimeLogger::setLogInfo(const CommunicatorPtr &comm, const string &obj, const string &sApp, const string &sServer, const string &sLogpath, const string& setdivision, const bool &bLogStatReport)
-{
-    _app         = sApp;
-    _server      = sServer;
-    _logpath     = sLogpath;
-    _comm        = comm;
-    _setDivision = setdivision;
-    _logStatReport = bLogStatReport;
-    if(!obj.empty())
-    {
-        _logPrx = _comm->stringToProxy<LogPrx>(obj);
-        //单独设置超时时间
-        _logPrx->tars_timeout(3000);
-
-        if(_defaultLogger)
-        {
-            _defaultLogger->getWriteT().setLogPrx(_logPrx);
-        }
-    }
-
-    //创建本地目录
-    TC_File::makeDirRecursive(_logpath + "/" + _app + "/" + _server);
-}
-
-void TarsTimeLogger::initFormat(const string &sFile, const string &sFormat,const TarsLogTypePtr& logTypePtr)
-{
-    if(sFile.empty())
-    {
-        if(!_defaultLogger)
-        {
-            _defaultLogger = new TimeLogger();
-
-        }
-        initTimeLogger(_defaultLogger, "", sFormat,logTypePtr);
-    }
-    else
-    {
-        string s = _app + "/" + _server + "/"+ sFile;
-        Lock lock(*this);
-        map<string, TimeLogger*>::iterator it = _loggers.find(s);
-        if( it == _loggers.end())
-        {
-            TimeLogger *p = new TimeLogger();
-            initTimeLogger(p, sFile, sFormat,logTypePtr);
-            _loggers[s] = p;
-            return;
-        }
-
-        initTimeLogger(it->second, sFile, sFormat,logTypePtr);
-    }
-}
-void TarsTimeLogger::initFormat(const string &sApp, const string &sServer,const string &sFile, const string &sFormat,const TarsLogTypePtr& logTypePtr)
-{
-    string s = sApp + "/" + sServer + "/"+ sFile;
-    Lock lock(*this);
-    map<string, TimeLogger*>::iterator it = _loggers.find(s);
-    if( it == _loggers.end())
-    {
-        TimeLogger *p = new TimeLogger();
-        initTimeLogger(p, sApp, sServer, sFile, sFormat,logTypePtr);
-        _loggers[s] = p;
-        return;
-    }
-
-    initTimeLogger(it->second, sApp, sServer, sFile, sFormat,logTypePtr);
-}
-
-TarsTimeLogger::TimeLogger* TarsTimeLogger::logger(const string &sFile)
-{
-    if(sFile.empty())
-    {
-        if(!_defaultLogger)
-        {
-            _defaultLogger = new TimeLogger();
-            initTimeLogger(_defaultLogger, "", "%Y%m%d");
-        }
-        return _defaultLogger;
-    }
-
-    string s = _app + "/" + _server + "/"+ sFile;
-    Lock lock(*this);
-    map<string, TimeLogger*>::iterator it = _loggers.find(s);
-    if( it == _loggers.end())
-    {
-        TimeLogger *p = new TimeLogger();
-        initTimeLogger(p, sFile, "%Y%m%d");
-        _loggers[s] = p;
-        return p;
-    }
-
-    return it->second;
-}
-
-TarsTimeLogger::TimeLogger* TarsTimeLogger::logger(const string &sApp, const string &sServer,const string &sFile)
-{
-    string s = sApp + "/" + sServer + "/"+ sFile;
-
-    Lock lock(*this);
-    map<string, TimeLogger*>::iterator it = _loggers.find(s);
-    if( it == _loggers.end())
-    {
-        TimeLogger *p = new TimeLogger();
-        initTimeLogger(p, sApp, sServer, sFile, "%Y%m%d");
-        _loggers[s] = p;
-        return p;
-    }
-
-    return it->second;
-}
-
-
-void TarsTimeLogger::sync(const string &sFile, bool bSync)
-{
-    if(bSync)
-    {
-        logger(sFile)->unSetupThread();
-    }
-    else
-    {
-        logger(sFile)->setupThread(TarsLoggerThread::getInstance()->local());
-    }
-}
-
-void TarsTimeLogger::enableRemote(const string &sFile, bool bEnable)
-{
-    logger(sFile)->getWriteT().enableRemote(bEnable);
-}
-
-void TarsTimeLogger::enableRemoteEx(const string &sApp, const string &sServer,const string &sFile, bool bEnable)
-{
-    logger(sApp,sServer,sFile)->getWriteT().enableRemote(bEnable);
-}
-void TarsTimeLogger::enableLocal(const string &sFile, bool bEnable)
-{
-    logger(sFile)->getWriteT().enableLocal(bEnable);
-    logger(sFile)->setRemote(!bEnable);
-}
-
-void TarsTimeLogger::enableLocalEx(const string &sApp, const string &sServer,const string &sFile, bool bEnable)
-{
-    logger(sApp,sServer,sFile)->getWriteT().enableLocal(bEnable);
-    logger(sApp,sServer,sFile)->setRemote(!bEnable);
-}
-
-}

+ 0 - 116
servant/libservant/TarsNodeF.cpp

@@ -1,116 +0,0 @@
-/**
- * Tencent is pleased to support the open source community by making Tars available.
- *
- * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
- *
- * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 
- * in compliance with the License. You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- *
- * Unless required by applicable law or agreed to in writing, software distributed 
- * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
- * specific language governing permissions and limitations under the License.
- */
-
-#include "util/tc_port.h"
-#include "servant/TarsNodeF.h"
-#include "servant/TarsLogger.h"
-#include "servant/Communicator.h"
-
-namespace tars
-{
-
-void TarsNodeFHelper::setNodeInfo(const CommunicatorPtr &comm, const string &obj, const string &app, const string &server)
-{
-    _comm           = comm;
-    if(!obj.empty())
-    {
-        _nodePrx        = _comm->stringToProxy<ServerFPrx>(obj);
-    }
-
-    _si.application = app;
-    _si.serverName  = server;
-	_si.pid = TC_Port::getpid();
-}
-
-void TarsNodeFHelper::keepAlive(const string &adapter)
-{
-        try
-        {
-            if(_nodePrx)
-            {
-                set<string> s;
-                {
-                    TC_LockT<TC_ThreadMutex> lock(*this);
-
-                    _adapterSet.insert(adapter);
-
-                    if(adapter != "AdminAdapter")
-                    {
-                        return;
-                    }
-                    s.swap(_adapterSet);
-                }
-                ServerInfo si   = _si;
-                set<string>::const_iterator it = s.begin();
-                while(it != s.end())
-                {
-                    si.adapter      = *it;
-                    _nodePrx->async_keepAlive(NULL,si);
-                    ++it;
-                }
-
-            }
-        }
-        catch(exception &ex)
-        {
-                TLOGERROR("TarsNodeFHelper::keepAlive error:" << ex.what() << endl);
-        }
-        catch(...)
-        {
-                TLOGERROR("TarsNodeFHelper::keepAlive unknown error" << endl);
-        }
-}
-
-void TarsNodeFHelper::keepActiving()
-{
-    try
-    {
-        if(_nodePrx)
-        {
-            _nodePrx->async_keepActiving(NULL, _si);
-        }
-    }
-    catch(exception &ex)
-    {
-        LOG->error() << "TafNodeFHelper::keepAlive error:" << ex.what() << endl;
-    }
-    catch(...)
-    {
-        LOG->error() << "TafNodeFHelper::keepAlive unknown error" << endl;
-    }
-}
-
-void TarsNodeFHelper::reportVersion(const string &version)
-{
-        try
-        {
-        if(_nodePrx)
-        {
-            _nodePrx->async_reportVersion(NULL, _si.application, _si.serverName, version);
-        }
-        }
-        catch(exception &ex)
-        {
-                TLOGERROR("TarsNodeFHelper::reportVersion error:" << ex.what() << endl);
-        }
-        catch(...)
-        {
-                TLOGERROR("TarsNodeFHelper::reportVersion unknown error" << endl);
-        }
-}
-
-}
-

+ 0 - 132
servant/libservant/TarsNotify.cpp

@@ -1,132 +0,0 @@
-/**
- * Tencent is pleased to support the open source community by making Tars available.
- *
- * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
- *
- * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 
- * in compliance with the License. You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- *
- * Unless required by applicable law or agreed to in writing, software distributed 
- * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
- * specific language governing permissions and limitations under the License.
- */
-
-#include "servant/TarsNotify.h"
-#include "servant/Communicator.h"
-#include "servant/TarsLogger.h"
-
-namespace tars
-{
-
-int TarsRemoteNotify::setNotifyInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string &sSetName, const string &nodeName)
-{
-    _comm           = comm;
-    if(!obj.empty())
-    {
-        _notifyPrx  = _comm->stringToProxy<NotifyPrx>(obj);
-        _notifyPrx->tars_timeout(500);
-    }
-
-    _setName        = sSetName;
-    _app            = app;
-    _serverName     = serverName;
-    _nodeName      =  nodeName;
-    return 0;
-}
-
-void TarsRemoteNotify::report(const string &sResult, bool bSync)
-{
-    try
-    {
-        if(_notifyPrx)
-        {
-            ReportInfo info;
-            info.sApp      = _app;
-            info.sServer   = _serverName;
-            info.sSet      = _setName;
-            info.sThreadId = TC_Common::tostr(std::this_thread::get_id());
-            info.sMessage  = sResult;
-            info.sNodeName = _nodeName;
-            if(!bSync)
-            {
-                //_notifyPrx->async_reportServer(NULL, _app + "." + _serverName, TC_Common::tostr(std::this_thread::get_id()), sResult);
-                _notifyPrx->async_reportNotifyInfo(NULL, info);
-            }
-            else
-            {
-                //_notifyPrx->reportServer(_app + "." + _serverName, TC_Common::tostr(std::this_thread::get_id()), sResult);
-                _notifyPrx->reportNotifyInfo(info);
-            }
-        }
-    }
-    catch(exception &ex)
-    {
-        TLOGERROR("TarsRemoteNotify::report error:" << ex.what() << endl);
-    }
-    catch(...)
-    {
-        TLOGERROR("TarsRemoteNotify::report unknown error" << endl);
-    }
-}
-
-void TarsRemoteNotify::notify(NOTIFYLEVEL level, const string &sMessage)
-{
-    try
-    {
-        if(_notifyPrx)
-        {
-            ReportInfo info;
-           // info.eType     = 0;
-            info.sApp      = _app;
-            info.sServer   = _serverName;
-            info.sSet      = _setName;
-            info.sThreadId = TC_Common::tostr(std::this_thread::get_id());
-            info.sMessage  = sMessage;
-            info.eLevel    = level;
-            info.sNodeName = _nodeName;
-            //_notifyPrx->async_notifyServer(NULL, _app + "." + _serverName, level, sMessage);
-            _notifyPrx->async_reportNotifyInfo(NULL, info);
-        }
-    }
-    catch(exception &ex)
-    {
-        TLOGERROR("TarsRemoteNotify::notify error:" << ex.what() << endl);
-    }
-    catch(...)
-    {
-        TLOGERROR("TarsRemoteNotify::notify unknown error" << endl);
-    }
-}
-
-void TarsRemoteNotify::report(const string &sMessage, const string & app, const string &serverName, const string &sNodeName)
-{
-    try
-    {
-        if(_notifyPrx)
-        {
-            ReportInfo info;
-           // info.eType     = 0;
-            info.sApp      = app;
-            info.sServer   = serverName;
-            info.sSet      = "";
-            info.sMessage  = sMessage;
-            info.sNodeName = sNodeName;
-            _notifyPrx->async_reportNotifyInfo(NULL, info);
-        }
-    }
-    catch(exception &ex)
-    {
-        TLOGERROR("TarsRemoteNotify::notify error:" << ex.what() << endl);
-    }
-    catch(...)
-    {
-        TLOGERROR("TarsRemoteNotify::notify unknown error" << endl);
-    }
-}
-
-}
-
-

+ 14 - 12
servant/libservant/Transceiver.cpp

@@ -17,7 +17,7 @@
 #include "servant/Transceiver.h"
 #include "servant/AdapterProxy.h"
 #include "servant/Application.h"
-#include "servant/TarsLogger.h"
+#include "servant/RemoteLogger.h"
 #include "servant/AuthLogic.h"
 
 #if TARS_SSL
@@ -160,6 +160,7 @@ void Transceiver::setConnected()
 	{
 		_adapterProxy->getObjProxy()->getPushCallback()->onConnect(_ep.getEndpoint());
 	}
+	_adapterProxy->onConnect();
 }
 
 void Transceiver::onConnect()
@@ -181,6 +182,7 @@ void Transceiver::onConnect()
 	    _openssl->setReadBufferSize(1024 * 8);
 	    _openssl->setWriteBufferSize(1024 * 8);
 
+	    _openssl->recvBuffer()->setConnection(this);
         int ret = _openssl->doHandshake(_sendBuffer);
         if (ret != 0)
         {
@@ -212,7 +214,7 @@ void Transceiver::doAuthReq()
     if (_adapterProxy->endpoint().authType() == AUTH_TYPENONE)
     {
         _authState = AUTH_SUCC;
-        _adapterProxy->doInvoke();
+        _adapterProxy->doInvoke(true);
     }
     else
     {
@@ -284,7 +286,7 @@ void Transceiver::doAuthReq()
 //
 //			if (ret == TC_NetWorkBuffer::PACKET_ERR)
 //			{
-//				TLOGERROR("[TAF][tcp doResponse," << _pAdapterProxy->getObjProxy()->name() << ",fd:" << _iFd << "," << _ep.desc() << ",tcp recv decode error" << endl);
+//				TLOGERROR("[TARS][tcp doResponse," << _pAdapterProxy->getObjProxy()->name() << ",fd:" << _iFd << "," << _ep.desc() << ",tcp recv decode error" << endl);
 //				msg->eStatus = ReqMessage::REQ_NET;
 //				msg->response->sResultDesc = "recv packet decode failed";
 //
@@ -298,7 +300,7 @@ void Transceiver::doAuthReq()
 //		}
 //		catch (exception & ex) {
 //			TLOGERROR(
-//				"[TAF][tcp doResponse," << _pAdapterProxy->getObjProxy()->name() << ",fd:" << _iFd << "," << _ep.desc() << ",tcp recv decode error:" << ex.what() << endl);
+//				"[TARS][tcp doResponse," << _pAdapterProxy->getObjProxy()->name() << ",fd:" << _iFd << "," << _ep.desc() << ",tcp recv decode error:" << ex.what() << endl);
 //			msg->eStatus = ReqMessage::REQ_NET;
 //			msg->response->sResultDesc = "recv packet decode failed";
 //
@@ -306,7 +308,7 @@ void Transceiver::doAuthReq()
 //		}
 //		catch (...) {
 //			TLOGERROR(
-//				"[TAF][tcp doResponse," << _pAdapterProxy->getObjProxy()->name() << ",fd:" << _iFd << "," << _ep.desc() << ",tcp recv decode error." << endl);
+//				"[TARS][tcp doResponse," << _pAdapterProxy->getObjProxy()->name() << ",fd:" << _iFd << "," << _ep.desc() << ",tcp recv decode error." << endl);
 //			msg->eStatus = ReqMessage::REQ_NET;
 //			msg->response->sResultDesc = "recv packet decode failed";
 //		}
@@ -323,7 +325,7 @@ void Transceiver::doAuthReq()
 
 void Transceiver::finishInvoke(shared_ptr<ResponsePacket> &rsp)
 {
-	if (_authState != AUTH_SUCC)
+	if (_adapterProxy->endpoint().authType() == AUTH_TYPELOCAL && _authState != AUTH_SUCC)
 	{
 		std::string ret(rsp->sBuffer.begin(), rsp->sBuffer.end());
 		tars::AUTH_STATE tmp = AUTH_SUCC;
@@ -336,7 +338,7 @@ void Transceiver::finishInvoke(shared_ptr<ResponsePacket> &rsp)
 		if (newstate == AUTH_SUCC)
 		{
 			// flush old buffered msg when auth is not complete
-			_adapterProxy->doInvoke();
+			_adapterProxy->doInvoke(true);
 		}
 		else
 		{
@@ -406,7 +408,7 @@ void Transceiver::close()
     if(!isValid()) return;
 
 
-#if TAF_SSL
+#if TARS_SSL
     if (_openssl)
     {
         _openssl->release();
@@ -437,11 +439,11 @@ void Transceiver::close()
 
 	if(second > 0) {
 		_adapterProxy->getObjProxy()->getCommunicatorEpoll()->reConnect(TNOWMS + second * 1000, this);
-		TLOGERROR("[TAF][trans close:" << _adapterProxy->getObjProxy()->name() << "," << _ep.desc() << ", reconnect:" << second << "]" << endl);
+		TLOGERROR("[TARS][trans close:" << _adapterProxy->getObjProxy()->name() << "," << _ep.desc() << ", reconnect:" << second << "]" << endl);
 	}
 //	else
 //	{
-//		TLOGERROR("[TAF][trans close:" << _adapterProxy->getObjProxy()->name() << "," << _ep.desc() << "]" << endl);
+//		TLOGERROR("[TARS][trans close:" << _adapterProxy->getObjProxy()->name() << "," << _ep.desc() << "]" << endl);
 //	}
 }
 
@@ -467,7 +469,7 @@ int Transceiver::doRequest()
 
 	//取adapter里面积攒的数据
     if(_sendBuffer.empty()) {
-        _adapterProxy->doInvoke();
+        _adapterProxy->doInvoke(false);
     }
 
 	//object里面应该是空的
@@ -939,7 +941,7 @@ UdpTransceiver::UdpTransceiver(AdapterProxy * pAdapterProxy, const EndpointInfo
         _pRecvBuffer = new char[DEFAULT_RECV_BUFFERSIZE];
         if(!_pRecvBuffer)
         {
-            throw TC_Exception("objproxy '" + _adapterProxy->getObjProxy()->name() + "' malloc udp receive buffer fail");
+            throw TC_Exception("obj: '" + _adapterProxy->getObjProxy()->name() + "' malloc udp receive buffer fail");
         }
     }
 

+ 4 - 4
servant/makefile/makefile.tars

@@ -42,8 +42,8 @@ MYSQL_LIB_DIR   += -L/usr/local/mysql/lib/mysql -L/usr/local/mysql/lib -L/usr/li
 LIB_DIR         += ${MYSQL_LIB_DIR}
 INC_DIR         += ${MYSQL_INC}
 
-ifneq ($(_USE_OPENTRACKING), 0)
-ifneq ($(_USE_OPENTRACKING), )
+ifneq ($(TARS_OPENTRACKING), 0)
+ifneq ($(TARS_OPENTRACKING), )
 	OPENTRACKING_INC     += -I/usr/local/include
 	OPENTRACKING_LIB_DIR += -L/usr/local/lib 
 	LIB_DIR += ${OPENTRACKING_LIB_DIR}
@@ -72,8 +72,8 @@ ifneq ($(TARS_HTTP2), )
 endif
 endif
 
-ifneq ($(_USE_OPENTRACKING), 0)
-ifneq ($(_USE_OPENTRACKING), )
+ifneq ($(TARS_OPENTRACKING), 0)
+ifneq ($(TARS_OPENTRACKING), )
 	#业务编译
 	CFLAGS += -D_USE_OPENTRACKING=1
 	LIB += -lopentracing -lzipkin_opentracing -lzipkin -lcurl 

+ 64 - 18
servant/servant/AdapterProxy.h

@@ -26,7 +26,9 @@
 #include "servant/Message.h"
 #include "servant/StatReport.h"
 #include <queue>
-#ifdef _USE_OPENTRACKING
+#include <unordered_map>
+
+#ifdef TARS_OPENTRACKING
 #include <opentracing/span.h>
 #endif
 namespace tars
@@ -52,14 +54,30 @@ public:
 
     /**
      * 调用server端对象方法
+     * @param req
+     * @return int
      */
-    int invoke(ReqMessage * msg);
+	int invoke(ReqMessage * msg);
+
+//	/**
+//	 * 同步阻塞调用server
+//	 * @param msg
+//	 * @return
+//	 */
+//	bool invoke_sync(ReqMessage * msg);
+
+	/**
+	 *
+	 */
+	void onConnect();
 
     /**
      * 发送请求
      * 发送挤压的数据
+     * @param req
+     * @return
      */
-    void doInvoke();
+    void doInvoke(bool initInvoke);
 
     /**
      * server端的响应包返回
@@ -91,9 +109,9 @@ public:
     /**
      * 处理采样
      */
-    void sample(ReqMessage * msg);
+//    void sample(ReqMessage * msg);
 
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
 	/** 
 	 * Zipkin调用链
 	 */
@@ -169,6 +187,17 @@ public:
      */
     inline int getId() const { return _id; }
 
+    /**
+     *
+     * @return
+     */
+	inline Transceiver* getTransceiver() const { return _trans.get(); }
+
+	/**
+	 * 屏蔽结点
+	 */
+	void onSetInactive();
+
 private:
 
     /**
@@ -204,9 +233,31 @@ private:
     void merge(const StatMicMsgBody& inBody, StatMicMsgBody& outBody);
 
     /**
-     * 获取被调名
+     * 连接串行模式
+     * @param msg
+     * @return
      */
-    string getSlaveName(const string& sSlaveName);
+	int invoke_connection_serial(ReqMessage * msg);
+
+	/**
+	 * 连接并行模式
+	 * @param msg
+	 * @return
+	 */
+	int invoke_connection_parallel(ReqMessage * msg);
+
+	void finishInvoke_serial(shared_ptr<ResponsePacket> & rsp);
+
+	void finishInvoke_parallel(shared_ptr<ResponsePacket> & rsp);
+
+	void doInvoke_serial();
+
+	void doInvoke_parallel();
+
+   /**
+    * 获取被调名
+    */
+   string getSlaveName(const string& sSlaveName);
 
 private:
 
@@ -225,6 +276,11 @@ private:
      */
     EndpointInfo                           _endpoint;
 
+    /**
+     * in request
+     */
+    ReqMessage*                             _requestMsg = NULL;
+
     /*
      * 收发包处理
      */
@@ -315,20 +371,10 @@ private:
      */
     map<string,StatMicMsgBody>               _statBody;
 
-    /*
-     * 最大采样次数
-     */
-    uint32_t                               _maxSampleCount;
-
-    /*
-     * 采样比率
-     */
-    int                                    _sampleRate;
-
     /*
      * 调用链信息
      */
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
     map<int,std::unique_ptr<opentracing::Span>> _spanMap;
 #endif
     int                                    _id;

+ 1 - 1
servant/servant/AdminServant.h

@@ -22,7 +22,7 @@
 namespace tars
 {
 
-class TarsCurrent;
+class Current;
 class Application;
 
 ////////////////////////////////////////////////////////////////////////

+ 2 - 2
servant/servant/AppCache.h

@@ -26,7 +26,7 @@
 #include "util/tc_timeprovider.h"
 #include "util/tc_file.h"
 #include "util/tc_thread_mutex.h"
-#include "servant/TarsLogger.h"
+#include "servant/RemoteLogger.h"
 
 #define APPCACHE_ROOT_PATH "/cache"
 
@@ -38,7 +38,7 @@ namespace tars
 /**
  * 缓存
  */
-class AppCache : public TC_Singleton<AppCache>, public TC_ThreadMutex
+class SVT_DLL_API AppCache : public TC_Singleton<AppCache>, public TC_ThreadMutex
 {    
 public:
     AppCache()

+ 2 - 0
servant/servant/AppProtocol.h

@@ -143,6 +143,8 @@ public:
     static vector<char> http1Request(tars::RequestPacket& request, Transceiver *);
     static TC_NetWorkBuffer::PACKET_TYPE http1Response(TC_NetWorkBuffer &in, ResponsePacket& done);
 
+	// static vector<char> httpJceRequest(taf::RequestPacket& request, Transceiver *);
+	// static TC_NetWorkBuffer::PACKET_TYPE httpJceResponse(TC_NetWorkBuffer &in, ResponsePacket& done);
 #if TARS_HTTP2
 
     // ENCODE function, called by network thread

+ 23 - 11
servant/servant/Application.h

@@ -30,9 +30,9 @@
 #include "servant/ServantHandle.h"
 #include "servant/StatReport.h"
 #include "servant/CommunicatorFactory.h"
-#include "servant/TarsLogger.h"
-#include "servant/TarsConfig.h"
-#include "servant/TarsNotify.h"
+#include "servant/RemoteLogger.h"
+#include "servant/RemoteConfig.h"
+#include "servant/RemoteNotify.h"
 
 #if TARS_SSL
 #include "util/tc_openssl.h"
@@ -62,27 +62,28 @@ namespace tars
 #define TARS_CMD_CLOSE_CORE          "tars.closecore"         //设置服务的core limit:  tars.setlimit [yes|no]
 #define TARS_CMD_RELOAD_LOCATOR      "tars.reloadlocator"     //重新加载locator的配置信息
 #define TARS_CMD_RESOURCE            "tars.resource"          //get resource
+#define TARS_CMD_VIEW_BID            "tars.bid"               //查看服务编译时间,build id
 //////////////////////////////////////////////////////////////////////
 /**
  * 通知信息给notify服务, 展示在页面上
  */
 //上报普通信息
-#define TARS_NOTIFY_NORMAL(info)     {TarsRemoteNotify::getInstance()->notify(NOTIFYNORMAL, info);}
+#define TARS_NOTIFY_NORMAL(info)     {RemoteNotify::getInstance()->notify(NOTIFYNORMAL, info);}
 
 //上报警告信息
-#define TARS_NOTIFY_WARN(info)       {TarsRemoteNotify::getInstance()->notify(NOTIFYWARN, info);}
+#define TARS_NOTIFY_WARN(info)       {RemoteNotify::getInstance()->notify(NOTIFYWARN, info);}
 
 //上报错误信息
-#define TARS_NOTIFY_ERROR(info)      {TarsRemoteNotify::getInstance()->notify(NOTIFYERROR, info);}
+#define TARS_NOTIFY_ERROR(info)      {RemoteNotify::getInstance()->notify(NOTIFYERROR, info);}
 
 //发送心跳给node 多个adapter分别上报
-#define TARS_KEEPALIVE(adapter)      {TarsNodeFHelper::getInstance()->keepAlive(adapter);}
+#define TARS_KEEPALIVE(adapter)      {KeepAliveNodeFHelper::getInstance()->keepAlive(adapter);}
 
 //发送激活信息
-#define TARS_KEEPACTIVING            {TarsNodeFHelper::getInstance()->keepActiving();}
+#define TARS_KEEPACTIVING            {KeepAliveNodeFHelper::getInstance()->keepActiving();}
 
 //发送TARS版本给node
-#define TARS_REPORTVERSION(x)        {TarsNodeFHelper::getInstance()->reportVersion(TARS_VERSION);}
+#define TARS_REPORTVERSION(x)        {KeepAliveNodeFHelper::getInstance()->reportVersion(TARS_VERSION);}
 
 //////////////////////////////////////////////////////////////////////
 /**
@@ -105,7 +106,7 @@ namespace tars
 /**
  * 服务基本信息
  */
-struct ServerConfig
+struct SVT_DLL_API ServerConfig
 {
     static std::string TarsPath;
     static std::string Application;         //应用名称
@@ -139,6 +140,7 @@ struct ServerConfig
 	static std::string Cert;
 	static std::string Key;
 	static bool VerifyClient;
+	static std::string Ciphers;
 #endif
 	static map<string, string> Context;     //框架内部用, 传递节点名称(以域名形式部署时)
 };
@@ -326,7 +328,17 @@ protected:
      *
      * @return bool
      */
-    bool cmdViewVersion(const string& command, const string& params, string& result);
+    bool cmdViewVersion(const string &command, const string &params, string &result);
+
+    /**
+     * 查看服务的buildid(编译时间)
+     * @param command
+     * @param params
+     * @param result
+     *
+     * @return bool
+     */
+    bool cmdViewBuildID(const string &command, const string &params, string &result);
 
     /**
      * 使配置文件的property信息生效

+ 27 - 11
servant/servant/Communicator.h

@@ -26,8 +26,8 @@
 #include "servant/ObjectProxyFactory.h"
 #include "servant/AsyncProcThread.h"
 #include "servant/CommunicatorEpoll.h"
-#include "servant/TarsLogger.h"
-#ifdef _USE_OPENTRACKING
+#include "servant/RemoteLogger.h"
+#ifdef TARS_OPENTRACKING
 #include "zipkin/opentracing.h"
 #include "zipkin/tracer.h"
 #include "zipkin/ip_address.h"
@@ -77,10 +77,11 @@ struct ClientConfig
 /**
  * 通信器,用于创建和维护客户端proxy
  */
-class Communicator : public TC_HandleBase, public TC_ThreadRecMutex
+class SVT_DLL_API Communicator : public TC_HandleBase, public TC_ThreadRecMutex
 {
 public:
 
+	typedef std::function<void(ReqMessagePtr)> custom_callback;
     /**
      * 构造函数
      */
@@ -195,6 +196,11 @@ public:
 	 */
 	string getServantProperty(const string &sObj, const string& name);
 
+	/**
+	 * 设置自动回调对象
+	 */
+	void setServantCustomCallback(const string &sObj, custom_callback callback);
+
     /**
      * 上报统计
      * @return StatReport*
@@ -218,12 +224,12 @@ public:
      */
     vector<TC_Endpoint> getEndpoint(const string & objName);
 
-    /**
-     * 获取obj对应可用ip port列表 包括所有IDC的
-     * @param sObjName
-     * @return vector<TC_Endpoint>
-     */
-    vector<TC_Endpoint> getEndpoint4All(const string & objName);
+   /**
+    * 获取obj对应可用ip port列表 包括所有IDC的
+    * @param sObjName
+    * @return vector<TC_Endpoint>
+    */
+   vector<TC_Endpoint> getEndpoint4All(const string& objName);
 
     /**
      * 结束
@@ -244,7 +250,7 @@ public:
      * get resource info
      * @return
      */
-	string getResouresInfo();
+	string getResourcesInfo();
 
 protected:
     /**
@@ -376,6 +382,16 @@ protected:
 	unordered_map<string, shared_ptr<TC_OpenSSL::CTX>> _objCtx;
 #endif
 
+	/**
+	 *
+	 */
+	TC_SpinLock                                    _callbackLock;
+
+	/**
+	 * callback
+	 */
+	unordered_map<string, custom_callback>         _callback;
+
     /*
      * 异步线程数组
      */
@@ -396,7 +412,7 @@ protected:
      */
     size_t                 _asyncSeq = 0;
 
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
 public:
     struct TraceManager:public TC_HandleBase{
         zipkin::ZipkinOtTracerOptions _zipkin_options;

+ 4 - 7
servant/servant/CommunicatorEpoll.h

@@ -65,13 +65,9 @@ struct FDInfo
     }
 
     size_t iSeq;
-
-    int    fd;
-
-    int    iType;
-
+    int fd;
+    int iType;
     void * p;
-
     TC_Epoller::NotifyInfo notify;
 };
 
@@ -82,6 +78,7 @@ struct FDInfo
 class CommunicatorEpoll : public TC_Thread ,public TC_ThreadRecMutex
 {
 public:
+
     /**
      * 构造函数
      */
@@ -190,7 +187,7 @@ public:
 	 * communicator resource desc
 	 * @return
 	 */
-	string getResouresInfo();
+	string getResourcesInfo();
 
 protected:
     /**

+ 19 - 7
servant/servant/EndpointManager.h

@@ -33,8 +33,8 @@ namespace tars
 enum  GetEndpointType
 {
     E_DEFAULT = 0,
-    E_ALL     = 1,
-    E_SET     = 2,
+    E_ALL = 1,
+    E_SET = 2,
     E_STATION = 3
 };
 
@@ -129,9 +129,9 @@ public:
      */
     virtual void doNotify() = 0;
 
-    /*
-     * 设置主控的代理
-     */
+	/*
+	 * 设置主控的代理
+	 */
     int  setLocatorPrx(QueryFPrx prx);
 
     /*
@@ -168,7 +168,7 @@ private:
     /*
      * 主控的请求的响应到了,做相应的处理
      */
-    void doEndpoints(const vector<tars::EndpointF>& activeEp, const vector<tars::EndpointF>& inactiveEp, int iRet, bool bSync = false);
+    void doEndpoints(const vector<EndpointF>& activeEp, const vector<EndpointF>& inactiveEp, int iRet, bool bSync = false);
 
     /*
      * 请求主控异常,做相应的处理
@@ -246,6 +246,11 @@ protected:
      */
     set<EndpointInfo>         _inactiveEndpoints;
 
+    /**
+     * 是否是root servant
+     */
+	bool                      _rootServant;
+
 private:
 
     /////////以下是请求主控的策略信息/////////////////
@@ -334,7 +339,14 @@ public:
      */
     void notifyEndpoints(const set<EndpointInfo> & active, const set<EndpointInfo> & inactive, bool bSync = false);
 
-    /*
+    /**
+     * 更新
+     * @param active
+     * @param inactive
+     */
+	void updateEndpoints(const set<EndpointInfo> & active, const set<EndpointInfo> & inactive);
+
+	/*
      * 重写基类的实现
      */
     void doNotify();

+ 12 - 4
servant/servant/Global.h

@@ -50,7 +50,7 @@ class AdapterProxy;
 class ServantProxy;
 class ServantProxyCallback;
 class ObjectProxy;
-class TarsCurrent;
+class Current;
 class FDReactor;
 class Transceiver;
 class StatFProxy;
@@ -58,19 +58,27 @@ class StatReport;
 class ServantProxyFactory;
 class ObjectProxyFactory;
 class AsyncProcThread;
+class LocalRollLogger;
+class RemoteConfig;
+class RemoteTimeLogger;
+class RemoteNotify;
 
 typedef TC_AutoPtr<Communicator> CommunicatorPtr;
 typedef TC_AutoPtr<ServantProxy> ServantPrx;
 typedef TC_AutoPtr<ServantProxyCallback> ServantProxyCallbackPtr;
 typedef TC_AutoPtr<ObjectProxy> ObjectPrx;
-typedef TC_AutoPtr<TarsCurrent> TarsCurrentPtr;
+typedef TC_AutoPtr<Current> CurrentPtr;
 typedef TC_AutoPtr<StatFProxy> StatFPrx;
 typedef TC_AutoPtr<StatReport> StatReportPtr;
 typedef TC_AutoPtr<FDReactor> FDReactorPtr;
-// typedef TC_AutoPtr<ServantProxyFactory> ServantProxyFactoryPtr;
-//typedef TC_AutoPtr<ObjectProxyFactory> ObjectProxyFactoryPtr;
 typedef TC_AutoPtr<AsyncProcThread> AsyncProcThreadPtr;
 
+typedef CurrentPtr TarsCurrentPtr;
+typedef RemoteConfig TarsRemoteConfig;
+typedef RemoteNotify TarsRemoteNotify;
+typedef LocalRollLogger TarsRollLogger;
+typedef RemoteTimeLogger TarsTimeLogger;
+
 //////////////////////////////////////////////////////////////
 /**
  * 定义TARS网络调用的异常基类

+ 9 - 59
servant/servant/Message.h

@@ -49,8 +49,8 @@ struct CheckTimeoutInfo
     , frequenceFailInvoke(5)
     , minFrequenceFailTime(5)
     , radio(0.5)
-    , tryTimeInterval(30)
-    , maxConnectExc(5)
+    , tryTimeInterval(10)
+    , maxConnectExc(1)
     {
     }
 
@@ -90,61 +90,6 @@ struct CheckTimeoutInfo
     uint32_t maxConnectExc;
 };
 
-/////////////////////////////////////////////////////////////////////////
-/*
- * stat采样信息(用于调用链时序分析)
- */
-struct SampleKey
-{
-    /*
-     * 构造函数
-     */
-    SampleKey()
-    : _root(true)
-    , _unid("")
-    , _depth(0)
-    , _width(0)
-    , _parentWidth(0)
-    {}
-
-    /*
-     * 初始化
-     */
-    void init()
-    {
-        _root        = true;
-        _unid.clear();
-        _depth       = 0;
-        _width       = 0;
-        _parentWidth = 0;
-    }
-
-    /*
-     * 是否根节点 在根节点产生唯一id
-     */
-    bool _root;
-
-    /*
-     * 唯一id
-     */
-    string _unid;
-
-    /*
-     * 深度
-     */
-    int _depth;
-
-    /*
-     * 广度
-     */
-    int _width;
-
-    /*
-     * 父节点广度值
-     */
-    int _parentWidth;
-};
-
 /////////////////////////////////////////////////////////////////////////
 /**
  * 用于同步调用时的条件变量
@@ -211,6 +156,11 @@ struct ReqMessage : public TC_HandleBase
      */
     ~ReqMessage()
     {
+    	if(deconstructor)
+	    {
+		    deconstructor();
+	    }
+
         if(pMonitor != NULL)
         {
             delete pMonitor;
@@ -263,6 +213,7 @@ struct ReqMessage : public TC_HandleBase
     ObjectProxy *               pObjectProxy;   //调用端的proxy对象
 
     RequestPacket               request;        //请求消息体
+    std::function<void()>       deconstructor;  //析构时调用
     shared_ptr<ResponsePacket>      response;   //响应消息体
     // string                      sReqData;       //请求消息体
 	shared_ptr<TC_NetWorkBuffer::Buffer> sReqData;       //请求消息体
@@ -289,7 +240,7 @@ struct ReqMessage : public TC_HandleBase
     uint32_t                    iCoroId;        //协程的id
 
 
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
     std::unordered_map<std::string, std::string> trackInfoMap; //调用链信息
 #endif
 
@@ -299,7 +250,6 @@ struct ReqMessage : public TC_HandleBase
 typedef TC_AutoPtr<ReqMessage>          ReqMessagePtr;
 typedef TC_LoopQueue<ReqMessage*>  ReqInfoQueue;
     
-#define HTTP2 "http2"
 
 }
 

+ 1 - 1
servant/servant/NotifyObserver.h

@@ -18,7 +18,7 @@
 #define __TARS_NOTIFY_OBSERVER_H_
 
 #include "servant/Global.h"
-#include "servant/TarsCurrent.h"
+#include "servant/Current.h"
 #include "util/tc_singleton.h"
 
 namespace tars

+ 70 - 16
servant/servant/ObjectProxy.h

@@ -87,6 +87,19 @@ public:
      */
     void doInvoke();
 
+    /**
+     *
+     * @param adapterProxy
+     */
+//	void doInvoke(AdapterProxy *adapterProxy);
+
+	/**
+     *
+     * @param active
+     * @param inactive
+     */
+	void onNotifyEndpoints(const set<EndpointInfo> & active,const set<EndpointInfo> & inactive);
+
     /**
      * 设置协议解析器
      * @return UserProtocol&
@@ -121,10 +134,13 @@ public:
     ServantProxyCallbackPtr getPushCallback();
 
     /**
-     * 获取所有的adapter
+     * connected
      */
-    // const vector<AdapterProxy*> & getAdapters() const;
+	void onConnect(AdapterProxy *adapterProxy);
 
+	/**
+     * 获取所有的adapter
+     */
     void mergeStat(map<StatMicMsgHead, StatMicMsgBody> & mStatMicMsg);
 
     /**
@@ -132,14 +148,6 @@ public:
      */
     void doTimeout();
 
-//    /**
-//     * Obj的超时队列的长度
-//     */
-//    size_t timeoutQSize()
-//    {
-//        return _reqTimeoutQueue.size();
-//    }
-//
     /**
      * 获取CommunicatorEpoll*
      */
@@ -157,6 +165,24 @@ public:
         return _name;
     }
 
+	/**
+	 * address
+	 * @return
+	 */
+	inline const string &hash() const
+	{
+		return _hash;
+	}
+
+    /**
+     * address
+     * @return
+     */
+    inline const string &address() const
+    {
+    	return _address;
+    }
+
     /**
      * reconnect
      * @param second
@@ -233,18 +259,34 @@ public:
         _servantProxy = pServantProxy;
     }
 
+    /**
+     *
+     * @return
+     */
+	inline EndpointManager* getEndpointManager()
+	{
+    	return _endpointManger.get();
+	}
+
     /**
      * get all adapter proxy
      * @return
      */
 	const vector<AdapterProxy*> & getAdapters();
 
+	/**
+	 *
+	 * @param ep
+	 */
+	void onSetInactive(const EndpointInfo& ep);
+
 protected:
 
-    /**
-     * 处理请求异常
-     */
-    void doInvokeException(ReqMessage * msg);
+	/**
+	 * 处理请求异常
+	 *
+	 */
+	void doInvokeException(ReqMessage * msg);
 
 private:
     /*
@@ -253,10 +295,22 @@ private:
     CommunicatorEpoll *                   _communicatorEpoll;
 
     /*
-     * object的名称
+     * [obname]#hash@tcp -h xxxx -p xxx
      */
     string                                _name;
 
+    /**
+     * obname#[hash]@tcp -h xxxx -p xxx
+     * ever hash has one connection
+     */
+    string                                _hash;
+
+	/**
+	 * obname#hash@[tcp -h xxxx -p xxx]
+	 * ever hash has one connection
+	 */
+    string                                _address;
+
     /*
      * 按set规则调用的set名称
      */
@@ -268,7 +322,7 @@ private:
     bool                                  _isInvokeBySet;
 
     /*
-     * 是否调用了tars_set_protocol设置过proxy的协议函数,
+     * 是否调用了taf_set_protocol设置过proxy的协议函数,
      * 设置过了就不在设置
      */
     bool                                  _hasSetProtocol;

+ 5 - 5
servant/servant/PropertyReport.h

@@ -19,7 +19,7 @@
 
  #include "util/tc_lock.h"
 #include "util/tc_autoptr.h"
-//#include "util/tc_thread_mutex.h"
+#include "util/tc_thread_mutex.h"
 #include "util/tc_spin_lock.h"
 #include <tuple>
 #include <vector>
@@ -80,7 +80,7 @@ public:
         string get();
         void   set(int o)           { _sum += o;++_count; }
     protected:
-        void   clear()                { _sum = 0; _count = 0; }
+        void clear()                { _sum = 0; _count = 0; }
     private:
         int _sum;
         int _count;
@@ -170,7 +170,7 @@ typedef TC_AutoPtr<PropertyReport> PropertyReportPtr;
  */
 
 template <typename... Params>
-class PropertyReportImp : public PropertyReport, public TC_SpinLock
+class PropertyReportImp : public PropertyReport, public TC_ThreadMutex
 {
 public:
     using PropertyReportData = std::tuple<Params...>;
@@ -195,7 +195,7 @@ public:
     */
     void report(int iValue) override
     {
-        TC_LockT<TC_SpinLock> lock(*this);
+        TC_LockT<TC_ThreadMutex> lock(*this);
         Helper<std::tuple_size<decltype(_propertyReportData)>::value>::Report(*this, iValue);
     }
 
@@ -207,7 +207,7 @@ public:
      */
     vector<pair<string, string> > get() override
     {
-        TC_LockT<TC_SpinLock> lock(*this);
+        TC_LockT<TC_ThreadMutex> lock(*this);
         return Helper<std::tuple_size<decltype(_propertyReportData)>::value>::Get(*this);
     }
 

+ 2 - 2
servant/servant/Servant.h

@@ -22,7 +22,7 @@
 #include "util/tc_thread_pool.h"
 #include "util/tc_cas_queue.h"
 #include "servant/ServantProxy.h"
-#include "servant/TarsCurrent.h"
+#include "servant/Current.h"
 #include "servant/BaseNotify.h"
 
 namespace tars
@@ -250,7 +250,7 @@ protected:
     ServantPtr _servant;
 
     /*
-     * TarsCurrent
+     * Current
      */
     TarsCurrentPtr _current;
 };

+ 9 - 15
servant/servant/ServantHandle.h

@@ -27,7 +27,7 @@
 #include "servant/Servant.h"
 #include "servant/StatReport.h"
 #include "servant/CoroutineScheduler.h"
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
 #include "opentracing/span.h"
 #endif
 
@@ -58,10 +58,10 @@ public:
      */
     ~ServantHandle();
 
-    /**
-     * 线程处理方法
-     */
-    virtual void run();
+	/**
+	 * 线程处理方法
+	 */
+	virtual void run();
 
     /**
      * 获取协程调度器
@@ -136,14 +136,14 @@ protected:
     /**
      * 创建上下文
      * @param stRecvData
-     * @return TarsCurrent*
+     * @return Current*
      */
     TarsCurrentPtr createCurrent(const shared_ptr<TC_EpollServer::RecvContext> &data);
 
     /**
      * 创建闭连接时的关上下文
      * @param stRecvData
-     * @return TarsCurrent*
+     * @return Current*
      */
     TarsCurrentPtr createCloseCurrent(const shared_ptr<TC_EpollServer::RecvContext> &data);
 
@@ -161,14 +161,8 @@ protected:
      */
     void handleNoTarsProtocol(const TarsCurrentPtr &current);
 
-    /**
-     * 处理TARS下的采样统计逻辑
-     *
-     * @param current
-     */
-    void processSample(const TarsCurrentPtr &current);
 
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
     /**
      * 处理TARS下的调用链逻辑
      *
@@ -211,7 +205,7 @@ protected:
      */
     CoroutineScheduler     *_coroSched;
 
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
     map<int,std::unique_ptr<opentracing::Span>> _spanMap;
 #endif
 };

+ 4 - 4
servant/servant/ServantHelper.h

@@ -56,7 +56,7 @@ struct ServantCreation : public ServantHelperCreation
 /**
  * Servant管理
  */
-class ServantHelperManager : public TC_Singleton<ServantHelperManager>
+class SVT_DLL_API ServantHelperManager : public TC_Singleton<ServantHelperManager>
 {
 public:
     /**
@@ -77,8 +77,8 @@ public:
     {
         if(check && _servant_adapter.end() == _servant_adapter.find(id))
         {
-            cerr<<"[TAF]ServantHelperManager::addServant "<< id <<" not find adapter.(maybe not conf in the web)"<<endl;
-			throw runtime_error("[TAF]ServantHelperManager::addServant " + id + " not find adapter.(maybe not conf in the web)");
+            cerr<<"[TARS]ServantHelperManager::addServant "<< id <<" not find adapter.(maybe not conf in the web)"<<endl;
+			throw runtime_error("[TARS]ServantHelperManager::addServant " + id + " not find adapter.(maybe not conf in the web)");
         }
         _servant_creator[id] = new ServantCreation<T>(application);
     }
@@ -188,7 +188,7 @@ protected:
     /**
      * 是否染色
      */
-    bool           _isDyeing;
+    bool   _isDyeing;
 
     /**
      * 染色用户号码

+ 146 - 41
servant/servant/ServantProxy.h

@@ -21,7 +21,7 @@
 #include "util/tc_autoptr.h"
 #include "servant/Message.h"
 #include "servant/AppProtocol.h"
-#include "servant/TarsCurrent.h"
+#include "servant/Current.h"
 //#include "servant/EndpointInfo.h"
 #include "servant/CommunicatorEpoll.h"
 
@@ -148,7 +148,7 @@ public:
      *  objectProxy Pointer
      */
     shared_ptr<ObjectProxy *> _objectProxyOwn;                    //保存ObjectProxy对象的指针数组
-#ifdef _USE_OPENTRACKING
+#ifdef TARS_OPENTRACKING
     std::unordered_map<std::string, std::string> _trackInfoMap;
 #endif
 
@@ -264,6 +264,12 @@ public:
      */
     virtual ~ServantProxyCallback() {}
 
+    /**
+     * 设置发起调用的servant
+     * @param prx
+     */
+	void setServantPrx(const ServantPrx &prx) { _servantPrx = prx; }
+
     /**
      * 获取类型
      * @return const string&
@@ -288,7 +294,7 @@ public:
 
     /**
      * 异步请求是否在网络线程处理
-     * tars内部用的到 业务不能设置这个值
+     * taf内部用的到 业务不能设置这个值
      * */
     inline void setNetThreadProcess(bool bNetThreadProcess)
     {
@@ -301,23 +307,32 @@ public:
     }
 
 public:
+	/**
+	 * dispatch, call onDispatch
+	 * @param msg
+	 * @return
+	 */
+	int dispatch(ReqMessagePtr msg);
+
+protected:
     /**
      * 异步回调对象实现该方法,进行业务逻辑处理
      * @param msg
      * @return int
      */
-    virtual int onDispatch(ReqMessagePtr ptr) = 0;
+    virtual int onDispatch(ReqMessagePtr msg) = 0;
 
     /**
-     * 连接关闭掉了(只对PUSH callback生效)
+     * 连接关闭掉了(push callback 才有效)
      */    
     virtual void onClose(){};
 
 	/**
-	 * 连接已建立(只对PUSH callback生效)
+	 * 连接已建立(push callback 才有效)
 	 */
 	virtual void onConnect(const TC_Endpoint &ep){};
 
+	friend class Transceiver;
 protected:
 
     /**
@@ -334,18 +349,20 @@ protected:
     /**
      * 协程并行请求的共享智能指针
      */
-    tars::CoroParallelBasePtr _pPtr;
+    CoroParallelBasePtr _pPtr;
+
+    /**
+     * servant prx
+     */
+	ServantPrx _servantPrx;
 };
 ///////////////////////////////////////////////////////////////////////////////////////////////
 // for http
 class HttpCallback : public TC_HandleBase
 {
 public:
-    virtual int onHttpResponse(const std::map<std::string, std::string>& requestHeaders ,
-                               const std::map<std::string, std::string>& responseHeaders ,
-                               const std::vector<char>& rspBody) = 0;
-    virtual int onHttpResponseException(const std::map<std::string, std::string>& requestHeaders,
-                                        int expCode) = 0;
+    virtual int onHttpResponse(const shared_ptr<TC_HttpResponse> &rsp) = 0;
+    virtual int onHttpResponseException(int expCode) = 0;
 };
 
 typedef TC_AutoPtr<HttpCallback> HttpCallbackPtr;
@@ -411,7 +428,7 @@ public:
 
     static string STATUS_TRACK_KEY; //track信息
 
-    static string STATUS_COOKIE; //cookie信息
+    // static string STATUS_COOKIE; //cookie信息
 
     /**
      * 缺省的同步调用超时时间
@@ -419,6 +436,23 @@ public:
      */
     enum { DEFAULT_SYNCTIMEOUT = 3000, DEFAULT_ASYNCTIMEOUT=5000};
 
+    /**
+     * default connection serial num
+     */
+    const static int DEFAULT_CONNECTION_SERIAL = 10;
+
+	/**
+	 * 内置四种协议支持
+	 */
+    enum SERVANT_PROTOCOL
+    {
+    	PROTOCOL_TARS,              //默认tars服务的协议
+    	PROTOCOL_HTTP1,             //http协议
+#if TARS_HTTP2
+	    PROTOCOL_HTTP2,             //http2协议
+#endif
+    };
+
     /**
      * 构造函数
      * @param op
@@ -528,19 +562,48 @@ public:
      */
     string tars_name() const;
 
+	/**
+	 * 获取所属的Object名称#hash@address
+	 * @return string
+	 */
+	string tars_full_name() const;
+
     /**
      * 获取最近一次调用的IP地址和端口
      * @return string
      */
     static TC_Endpoint tars_invoke_endpoint();
 
+	/**
+	 * 设置连接为多连接, 串行模式
+	 * @param connectionSerial, <=0: 连接复用模式(一个连接上同时跑多个请求, 响应包), >0: 连接串行模式(连接个数), 同一个连接上并行只能跑一个包(http协议)
+	 */
+	void tars_connection_serial(int connectionSerial);
+
+	/**
+	 * 获取连接并发模式
+	 * @return int
+	 */
+	int tars_connection_serial() const;
+
+	/**
+	 * 直接设置内置支持的协议
+	 */
+    void tars_set_protocol(SERVANT_PROTOCOL protocol, int connectionSerial = 0);
+
     /**
      * 设置用户自定义协议
      * @param protocol
      */
-    void tars_set_protocol(const ProxyProtocol& protocol);
+    void tars_set_protocol(const ProxyProtocol& protocol, int connectionSerial = 0);
 
     /**
+     * get protocol
+     * @return
+     */
+	ProxyProtocol tars_get_protocol();
+
+	/**
     *设置套接字选项
     */
     void tars_set_sockopt(int level, int optname, const void *optval, SOCKET_LEN_TYPE optlen);
@@ -643,28 +706,19 @@ public:
 //	               std::map<std::string, std::string>& rheaders,
 //	               std::string& rbody);
 
-    /**
-     * http2协议同步远程调用
-     */
-    void http_call(const std::string& method,
-                    const std::string& uri,
-                    const std::map<std::string, std::string>& headers,
-                    const std::string& body,
-                    std::map<std::string, std::string>& rheaders,
-                    std::string& rbody);
-    /**
-     * http2协议异步远程调用
-     */
-    void http_call_async(const std::string& method,
-                         const std::string& uri,
-                         const std::map<std::string, std::string>& headers,
-                          const std::string& body,
-                          const HttpCallbackPtr &cb);
+	/**
+	 * http1/2协议同步远程调用
+	 * @param funcName: 调用名称, 这里只是做统计用
+	 */
+	void http_call(const string &funcName, shared_ptr<TC_HttpRequest> &request, shared_ptr<TC_HttpResponse> &response);
 
-    /**
-     * 在RequestPacket中的context设置主调信息标识
-     */
-    virtual void tars_setMasterFlag(bool bMasterFlag) {_masterFlag = bMasterFlag;}
+	/**
+	 * http1/2协议异步远程调用
+	 * @param funcName: 调用名称, 这里只是做统计用
+	 */
+	void http_call_async(const string &funcName, shared_ptr<TC_HttpRequest> &request, const HttpCallbackPtr &cb, bool bCoro = false);
+
+protected:
 
     /**
      * TARS协议同步方法调用
@@ -686,6 +740,14 @@ public:
                                   const ServantProxyCallbackPtr& callback,
                                   bool bCoro = false);
 
+	/**
+	 * 获得可以复用的servant
+	 * @return
+	 */
+	ServantPrx getServantPrx(ReqMessage *msg);
+
+	friend class ServantProxyCallback;
+
 private:
     /**
      * 远程方法调用
@@ -694,6 +756,13 @@ private:
      */
     void invoke(ReqMessage *msg, bool bCoroAsync = false);
 
+    /**
+     * 选择某个servant来发送
+     * @param msg
+     * @param bCoroAsync
+     */
+	int servant_invoke(ReqMessage *msg, bool bCoroAsync);
+
 //    /**
 //     * invoke 异步
 //     * @param msg
@@ -724,6 +793,17 @@ private:
      */
     void checkDye(RequestPacket& req);
 
+    /**
+     * 更新endpoint
+     * @param active
+     * @param inactive
+     */
+	void onNotifyEndpoints(const set<EndpointInfo> & active,const set<EndpointInfo> & inactive);
+
+	/**
+	 * 端口不活跃
+	 */
+	void onSetInactive(const EndpointInfo& ep);
     /**
      * 检查是否需要设置cookie
      * @param  req
@@ -737,29 +817,29 @@ private:
     /**
      * 通信器
      */
-    Communicator *            _communicator;
+    Communicator *              _communicator;
 
     /**
      * 保存ObjectProxy对象的指针数组
      */
-    ObjectProxy ** _objectProxy;                    //保存ObjectProxy对象的指针数组
-    shared_ptr<ObjectProxy *> _objectProxyOwn;                    //保存ObjectProxy对象的指针数组
+    ObjectProxy **              _objectProxy;                    //保存ObjectProxy对象的指针数组
+    shared_ptr<ObjectProxy *>   _objectProxyOwn;                    //保存ObjectProxy对象的指针数组
 
     /**
      * ObjectProxy对象的个数,其个数由客户端的网络线程数决定,
      * 每个网络线程有一个ObjectProxy
      */
-    size_t                    _objectProxyNum;
+    size_t                      _objectProxyNum;
 
     /**
      * 同步调用超时(毫秒)
      */
-    int                        _syncTimeout;
+    int                         _syncTimeout;
 
     /**
      * 同步调用超时(毫秒)
      */
-    int                        _asyncTimeout;
+    int                         _asyncTimeout;
 
     /**
      * 唯一id
@@ -780,6 +860,31 @@ private:
      *最小的超时时间
      */
     int64_t                    _minTimeout;
+
+    /**
+     * 最大连接串行数(默认0, 表示连接并行请求)
+     */
+    int                         _connectionSerial = 0;
+
+    /**
+     * 短连接使用http使用
+     */
+	ServantPrx                  _rootPrx;
+
+	/**
+	 *
+	 */
+	int                         _servantId = 0;
+
+	/**
+	 *
+	 */
+	std::mutex                  _servantMutex;
+
+	/**
+	 *
+	 */
+	vector<ServantPrx>          _servantList;
 };
 }
 #endif

+ 5 - 0
servant/servant/StatReport.h

@@ -42,6 +42,11 @@
 namespace tars
 {
 
+/**
+ * 状态上报类, 上报的信息包括:
+ * 1 模块间调用的信息
+ * 2 业务自定义的属性统计
+ */
 struct StatSampleMsgHead
 {
     string slaveName;

+ 0 - 154
servant/servant/TarsConfig.h

@@ -1,154 +0,0 @@
-/**
- * Tencent is pleased to support the open source community by making Tars available.
- *
- * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
- *
- * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 
- * in compliance with the License. You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- *
- * Unless required by applicable law or agreed to in writing, software distributed 
- * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
- * specific language governing permissions and limitations under the License.
- */
-
-#ifndef __TARS_CONFIG_H_
-#define __TARS_CONFIG_H_
-
-#include "util/tc_autoptr.h"
-#include "util/tc_singleton.h"
-#include "servant/Global.h"
-#include "servant/ConfigF.h"
-
-using namespace std;
-
-namespace tars
-{
-     
-/**
- *
- * 功能:获取远程系统配置,生成本地文件,支持备份和回滚
- *
- * 说明:该对象只实现将ConfigServer上指定的配置文件
- * 读取到本地(保存到应用程序执行目录),具体配置解析
- * 由客户端实现
- *
- * 客户端通过调用addConfig接口为
- * 每个配置文件创建一个TarsRemoteConfig实例
- *
- * 备份文件数目在对象创建时指定,缺省为5个,
- * 能回滚的次数等于备份文件数目
- *
- */
-
-class TarsRemoteConfig : public TC_Singleton<TarsRemoteConfig>
-{
-public:
-    /**
-     * 初始化
-     * @param comm, 通信器
-     * @param obj, 对象名称
-     * @param app, 应用名称
-     * @param serverName, 服务名称
-     * @param basePath, 基本路径
-     * @param maxBakNum, 最大备份文件个数
-     *
-     * @return int
-     */
-    int setConfigInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string& basePath,const string& setdivision="",int maxBakNum = 5);
-
-    /**
-     * 读取ConfigServer上配置文件到本地,并备份原文件
-     * @param  sFullFileName 文件名称
-     * @param  result        结果
-     * @param  bAppOnly      是否只获取应用级别的配置
-     *
-     * @return bool
-     */
-    bool addConfig(const string & filename, string &result, bool bAppConfigOnly = false);
-
-private:
-    /**
-     *  实现请求ConfigServer并将结果以文件形式保存到本地目录
-     * @param  sFullFileName 文件名称
-     * @param  bAppOnly      是否只获取应用级别的配置
-     *
-     * @return string       生成的文件名称
-     */
-    string getRemoteFile(const string & sFullFileName, bool bAppConfigOnly = false);
-
-    /**
-     * 实现本地文件的回滚,可回滚次数等于最大备份文件数,每次
-     * 都使用最近的备份文件覆盖当前配置文件
-     *
-     * @return string
-     */
-    string recoverSysConfig(const string & sFullFileName);
-
-    /**
-     * 备份文件名称 Config.conf.1.bak,Config.conf.2.bak ...
-     * 该方法提供下标到文件名的转化
-     *
-     * @param index         第几个备份文件
-     *
-     * @return string       配置文件全路径
-     */
-    inline string index2file(const string & sFullFileName, int index);
-
-    /**
-     *  rename系统操作的封装,当oldFile不存在时抛出异常
-     *
-     * @param oldFile   原文件路径和名称
-     * @param newFile   新文件逻辑和名称
-     */
-    inline void localRename(const string& oldFile, const string& newFile);
-
-protected:
-
-    /**
-     * 通信器
-     */
-    CommunicatorPtr _comm;
-
-    /**
-     * 配置代理
-     */
-    ConfigPrx       _configPrx;
-
-    /**
-     * 应用
-     */
-    string          _app;
-
-    /**
-     * 服务名称
-     */
-    string          _serverName;
-
-    /**
-     * 路径
-     */
-    string          _basePath;
-
-    /**
-     * set信息
-     */
-
-    string          _setdivision;
-
-    /**
-     * 最大备份数
-     */
-    int             _maxBakNum;
-
-    /**
-     * 线程锁
-     */
-    TC_ThreadMutex     _mutex;
-};
-
-}
-
-#endif

+ 0 - 72
servant/servant/TarsCookie.h

@@ -1,72 +0,0 @@
-/**
- * Tencent is pleased to support the open source community by making Tars available.
- *
- * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
- *
- * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 
- * in compliance with the License. You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- *
- * Unless required by applicable law or agreed to in writing, software distributed 
- * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
- * specific language governing permissions and limitations under the License.
- */
-
-#ifndef __TARS_COOKIE_H__
-#define __TARS_COOKIE_H__
-
-
-/**
- * cookie操作类
- */
-class TarsCookieOp
-{
-public:
-    /**
-     * 构造函数
-     */
-    TarsCookieOp()
-    {
-    }
-
-    /**
-     * 析构函数,清理掉已设置的cookie
-     */
-    ~TarsCookieOp()
-    {
-        ServantProxyThreadData * td = ServantProxyThreadData::getData();
-        assert(NULL != td);
-        if (td)
-        {
-            td->_cookie.clear();
-        }
-    }
-
-    /**
-     * 获取cookie
-     */
-    static map<string, string> & getCookie()
-    {
-        ServantProxyThreadData * td = ServantProxyThreadData::getData();
-        assert(NULL != td);
-
-        return td->_cookie;
-    }
-
-    /**
-     * 设置cookie
-     */
-    void setCookie(const map<string, string> &cookie)
-    {
-        ServantProxyThreadData * td = ServantProxyThreadData::getData();
-        assert(NULL != td);
-        if(td)
-        {
-            td->_cookie = cookie;
-        }
-    }
-};
-
-#endif

+ 0 - 330
servant/servant/TarsCurrent.h

@@ -1,330 +0,0 @@
-/**
- * Tencent is pleased to support the open source community by making Tars available.
- *
- * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
- *
- * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 
- * in compliance with the License. You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- *
- * Unless required by applicable law or agreed to in writing, software distributed 
- * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
- * specific language governing permissions and limitations under the License.
- */
-
-#ifndef __TARS_CURRENT_H_
-#define __TARS_CURRENT_H_
-
-#include "util/tc_epoll_server.h"
-#include "tup/RequestF.h"
-#include "tup/tup.h"
-#include "servant/BaseF.h"
-
-namespace tars
-{
-
-class ServantHandle;
-
-//////////////////////////////////////////////////////////////
-/**
- * 当前请求的上下文
- */
-class TarsCurrent : public TC_HandleBase
-{
-public:
-    typedef std::map<string, string>    TARS_STATUS;
-
-    typedef std::vector<char>           TARS_BUFFER;
-
-    /**
-     * 构造函数
-     * @param pServantHandle
-     */
-    TarsCurrent(ServantHandle *pServantHandle);
-
-    /**
-     * 析构
-     */
-    ~TarsCurrent();
-
-    /**
-     * 获取IP
-     * @return string
-     */
-    const string &getIp() const;
-
-    /**
-     * get host name
-     * @return
-     */
-	const string &getHostName() const;
-
-	/**
-     * 获取端口
-     * @return int
-     */
-    int getPort() const;
-
-    /**
-     * 获取uid
-     * @return uint32
-     */
-    uint32_t getUId() const;
-
-    /**
-     * 获取fd
-     * @return int
-     */
-    int getFd() const { return _data->fd(); }
-
-    /**
-     * 是否函数返回时发送响应包给客户端
-     * @return bool
-     */
-    bool isResponse() const;
-
-    /**
-     * 设置连接的关闭类型,详情参看TC_EpollServer::EM_CLOSE_T
-     */
-    void setCloseType(int type);
-
-    /**
-     * 获取连接关闭类型,详情请参考TC_EpollServer::EM_CLOSE_T类型
-     */
-    int getCloseType() const;
-
-    /**
-     * 设置是否自动回响应包
-     */
-    void setResponse(bool value) { _response = value; }
-
-    /**
-     * 设置返回的context(仅TARS协议有效)
-     */
-    void setResponseContext(const map<std::string, std::string> & context){_responseContext = context;}
-
-    /**
-     * 获取返回的context(仅TARS协议有效)
-     */
-    const map<std::string, std::string> & getResponseContext() const {return _responseContext;}
-
-    /**
-     * 关闭当前连接
-     */
-    void close();
-
-    /**
-     * 获取所属的ServantHandle
-     */
-    ServantHandle* getServantHandle();
-
-    /**
-     * 获取来源的Adapter
-     * @return TC_EpollServer::BindAdapter*
-     */
-    TC_EpollServer::BindAdapter* getBindAdapter();
-
-    /**
-     * 获取请求buffer
-     * @return string
-     */
-    const vector<char> &getRequestBuffer() const;
-
-    /**
-     * 获取服务Servant名称
-     * @return string
-     */
-    string getServantName() const;
-
-    /**
-     * 请求的协议的版本号(仅TARS协议有效)
-     *
-     * @return short
-     */
-    short getRequestVersion() const;
-
-    /**
-     * 扩展map(仅TARS协议有效)
-     * @return map<string,string>&
-     */
-    map<string, string>& getContext();
-
-    /**
-     * 获取保存状态信息,比如染色等(仅TARS协议有效)
-     * @return map<string,string>&
-     */
-    const map<string, string>& getRequestStatus() const;
-
-    /**
-     * 函数名称(仅TARS协议有效)
-     * @return string
-     */
-    string getFuncName() const;
-
-    /**
-     * 请求ID(仅TARS协议有效)
-     * @return int
-     */
-    uint32_t getRequestId() const;
-
-    /**
-     * 获取包类型(仅TARS协议有效)
-     * @return char
-     */
-    char getPacketType() const;
-
-    /**
-     * 获取消息类型(仅TARS协议有效)
-     * @return tars::Int32
-     */
-    tars::Int32 getMessageType() const;
-
-    /**
-     * 获取接收到请求的时间
-     */
-    struct timeval getRecvTime() const;
-
-    /**
-     * 设置是否上报状态报告
-     */
-    void setReportStat(bool bReport);
-
-    /**
-     * taf协议的发送响应数据(仅TAF协议有效)
-     * @param iRet
-     * @param status
-     * @param buffer
-     */
-    void sendResponse(int iRet);
-
-    /**
-     * taf协议的发送响应数据(仅TAF协议有效), 直接swapbuffer , 这样可以不用copy 数据
-     * @param iRet
-     * @param status
-     * @param buffer
-     */
-	void sendResponse(int iRet, tars::TarsOutputStream<tars::BufferWriterVector>& os);
-
-    /**
-     * taf协议的发送响应数据(仅TAF协议有效), 直接swapbuffer , 这样可以不用copy 数据
-     * @param iRet
-     * @param status
-     * @param buffer
-     */
-	void sendResponse(int iRet, tup::UniAttribute<tars::BufferWriterVector, tars::BufferReader>& attr);
-
-	/**
-	 * taf协议的发送响应数据(仅TAF协议有效)
-	 * @param iRet
-	 * @param buff
-	 */
-	void sendResponse(int iRet, const vector<char> &buff);
-
-	/**
-     * 普通协议的发送响应数据(非TAF协议有效)
-     * @param buff
-     * @param len
-     */
-    void sendResponse(const char* buff, uint32_t len);
-
-    /**
-     * 设置cookie
-     */
-    void setCookie(const map<string, string> &cookie)
-    {
-        _cookie = cookie;
-    }
-
-    /**
-     * 获取cookie
-     */
-    map<string, string> & getCookie()
-    {
-        return _cookie;
-    }
-
-protected:
-
-    friend class ServantHandle;
-
-    friend class Application;
-
-    /**
-     * 初始化
-     * @param data
-     */
-    void initialize(const shared_ptr<TC_EpollServer::RecvContext> &data);
-
-    /**
-     * 初始化
-     * @param data
-     */
-    void initializeClose(const shared_ptr<TC_EpollServer::RecvContext> &data);
-
-    /**
-     * 初始化
-     * @param sRecvBuffer
-     */
-    void initialize(const vector<char> &sRecvBuffer);
-
-    /**
-     * 服务端上报状态,针对单向调用及TUP调用(仅对TARS协议有效)
-     */
-    void reportToStat(const string & sObj);
-
-    /**
-     * 发送消息
-     * @param iRet
-     * @param response
-     * @param status
-     * @param sResultDesc
-     * @param push
-     */
-	void sendResponse(int iRet, const vector<char> &buffer, const map<string, string>& status, const string& sResultDesc);
-
-protected:
-    /**
-     * 操作类指针
-     */
-    ServantHandle*            _servantHandle;
-
-    /**
-     * 接收到的数据
-     */
-	shared_ptr<TC_EpollServer::RecvContext> _data;
-
-    /**
-     * 客户端请求包
-     */
-    RequestPacket            _request;
-
-    /**
-     * 响应
-     */
-    bool                    _response;
-
-    /**
-     * 接口处理的返回值
-     */
-    int                     _ret;
-
-    /**
-     * 是否上报stat
-     */
-    bool                    _reportStat;
-
-    /**
-     * 设置额外返回的内容
-     */
-    map<std::string, std::string> _responseContext;
-
-    /**
-     * cookie
-     */
-    map<string, string>             _cookie;
-};
-//////////////////////////////////////////////////////////////
-}
-#endif

+ 0 - 893
servant/servant/TarsLogger.h

@@ -1,893 +0,0 @@
-/**
- * Tencent is pleased to support the open source community by making Tars available.
- *
- * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
- *
- * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 
- * in compliance with the License. You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- *
- * Unless required by applicable law or agreed to in writing, software distributed 
- * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
- * specific language governing permissions and limitations under the License.
- */
-
-#ifndef __TARS_LOGGER_H__
-#define __TARS_LOGGER_H__
-
-#include "util/tc_logger.h"
-#include "util/tc_file.h"
-#include "util/tc_singleton.h"
-#include "servant/Global.h"
-#include "servant/LogF.h"
-#include "servant/PropertyReport.h"
-
-#define DYEING_DIR "tars_dyeing"
-#define DYEING_FILE "dyeing"
-
-namespace tars
-{
-
-/**
- * LOG的库说明:
- * 1 循环日志采用TLOGERROR(...),TLOGDEBUG(...)
- * 2 循环日志不上传到服务器
- * 3 按天日志采用DLOG, FDLOG来记录
- * 4 按天日志也可以不上传到远程服务器:DLOG("")->disableRemote();
- * 5 按天日志可以改变每天一个文件的方式:
- *   DLOG("abc3")->setFormat("%Y%m%d%H");
- *   每个小时一个文件
- */
-
-/*****************************************************************************
-实现方式说明(只介绍按时间的日志, 会写到tarslog):
-    1 自定义时间日志的WriteT类:RemoteTimeWriteT
-    2 在RemoteTimeWriteT类中, 写入到远程
-    3 定义远程日志类:typedef TC_Logger<RemoteTimeWriteT, TC_RollByTime> RemoteTimeLogger;
-    4 为了保证远程的写日志也是在单独线程处理,重新定义本地按天日志类
-    5 自定义时间日志的WriteT类:TimeWriteT
-    6 在TimeWriteT类中包含RemoteTimeLogger对象
-    7 在TimeWriteT类的写入操作中, 写入本地文件后, 同时写入到RemoteTimeLogger对象中
-    8 RemoteTimeLogger会在RemoteTimeWriteT对象中, 异步写入到远程
-    9 从而本地文件写和远程写不在一个线程中.
-*****************************************************************************/
-
-///////////////////////////////////////////////////////////////////////////////
-
-class RollWriteT
-{
-public:
-    RollWriteT();
-    ~RollWriteT();
-
-    void operator()(ostream &of, const deque<pair<size_t, string> > &ds);
-
-    void setDyeingLogInfo(const string &sApp, const string &sServer, const string & sLogPath,
-            int iMaxSize, int iMaxNum, const CommunicatorPtr &comm, const string & sLogObj);
-
-protected:
-
-    TC_RollLogger *_dyeingRollLogger;
-
-    static int  _dyeingThread;
-
-    string _app;
-    string _server;
-    string _logPath;
-    int _maxSize;
-    int _maxNum;
-
-    /**
-     * 染色远程滚动日志代理
-     */
-    LogPrx                _logPrx;
-
-
-};
-
-
-/**
- * 本地日志帮助类, 单件
- * 循环日志单件是永生不死的, 保证任何地方都可以使用
- * 当该对象析够以后, 则直接cout出来
- */
-class TarsRollLogger : public TC_Singleton<TarsRollLogger, CreateUsingNew, PhoneixLifetime>
-{
-public:
-    enum
-    {
-        NONE_LOG    = 1,    /**所有的log都不写*/
-        ERROR_LOG   = 2,    /**写错误log*/
-        WARN_LOG    = 3,    /**写错误,警告log*/
-        DEBUG_LOG   = 4,    /**写错误,警告,调试log*/
-        INFO_LOG    = 5,        /**写错误,警告,调试,Info log*/
-        TARS_LOG    = 6        /**写错误,警告,调试,Info log*/
-    };
-public:
-    typedef TC_Logger<RollWriteT, TC_RollBySize> RollLogger;
-
-    /**
-     * 设置本地信息
-     * @param app, 业务名称
-     * @param server, 服务名称
-     * @param logpath, 日志路径
-     * @param iMaxSize, 文件最大大小,字节
-     * @param iMaxNum, 文件最大数
-     */
-    void setLogInfo(const string &sApp, const string &sServer, const string &sLogpath, int iMaxSize = 1024*1024*50, int iMaxNum = 10, const CommunicatorPtr &comm=NULL, const string &sLogObj="");
-
-    /**
-     * 设置同步写日志
-     *
-     * @param bSync
-     */
-    void sync(bool bSync = true);
-
-    /**
-     * 获取循环日志
-     *
-     * @return RollLogger
-     */
-    RollLogger *logger()          { return &_logger; }
-
-    /**
-     * 染色日志是否启用
-     * @param bEnable
-     */
-    void enableDyeing(bool bEnable, const string& sDyeingKey = "");
-
-protected:
-
-    /**
-     * 应用
-     */
-    string                  _app;
-
-    /**
-     * 服务名称
-     */
-    string                  _server;
-
-    /**
-     * 日志路径
-     */
-    string                  _logpath;
-
-    /**
-     * 循环日志
-     */
-    RollLogger              _logger;
-
-    /**
-     * 本地线程组
-     */
-    TC_LoggerThreadGroup    _local;
-
-};
-
-///////////////////////////////////////////////////////////////////////////////////////
-//
-/**
- * 写日志线程
- * 将写本地日志和远程分开到不同的线程
- * 作为单件存在, 且是永生不死的单件
- */
-class TarsLoggerThread : public TC_Singleton<TarsLoggerThread, CreateUsingNew, PhoneixLifetime>
-{
-public:
-    /**
-     * 构造函数
-     */
-    TarsLoggerThread();
-
-    /**
-     * 析够函数
-     */
-    ~TarsLoggerThread();
-
-    /**
-     * 本地写日志线程
-     */
-    TC_LoggerThreadGroup* local();
-
-    /**
-     * 远程写日志线程
-     *
-     * @return TC_LoggerThreadGroup*
-     */
-    TC_LoggerThreadGroup* remote();
-
-protected:
-
-    /**
-     * 本地线程组
-     */
-    TC_LoggerThreadGroup    _local;
-
-    /**
-     * 远程写线程组
-     */
-    TC_LoggerThreadGroup    _remote;
-};
-
-///////////////////////////////////////////////////////////////////////////////////////
-class TimeWriteT;
-
-/**
- * 远程的Log写操作类
- */
-class RemoteTimeWriteT
-{
-public:
-    RemoteTimeWriteT();
-    ~RemoteTimeWriteT();
-
-    /**
-     * 构造函数
-     */
-    void setTimeWriteT(TimeWriteT *pTimeWrite);
-
-    /**
-     * 具体调用
-     * @param of
-     * @param buffer
-     */
-    void operator()(ostream &of, const deque<pair<size_t, string> > &buffer);
-
-protected:
-    /**
-     * 同步到远程
-     */
-    void sync2remote(const vector<string> &buffer);
-
-    /**
-     * 染色日志同步到远程
-     */
-    void sync2remoteDyeing(const vector<string> &buffer);
-
-protected:
-    /**
-     * 指针
-     */
-    TimeWriteT          *_timeWrite;
-
-};
-
-////////////////////////////////////////////////////////////////////////////
-/**
- * 写Logger
- */
-class TimeWriteT
-{
-public:
-    typedef TC_Logger<RemoteTimeWriteT, TC_RollByTime> RemoteTimeLogger;
-
-    typedef TC_Logger<TC_DefaultWriteT, TC_RollByTime> DyeingTimeLogger;
-
-    /**
-     * 构造
-     */
-    TimeWriteT();
-
-    /**
-     * 析够
-     */
-    ~TimeWriteT();
-
-    /**
-     * 设置基本信息
-     * @param app, 应用名称
-     * @param server, 服务名称
-     * @param file, 日志文件名
-     * @param sFormat, 格式
-     * @param setdivision,set名称
-     * @param sLogType,日志记录类型
-     */
-    void setLogInfo(const LogPrx &logPrx, const string &sApp, const string &sServer, const string &sFile, const string &sLogpath, const string &sFormat, const string& setdivision = "", const string& sLogType = "", const PropertyReportPtr &reportSuccPtr = NULL, const PropertyReportPtr &reportFailPtr = NULL);
-
-    /**
-     * 设置代理
-     * @param logPrx 代理信息
-     */
-    void setLogPrx(const LogPrx &logPrx);
-
-    /**
-     * 远程日志功能打开或关闭
-     * @param bEnable
-     */
-    void enableRemote(bool bEnable)         { _remote = bEnable; }
-
-    /**
-     * 本地日志功能功能打开或关闭
-     * @param bEnable
-     */
-    void enableLocal(bool bEnable);
-
-    /**
-     * 染色日志功能打开或关闭
-     * @param bEnable
-     */
-    void enableDyeing (bool bEnable, const string& sDyeingKey = "");
-
-
-    /**
-     * @brief 日志文件名是否带.log后缀
-     * @param bEnable
-     */
-    void enableSufix(bool bEnable=true){_hasSufix = bEnable;}
-    /**
-     * @brief 是否允许框架在日志文件名上增加业务相关的标识
-     * @param bEnable
-     */
-    void enablePrefix(bool bEnable=true){_hasAppNamePrefix = bEnable;}
-    /**
-     * @brief 日志文件名中用户自定义字符与日期字符间的连接符,默认是"_"
-     * @param str
-     */
-    void setFileNameConcatStr(const string& str) {_concatStr = str;}
-
-    /**
-     * @brief 框架中增加的日志内容之间的分割符,默认是"|"
-     * @param str
-     */
-    void setSeparator(const string& str) {_separ = str;}
-
-    /**
-     * @brief 框架中日期和时间之间是否需要加中括号[],有些统计由特殊需求;默认不加
-     * @param bEnable
-     */
-    void enableSqareWrapper(bool bEnable) {_hasSquareBracket = bEnable;}
-
-
-    /**
-     * 设置时间格式("%Y%m%d")
-     * @param sFormat
-     */
-    void setFormat(const string &sFormat)   { _format = sFormat;}
-
-    /**
-     * 具体调用
-     * @param of
-     * @param buffer
-     */
-    void operator()(ostream &of, const deque<pair<size_t, string> > &buffer);
-
-protected:
-
-    /**
-     * 友元
-     */
-    friend class RemoteTimeWriteT;
-
-    /**
-     * 记录错误文件
-     * @param buffer
-     */
-    void writeError(const vector<string> &buffer);
-
-    /**
-     * 记录错误文件
-     * @param buffer
-     */
-    void writeError(const deque<pair<size_t, string> > &buffer);
-
-    /**
-     * 初始化logger
-     */
-    void initError();
-
-    /**
-     * 初始化染色日志
-     */
-    void initDyeingLog();
-
-protected:
-
-    /**
-     * 远程时间日志
-     */
-    RemoteTimeLogger    *_remoteTimeLogger;
-
-    /**
-     * 本地功能
-     */
-    bool                _local;
-
-    /**
-     * 远程功能
-     */
-    bool                _remote;
-
-    /**
-     * 远程服务句柄
-     */
-    LogPrx              _logPrx;
-
-    /**
-     * app名称
-     */
-    string              _app;
-
-    /**
-     * 服务名称
-     */
-    string              _server;
-
-    /**
-     * 日志文件名称
-     */
-    string              _file;
-
-    /**
-     * 时间格式
-     */
-    string              _format;
-
-    /**
-     * 具体文件
-     */
-    string              _filePath;
-
-    /**
-     * 错误文件
-     */
-    TC_DayLogger        _logger;
-
-    /**
-     * 缺省写模式
-     */
-    TC_DefaultWriteT    _wt;
-
-    /**
-     * 染色日志
-     */
-    static int          _dyeing;
-
-    /**
-     * 染色日志目录路径
-     */
-    string              _dyeingFilePath;
-
-    /**
-     * 远程时间日志
-     */
-    DyeingTimeLogger    *_dyeingTimeLogger;
-
-    /**
-     * set分组信息
-     */
-    string               _setDivision;
-
-    /**
-     * 日志文件名是否带.log后缀
-     */
-    bool                 _hasSufix;
-    /**
-     * 是否允许框架在日志文件名上增加业务相关的标识
-     */
-    bool                  _hasAppNamePrefix;
-
-    /**
-     * 日志文件名中用户自定义字符与日期字符间的连接符,默认是"_"
-     */
-    string                  _concatStr;
-    /**
-     * 分隔符
-     */
-     string              _separ;
-    /**
-     * 日期部分是否加上[]
-     */
-     bool                  _hasSquareBracket;
-
-     /*
-      * 本地日志的记录类型,格式为TarsLogType.toString()返回值,如果不采用TarsLogType,则该值为""
-      */
-     string              _logType;
-     
-     /*
-     * 对于远程日志,上报同步到logser的成功量,默认不上报
-     */
-     PropertyReportPtr   _reportSuccPtr;
-
-     /*
-     * 对于远程日志,上报同步到logser的失败量,默认不上报
-     */
-     PropertyReportPtr   _reportFailPtr;
-}; 
-
-////////////////////////////////////////////////////////////////////////////
-/**
- * 远程日志帮助类, 单件
- */
-class TarsTimeLogger : public TC_HandleBase
-                    , public TC_ThreadLock
-                    , public TC_Singleton<TarsTimeLogger, CreateUsingNew, DefaultLifetime>
-{
-public:
-
-    //定义按时间滚动的日志
-    typedef TC_Logger<TimeWriteT, TC_RollByTime> TimeLogger;
-
-    /**
-     * 构造
-     */
-    TarsTimeLogger();
-
-    /**
-     * 析够
-     */
-    ~TarsTimeLogger();
-
-    /**
-     * 设置本地信息
-     * @param comm, 通信器
-     * @param obj, 日志对象名称
-     * @param app, 业务名称
-     * @param server, 服务名称
-     * @param logpath, 日志路径
-     */
-    void setLogInfo(const CommunicatorPtr &comm, const string &obj, const string &sApp, const string &sServer, const string &sLogpath,const string& setdivision="", const bool &bLogStatReport=false);
-
-    /**
-     * 初始化设置时间格式("%Y%m%d")
-     * 不要动态修改, 线程不安全
-     * 如果有需要, 初始化后直接修改
-     * @param sFormat, 文件名称, 为空表示缺省的时间日志
-     */
-    void initFormat(const string &sFile, const string &sFormat,const TarsLogTypePtr& logTypePtr=NULL);
-    void initFormat(const string &sApp, const string &sServer,const string &sFile, const string &sFormat,const TarsLogTypePtr& logTypePtr=NULL);
-    /**
-     * 初始化设置时间格式("%Y%m%d")
-     * 不要动态修改, 线程不安全
-     * 如果有需要, 初始化后直接修改
-     * @param sFormat, 文件名称, 为空表示缺省的时间日志
-     * @param frequency 支持每多少天/小时/分钟,详见TC_logger.h中关于TarsLogByDay,TarsLogByHour,TarsLogByMinute的描述
-     *
-     * 用法: 按两个小时记录日志
-     * initFormat<TarsLogByHour>("logfile",TarsLogByHour::FORMAT,2);
-     */
-    template<class TarsLogType>
-    void initFormatWithType(const string &sFile, const string &sFormat,size_t frequency)
-    {
-        TarsLogTypePtr logTypePtr = new TarsLogType(sFormat,frequency);
-        initFormat(sFile,sFormat,logTypePtr);
-    }
-
-    template<class TarsLogType>
-    void initFormatWithType(const string &sApp, const string &sServer,const string &sFile, const string &sFormat,size_t frequency)
-    {
-        TarsLogTypePtr logTypePtr = new TarsLogType(sFormat,frequency);
-        initFormat(sApp,sServer,sFile,sFormat,logTypePtr);
-    }
-    /**
-     * 获取时间日志
-     * @param file
-     */
-    TimeLogger *logger(const string &sFile = "");
-
-    /**
-     * 获取时间日志
-     * @param app, 业务名称
-     * @param server, 服务名称
-     * @param file
-     */
-    TimeLogger *logger(const string &sApp, const string &sServer,const string &sFile = "");
-
-    /**
-     * 同步写本地时间日志(远程日志一定是异步写的, 无法调整)
-     * @param bSync
-     */
-    void sync(const string &sFile, bool bSync);
-
-    /**
-     * 远程时间日志
-     * @param sFile, 文件名称, 为空表示缺省的时间日志
-     * @param bEnable
-     */
-    void enableRemote(const string &sFile, bool bEnable);
-
-    /**
-     * 远程时间日志
-     * @param sApp,应用名称
-     * @param sServer,服务名称
-     * @param sFile, 文件名称, 为空表示缺省的时间日志
-     * @param bEnable
-     */
-    void enableRemoteEx(const string &sApp, const string &sServer,const string &sFile, bool bEnable);
-    /**
-     * 本地时间日志
-     * @param sFile,文件名称, 为空表示缺省的时间日志
-     * @param bEnable
-     */
-    void enableLocal(const string &sFile, bool bEnable);
-    /**
-     * 本地时间日志
-     * @param sApp,应用名称
-     * @param sServer,服务名称
-     * @param sFile, 文件名称, 为空表示缺省的时间日志
-     * @param bEnable
-     */
-    void enableLocalEx(const string &sApp, const string &sServer,const string &sFile, bool bEnable);
-
-    /**
-     * @brief 日志文件名是否带.log后缀,影响全部日志文件
-     * @param bEnable
-     */
-    void enableSufix(bool bEnable=true){_hasSufix = bEnable;}
-    /**
-     * @brief 是否允许框架在日志文件名上增加业务相关的标识,影响全部日志文件
-     * @param bEnable
-     */
-    void enablePrefix(bool bEnable=true){_hasAppNamePrefix = bEnable;}
-    /**
-     * @brief 日志文件名中用户自定义字符与日期字符间的连接符,默认是"_",影响全部日志文件
-     * @param str
-     */
-    void setFileNameConcatStr(const string& str) {_concatStr = str;}
-
-    /**
-     * @brief 框架中增加的日志内容之间的分割符,默认是"|",影响全部日志文件
-     * @param str
-     */
-    void setSeparator(const string& str) {_separ = str;}
-
-    /**
-     * @brief 框架中日期和时间之间是否需要加中括号[],有些统计由特殊需求;默认不加,影响全部日志文件
-     * @param bEnable
-     */
-    void enableSqareWrapper(bool bEnable) {_hasSquareBracket = bEnable;}
-    /**
-     * @brief 是否输出本地日志文件,影响全部日志文件
-     * @param bEnable
-     */
-    void enableLocalLog(bool bEnable) {_local = bEnable;}
-    /**
-     * @brief 是否输出远程日志文件,影响全部日志文件
-     * @param bEnable
-     */
-    void enableRemoteLog(bool bEnable) {_remote = bEnable;}
-protected:
-
-    /**
-     * 初始化时间日志
-     * @param pTimeLogger
-     * @param sFile
-     * @param sFormat
-     * @param frequence, 每多少天/小时/分钟,单位是秒
-     */
-    void initTimeLogger(TimeLogger *pTimeLogger, const string &sFile, const string &sFormat,const TarsLogTypePtr& logTypePtr=NULL);
-
-    /**
-     * 初始化时间日志
-     * @param pTimeLogger
-     * @param sApp
-     * @param sServer
-     * @param sFile
-     * @param sFormat
-     * @param frequence, 每多少天/小时/分钟,单位是秒
-     */
-
-    void initTimeLogger(TimeLogger *pTimeLogger,const string &sApp, const string &sServer, const string &sFile, const string &sFormat,const TarsLogTypePtr& logTypePtr=NULL);
-
-protected:
-
-    /**
-     * 通信器
-     */
-    CommunicatorPtr         _comm;
-
-    /**
-     * 远程服务句柄
-     */
-    LogPrx                  _logPrx;
-
-    /**
-     * 应用
-     */
-    string                  _app;
-
-    /**
-     * 服务名称
-     */
-    string                  _server;
-
-    /**
-     * 日志路径
-     */
-    string                  _logpath;
-
-    /**
-     * 缺省按天日志
-     */
-    TimeLogger              *_defaultLogger;
-
-    /**
-     * 远程日志
-     */
-    map<string, TimeLogger*>  _loggers;
-    /**
-     * set分组信息
-     */
-    string                   _setDivision;
-
-    /**
-     * 是否带.log后缀
-     */
-    bool                     _hasSufix;
-    /**
-     * 是否允许框架在日志文件名上增加业务相关的标识
-     */
-    bool                      _hasAppNamePrefix;
-
-    /**
-     * 日志文件名中用户自定义字符与日期字符间的连接符,默认是"_"
-     */
-    string                      _concatStr;
-    /**
-     * 分隔符
-     */
-    string                   _separ;
-    /**
-     * 日期部分是否加上[]
-     */
-    bool                      _hasSquareBracket;
-    /**
-     * 是否输出本地日志
-     */
-    bool                     _local;
-    /**
-     * 是否输出远程日志
-     */
-    bool                     _remote;
-
-    /*
-    * 服务日志上报logser是否上报成功数量
-    */
-    bool                     _logStatReport;
-};
-
-/**
- * 染色开关类,析构时关闭
- */
-class TarsDyeingSwitch
-{
-public:
-    /**
-     * 构造函数,默认不打开染色日志
-     */
-    TarsDyeingSwitch()
-    :_needDyeing(false)
-    {
-    }
-
-    /**
-     * 析构函数,关闭已打开的染色日志
-     */
-    ~TarsDyeingSwitch()
-    {
-        if(_needDyeing)
-        {
-            TarsRollLogger::getInstance()->enableDyeing(false);
-
-            ServantProxyThreadData * td = ServantProxyThreadData::getData();
-            assert(NULL != td);
-            if (td)
-            {
-                td->_dyeing = false;
-                td->_dyeingKey = "";
-            }
-        }
-    }
-
-    /**
-     * 获取染色的key
-     *
-     * @param key
-     * @return bool
-     */
-    static bool getDyeingKey(string & sDyeingkey)
-    {
-        ServantProxyThreadData * td = ServantProxyThreadData::getData();
-        assert(NULL != td);
-
-        if (td && td->_dyeing == true)
-        {
-            sDyeingkey = td->_dyeingKey;
-            return true;
-        }
-        return false;
-    }
-
-    /**
-     * 启用染色日志
-     */
-    void enableDyeing(const string & sDyeingKey = "")
-    {
-        TarsRollLogger::getInstance()->enableDyeing(true);
-
-        ServantProxyThreadData * td = ServantProxyThreadData::getData();
-        assert(NULL != td);
-        if(td)
-
-        {
-            td->_dyeing       = true;
-            td->_dyeingKey = sDyeingKey;
-        }
-        _needDyeing = true;
-        _dyeingKey  = sDyeingKey;
-    }
-
-protected:
-    bool _needDyeing;
-    string _dyeingKey;
-};
-
-/**
- * 循环日志
- */
-#define LOG             (TarsRollLogger::getInstance()->logger())
-
-/**
- * @brief 按级别循环日志宏
- *
- * @param level 日志等级,TarsRollLogger::INFO_LOG,TarsRollLogger::DEBUG_LOG,TarsRollLogger::WARN_LOG,TarsRollLogger::ERROR_LOG
- * @msg 日志内容语句,包括<<重定向符连接的语句,如 "Demo begin" << " testing !" <<endl;
- *
- * @用法:
- *       标准输出流方式: cout << "I have " << vApple.size() << " apples!"<<endl;
- *       框架宏方式:     LOGMSG(TarsRollLogger::INFO_LOG,"I have " << vApple.size() << " apples!"<<endl);
- */
-#if TARGET_PLATFORM_WINDOWS
-#define LOGMSG(level,...) do{ if(LOG->isNeedLog(level)) LOG->log(level)<<__VA_ARGS__;}while(0)
-#else
-#define LOGMSG(level,msg...) do{ if(LOG->isNeedLog(level)) LOG->log(level)<<msg;}while(0)
-#endif
-
-/**
- * @brief 按级别循环日志
- *
- * @msg 日志内容语句,包括<<重定向符连接的语句,如 "Demo begin" << " testing !" <<endl;
- *
- * @用法:
- *       标准输出流方式: cout << "I have " << vApple.size() << " apples!"<<endl;
- *       框架宏方式:     TLOGINFO("I have " << vApple.size() << " apples!"<<endl);
- */
-#if TARGET_PLATFORM_WINDOWS
-#define TLOGINFO(...)    LOGMSG(TarsRollLogger::INFO_LOG,__VA_ARGS__)
-#define TLOGDEBUG(...)   LOGMSG(TarsRollLogger::DEBUG_LOG,__VA_ARGS__)
-#define TLOGWARN(...)    LOGMSG(TarsRollLogger::WARN_LOG,__VA_ARGS__)
-#define TLOGERROR(...)   LOGMSG(TarsRollLogger::ERROR_LOG,__VA_ARGS__)
-#define TLOGTARS(...)    LOGMSG(TarsRollLogger::TARS_LOG,__VA_ARGS__)
-#else
-#define TLOGINFO(msg...)    LOGMSG(TarsRollLogger::INFO_LOG,msg)
-#define TLOGDEBUG(msg...)   LOGMSG(TarsRollLogger::DEBUG_LOG,msg)
-#define TLOGWARN(msg...)    LOGMSG(TarsRollLogger::WARN_LOG,msg)
-#define TLOGERROR(msg...)   LOGMSG(TarsRollLogger::ERROR_LOG,msg)
-#define TLOGTARS(msg...)    LOGMSG(TarsRollLogger::TARS_LOG,msg)
-#endif
-
-/**
- * 按天日志
- */
-#define DLOG            (TarsTimeLogger::getInstance()->logger()->any())
-#define FDLOG(x)        (TarsTimeLogger::getInstance()->logger(x)->any())
-#define FFDLOG(x,y,z)   (TarsTimeLogger::getInstance()->logger(x,y,z)->any())
-
-/**
- *  按天日志局部使能开关,针对单个日志文件进行使能,请在所有按天日志输出前调用
- */
-#define TENREMOTE_FDLOG(swith,sApp,sServer,sFile) (TarsTimeLogger::getInstance()->enableRemoteEx(sApp,sServer,sFile,swith))
-#define TENLOCAL_FDLOG(swith,sApp,sServer,sFile)  (TarsTimeLogger::getInstance()->enableLocalEx(sApp,sServer,sFile,swith))
-
-/**
- * 按天日志全局使能开关,请在所有按天日志输出前调用
- */
-#define TENREMOTE(swith) (TarsTimeLogger::getInstance()->enableRemoteLog(swith))
-#define TENLOCAL(swith)  (TarsTimeLogger::getInstance()->enableLocalLog(swith))
-}
-
-#endif
-

+ 0 - 80
servant/servant/TarsNodeF.h

@@ -1,80 +0,0 @@
-/**
- * Tencent is pleased to support the open source community by making Tars available.
- *
- * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
- *
- * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 
- * in compliance with the License. You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- *
- * Unless required by applicable law or agreed to in writing, software distributed 
- * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
- * specific language governing permissions and limitations under the License.
- */
-
-#ifndef __TARS_NODEF_H__
-#define __TARS_NODEF_H__
-
-#include "servant/NodeF.h"
-#include "servant/Global.h"
-#include "util/tc_singleton.h"
-
-namespace tars
-{
-
-/**
- * 给node发送心跳
- * 调用keepAlive异步发送心跳给node
- */
-class TarsNodeFHelper : public TC_Singleton<TarsNodeFHelper>,public TC_ThreadMutex 
-{
-public:
-
-    /**
-     * 设置node信息
-     * @param comm, 通信器
-     * @param obj,
-     * @param app
-     * @param server
-     */
-    void setNodeInfo(const CommunicatorPtr &comm, const string &obj, const string &app, const string &server);
-
-    /**
-     * keepAlive
-     */
-    void keepAlive(const string &adapter = "");
-
-    void keepActiving();
-    
-    /**
-     * 上报TARS的编译版本
-     * @param version
-     */
-    void reportVersion(const string &version);
-
-protected:
-    /**
-     * 通信器
-     */
-    CommunicatorPtr _comm;
-
-    /**
-     * Node
-     */
-    ServerFPrx      _nodePrx;
-
-    /**
-     * 信息
-     */
-    ServerInfo      _si;
-
-    set<string>     _adapterSet;
-
-};
-
-}
-
-#endif
-

+ 0 - 101
servant/servant/TarsNotify.h

@@ -1,101 +0,0 @@
-/**
- * Tencent is pleased to support the open source community by making Tars available.
- *
- * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
- *
- * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 
- * in compliance with the License. You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- *
- * Unless required by applicable law or agreed to in writing, software distributed 
- * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
- * specific language governing permissions and limitations under the License.
- */
-
-#ifndef __TARS_NOTIFY_H_
-#define __TARS_NOTIFY_H_
-
-#include "servant/NotifyF.h"
-#include "servant/Global.h"
-#include "util/tc_singleton.h"
-
-using namespace std;
-
-namespace tars
-{
-
-/**
- * 上报信息给Notify服务
- * 异步上报给notify服务
- */
-class TarsRemoteNotify : public TC_Singleton<TarsRemoteNotify>
-{
-public:
-    /**
-     * 初始化
-     * @param comm, 通信器
-     * @param obj, 对象名称
-     * @param notifyPrx
-     * @param app
-     * @param serverName
-     *
-     * @return int
-     */
-    int setNotifyInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string &nodeName, const string &sSetName="");
-
-    /**
-     * 通知, 一定是异步上报的
-     * @param message
-     */
-    void notify(NOTIFYLEVEL level, const string &sMesage);
-
-    /**
-     * 上报
-     * @param sResult
-     * @param bSync
-     */
-    void report(const string &sResult, bool bSync = false);
-
-    /**
-     * 指定通知到某个服务, 一定是异步上报的
-     * @param message
-     */
-    void report(const string &sMesage, const string & app, const string &serverName, const string &sNodeName);
-
-protected:
-    /**
-     * 通信器
-     */
-    CommunicatorPtr _comm;
-
-    /**
-     * 通知代理
-     */
-    NotifyPrx       _notifyPrx;
-
-    /**
-     * 应用
-     */
-    string          _app;
-
-    /**
-     * 服务名称
-     */
-    string          _serverName;
-
-    /*
-    *set 名字
-    */
-    string          _setName;
-
-    /*
-    *节点
-    */
-    string          _nodeName;
-};
-
-}
-
-#endif

+ 2 - 2
servant/servant/Transceiver.h

@@ -183,8 +183,8 @@ public:
     /*
      * 获取端口信息
      */
-    EndpointInfo& getEndpointInfo()
-    { 
+    const EndpointInfo& getEndpointInfo() const
+    {
         return _ep;
     }
 

+ 4 - 4
tools/tars2node/gen_server_ts.cpp

@@ -38,7 +38,7 @@ string CodeGenerator::generateTSServerAsync(const NamespacePtr &nPtr, const Inte
         sParams += ": " + getTsType(vParamDecl[i]->getTypeIdPtr()->getTypePtr());
     }
 
-    str << TAB << "protected static __" << oPtr->getId() << "_responser(this: " << IDL_NAMESPACE_STR << "Rpc.TarsCurrent, " << sParams << ") {" << endl;
+    str << TAB << "protected static __" << oPtr->getId() << "_responser(this: " << IDL_NAMESPACE_STR << "Rpc.Current, " << sParams << ") {" << endl;
 
     INC_TAB;
 
@@ -105,7 +105,7 @@ string CodeGenerator::generateTSServerDispatch(const NamespacePtr &nPtr, const I
     ostringstream str;
     vector<ParamDeclPtr> & vParamDecl = oPtr->getAllParamDeclPtr();
 
-    str << TAB << "protected __" << oPtr->getId() << "(current: " << IDL_NAMESPACE_STR << "Rpc.TarsCurrent";
+    str << TAB << "protected __" << oPtr->getId() << "(current: " << IDL_NAMESPACE_STR << "Rpc.Current";
     if (vParamDecl.size() != 0) str << ", binBuffer: " << IDL_NAMESPACE_STR << "Stream.BinBuffer";
     str << ") {" << endl;
 
@@ -228,7 +228,7 @@ string CodeGenerator::generateTSServer(const InterfacePtr &pPtr, const Namespace
     str << TAB << "initialize(): PromiseLike<any> | void {}" << endl << endl;
 
     // generate the dispatch function
-    str << TAB << "onDispatch(current: " << IDL_NAMESPACE_STR << "Rpc.TarsCurrent, funcName: string, binBuffer: " << IDL_NAMESPACE_STR << "Stream.BinBuffer) { " << endl;
+    str << TAB << "onDispatch(current: " << IDL_NAMESPACE_STR << "Rpc.Current, funcName: string, binBuffer: " << IDL_NAMESPACE_STR << "Stream.BinBuffer) { " << endl;
     INC_TAB;
     str << TAB << "if (\"__\" + funcName in this) {" << endl;
     INC_TAB;
@@ -243,7 +243,7 @@ string CodeGenerator::generateTSServer(const InterfacePtr &pPtr, const Namespace
     str << TAB << "}" << endl << endl;
 
     // generate the ping function
-    str << TAB << "__" << TC_Common::lower(IDL_NAMESPACE_STR) << "_ping(current: " << IDL_NAMESPACE_STR << "Rpc.TarsCurrent) { " << endl;
+    str << TAB << "__" << TC_Common::lower(IDL_NAMESPACE_STR) << "_ping(current: " << IDL_NAMESPACE_STR << "Rpc.Current) { " << endl;
     INC_TAB;
     str << TAB << "const _ret = 0;" << endl;
     str << TAB << "if (current.getRequestVersion() === " << PROTOCOL_SIMPLE << " || current.getRequestVersion() === " << PROTOCOL_COMPLEX << ") {" << endl;

+ 18 - 18
tools/tarsparse/tars.lex.cpp

@@ -513,7 +513,7 @@ int yy_flex_debug = 0;
 #define YY_MORE_ADJ 0
 #define YY_RESTORE_YY_MORE_OFFSET
 char *yytext;
-#line 1 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 1 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 /**
  * Tencent is pleased to support the open source community by making Tars available.
  *
@@ -529,7 +529,7 @@ char *yytext;
  * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
  * specific language governing permissions and limitations under the License.
  */
-#line 20 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 20 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 #include <map>
 #include <string>
 #include <sstream>
@@ -742,7 +742,7 @@ YY_DECL
 	register char *yy_cp, *yy_bp;
 	register int yy_act;
     
-#line 67 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 67 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 
 
 #line 749 "tars.lex.cpp"
@@ -840,12 +840,12 @@ do_action:	/* This label is used only to access EOF actions. */
 
 case 1:
 YY_RULE_SETUP
-#line 69 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 69 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 { BEGIN(INCL); }
 	YY_BREAK
 case 2:
 YY_RULE_SETUP
-#line 71 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 71 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     if ( include_file_stack_ptr >= MAX_INCLUDE_DEPTH )
     {
@@ -878,7 +878,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(INCL):
-#line 101 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 101 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     --include_file_stack_ptr;
     if ( include_file_stack_ptr < 0 )
@@ -897,14 +897,14 @@ case YY_STATE_EOF(INCL):
 	YY_BREAK
 case 3:
 YY_RULE_SETUP
-#line 117 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 117 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     return TARS_SCOPE_DELIMITER;
 }
 	YY_BREAK
 case 4:
 YY_RULE_SETUP
-#line 121 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 121 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     // C++ comment
     bool e = false;
@@ -925,7 +925,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 5:
 YY_RULE_SETUP
-#line 139 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 139 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     // C comment
     bool e = false;
@@ -976,7 +976,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 6:
 YY_RULE_SETUP
-#line 187 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 187 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     StringGrammarPtr ident  = new StringGrammar;
     ident->v            = yytext;
@@ -987,7 +987,7 @@ YY_RULE_SETUP
 case 7:
 /* rule 7 can match eol */
 YY_RULE_SETUP
-#line 194 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 194 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     StringGrammarPtr ident  = new StringGrammar;
     ident->v            = yytext;
@@ -1000,7 +1000,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 8:
 YY_RULE_SETUP
-#line 204 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 204 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     StringGrammarPtr str = new StringGrammar;
     bool e = false;
@@ -1115,7 +1115,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 9:
 YY_RULE_SETUP
-#line 316 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 316 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     errno = 0;
     IntergerGrammarPtr ptr = new IntergerGrammar;
@@ -1140,7 +1140,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 10:
 YY_RULE_SETUP
-#line 338 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 338 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     errno = 0;
     FloatGrammarPtr ptr = new FloatGrammar;
@@ -1175,7 +1175,7 @@ YY_RULE_SETUP
 case 11:
 /* rule 11 can match eol */
 YY_RULE_SETUP
-#line 369 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 369 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     if(yytext[0] == '\n')
     {
@@ -1185,7 +1185,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 12:
 YY_RULE_SETUP
-#line 376 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 376 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     if(yytext[0] < 32 || yytext[0] > 126)
     {
@@ -1204,7 +1204,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 13:
 YY_RULE_SETUP
-#line 392 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 392 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 ECHO;
 	YY_BREAK
 #line 1211 "tars.lex.cpp"
@@ -2214,7 +2214,7 @@ void yyfree (void * ptr )
 
 #define YYTABLES_NAME "yytables"
 
-#line 392 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 392 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
 
 
 

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 132 - 132
tools/tarsparse/tars.tab.cpp


+ 2 - 2
util/include/util/tc_autoptr.h

@@ -18,7 +18,7 @@
 #define __TC_AUTOPTR_H
 
 #include "util/tc_ex.h"
-// #include "util/tc_atomic.h"
+#include "util/tc_platform.h"
 #include <atomic>
 #include <typeinfo> 
 
@@ -40,7 +40,7 @@ struct TC_AutoPtrNull_Exception : public TC_Exception
  *  所有需要智能指针支持的类都需要从该对象继承,
  *  
  */
-class TC_HandleBase
+class UTIL_DLL_API TC_HandleBase
 {
 public:
 

+ 12 - 12
util/include/util/tc_common.h

@@ -51,18 +51,18 @@ namespace tars
 */
 /////////////////////////////////////////////////
 
- /**
- * @brief  基础工具类,提供了一些非常基本的函数使用.
- *
- * 这些函数都是以静态函数提供。 包括以下几种函数:
- *
- * Trim类函数,大小写转换函数,分隔字符串函数(直接分隔字符串,
- *
- * 数字等),时间相关函数,字符串转换函数,二进制字符串互转函数,
- *
- * 替换字符串函数,Ip匹配函数,判断一个数是否是素数等
- */
-class TC_Common
+/**
+* @brief  基础工具类,提供了一些非常基本的函数使用.
+*
+* 这些函数都是以静态函数提供。 包括以下几种函数:
+*
+* Trim类函数,大小写转换函数,分隔字符串函数(直接分隔字符串,
+*
+* 数字等),时间相关函数,字符串转换函数,二进制字符串互转函数,
+*
+* 替换字符串函数,Ip匹配函数,判断一个数是否是素数等
+*/
+class UTIL_DLL_API TC_Common
 {
 public:
 

+ 6 - 6
util/include/util/tc_epoll_server.h

@@ -1170,6 +1170,12 @@ public:
 		 */
 		TC_NetWorkBuffer &getSendBuffer() { return _sendBuffer; }
 
+		/**
+		 * 发送buffer里面数据
+		 * @return
+		 */
+		int sendBuffer();
+
 	    friend class NetThread;
 
     protected:
@@ -1197,12 +1203,6 @@ public:
 		 */
 		int send(const shared_ptr<SendContext> &data);
 
-		/**
-		 * 发送buffer里面数据
-		 * @return
-		 */
-		int sendBuffer();
-
 		/**
 		 * 读取数据
 		 * @param fd

+ 1 - 2
util/include/util/tc_ex.h

@@ -107,8 +107,7 @@ private:
 //为了避免windows平台GetLastError()获取不对的问题, 因为抛异常, throw TC_Exception("xxxx", TC_Exception::getSystemCode())时
 //回调用系统函数分配内存, 导致错误码被改写, 因此专门定义宏来抛出异常
 //先获取到错误码, 再throw
-#define TARS_THROW_EXCEPTION(EX_CLASS, buffer) throw EX_CLASS(buffer)
-#define TARS_THROW_EXCEPTION_SYSCODE(EX_CLASS, buffer) \
+#define THROW_EXCEPTION_SYSCODE(EX_CLASS, buffer) \
     {   \
     int ret = TC_Exception::getSystemCode(); \
     throw EX_CLASS(buffer, ret);              \

+ 173 - 111
util/include/util/tc_http.h

@@ -343,6 +343,9 @@ protected:
 class TC_Http
 {
 public:
+	static unordered_map<string, int> HEADER;
+	static unordered_map<int, string> HEADER_REVERSE;
+
     /**
      * @brief  构造函数
      */
@@ -562,10 +565,25 @@ public:
     string getHeader(const string& sHeader) const;
 
     /**
-     * @brief 获取http头部map.
-     *
-     * @return http_header_type&
+     * 是否有header
+     * @param sHeader
+     * @return
+     */
+    bool hasHeader(const char *sHeader) const;
+
+    /**
+     * @brief 检查头部
+     * @param sHeader
+     * @param value
+     * @return
      */
+	bool checkHeader(const char *sHeader, const char *value) const;
+
+	/**
+	 * @brief 获取http头部map.
+	 *
+	 * @return http_header_type&
+	 */
     const http_header_type& getHeaders() const{return _headers;}
 
 	/**
@@ -579,82 +597,89 @@ public:
       */
     void reset();
 
-//    /**
-//     * @brief 读取一行.
-//     *
-//     * @param ppChar  读取位置指针
-//     * @return string 读取的内容
-//     */
-//    static string getLine(const char** ppChar);
-
-    /**
-     * @brief 读取一行.
-     *  
-     * @param ppChar   读取位置指针
-     * @param iBufLen  长度
-     * @return string  读取的内容
-     */
-//    static string getLine(const char** ppChar, int iBufLen);
-
     /**
-     * @brief 生成头部字符串(不包含第一行).
+     * @brief 生成头部字符串(不包含第一行), 直接累加到sHttpHeader后
      *
      * @return string:头部字符串
      */
-    string genHeader() const;
+    void genHeader(string &sHttpHeader) const;
 
     /**
-     * @brief 该http原始数据包是否是chunk编码格式.
-     * 
-     * @return bool:包含返回true,否则返回false
+     * @brief 生成头部字符串(不包含第一行)
+     * @return
      */
+	string genHeader() const;
+
+	/**
+	 * @brief 该http原始数据包是否是chunk编码格式.
+	 *
+	 * @return bool:包含返回true,否则返回false
+	 */
     bool isChunked() const { return _bIsChunked; }
 
     /**
      * @brief 解析请求head,不解析第一行,
      *        第一行请求包和响应包不一样, 后面的数据解析为map格式
-     * @param szBuffer 
+     * @param szBuffer
      * @return const char*, 偏移的指针
      */
 //    static const char* parseHeader(const char* szBuffer, http_header_type &sHeader);
+//
+//    template<typename ForwardIterator1, typename ForwardIterator2>
+//	static void parseHeader(const ForwardIterator1 &beginIt, const ForwardIterator2 &headerIt, http_header_type &sHeader)
+//	{
+//		sHeader.clear();
+//
+//		string sep      = "\r\n";
+//		string colon    = ":";
+//
+//		bool first      = true;
+//		auto lineStartIt= beginIt;
+//
+//		while (true)
+//		{
+//			auto it = std::search(lineStartIt, headerIt, sep.c_str(), sep.c_str() + sep.size());
+//			if(it == headerIt)
+//			{
+//				break;
+//			}
+//
+//			//first line ignore
+//			if(!first)
+//			{
+//				auto itF = std::search(lineStartIt, it, colon.c_str(), colon.c_str() + colon.size());
+//				if (itF != it)
+//				{
+//					string name;
+//					name.resize(itF - lineStartIt);
+//					std::copy(lineStartIt, itF, name.begin());
+//
+//					string value;
+//					value.resize(it - (itF + 1));
+//					std::copy(itF + 1, it, value.begin());
+//
+//					sHeader.insert(multimap<string, string>::value_type(TC_Common::trim(name, " "),
+//					                                                    TC_Common::trim(value, " ")));
+//
+//				}
+//			}
+//			else
+//			{
+//				first = false;
+//			}
+//
+//			lineStartIt = it + sep.size();
+//		}
+//	}
+
+	/**
+	 * 解析, 尽量避免内存copy, 提升效率
+	 * @param beginIt
+	 * @param headerIt
+	 * @param sHeader
+	 */
+	static size_t parseHeaderString(const char *beginIt, const char *headerIt, http_header_type &sHeader);
 
-    template<typename ForwardIterator1, typename ForwardIterator2>
-	static void parseHeader(const ForwardIterator1 &beginIt, const ForwardIterator2 &headerIt, http_header_type &sHeader)
-	{
-		sHeader.clear();
-		string sep      = "\r\n";
-		string colon    = ":";
-		bool first      = true;
-		auto lineStartIt= beginIt;
-		while (true)
-		{
-			auto it = std::search(lineStartIt, headerIt, sep.c_str(), sep.c_str() + sep.size());
-			if(it == headerIt)
-			{
-				break;
-			}
-			if(!first)
-			{
-				auto itF = std::search(lineStartIt, it, colon.c_str(), colon.c_str() + colon.size());
-				if (itF != it)
-				{
-					string name;
-					name.resize(itF - lineStartIt);
-					std::copy(lineStartIt, itF, name.begin());
-					string value;
-					value.resize(it - (itF + 1));
-					std::copy(itF + 1, it, value.begin());
-					sHeader.insert(multimap<string, string>::value_type(TC_Common::trim(name, " "),
-					                                                    TC_Common::trim(value, " ")));
-				}
-			}
-			else
-			{
-				first = false;
-			}
-			lineStartIt = it + sep.size();
-		}
-	}
 protected:
 
     /**
@@ -667,6 +692,11 @@ protected:
      */
     size_t              _headLength;
 
+	/**
+	 * 获取版本
+	 */
+	string  _version;
+
     /**
      * http头部内容
      */
@@ -989,45 +1019,67 @@ public:
 
     /**
      * @brief 解析应答头.
-     *  
+     *
      * @param szBuffer 应答头信息
      * @return
      */
-//    void parseResponseHeader(const char* szBuffer, const char* header);
-
-    template<typename ForwardIterator1, typename ForwardIterator2>
-	void parseResponseHeader(const ForwardIterator1 &beginIt, const ForwardIterator2 &headerIt)
-	{
-		string line = "\r\n";
-		auto it = std::search(beginIt, headerIt, line.c_str(), line.c_str() + line.size());
-		assert(it != headerIt);
-		string sep = " ";
-		auto f1 = std::search(beginIt, headerIt, sep.c_str(), sep.c_str() + sep.size());
-		if(f1 == headerIt)
-		{
-			throw TC_HttpResponse_Exception("[TC_HttpResponse_Exception::parseResponeHeader] http response parse version format error : " + string(beginIt, it));
-		}
-		auto f2 = std::search(f1 + 1, headerIt, sep.c_str(), sep.c_str() + sep.size());
-		if(f1 == headerIt)
-		{
-			throw TC_HttpResponse_Exception("[TC_HttpResponse_Exception::parseResponeHeader] http response parse status format error : " + string(beginIt, it));
-		}
-		_headerLine = string(beginIt, it);
-		if(TC_Port::strncasecmp(_headerLine.c_str(), "HTTP/", 5) != 0)
-		{
-			throw TC_HttpResponse_Exception("[TC_HttpResponse_Exception::parseResponeHeader] http response version is not start with 'HTTP/' : " + _headerLine);
-		}
-		_version    = string(beginIt, f1);
-		_status     = TC_Common::strto<int>(string(f1 + 1, f2));
-		_about      = TC_Common::trim(string(f2 + 1, it));
-		parseHeader(beginIt, headerIt, _headers);
-	}
+//    /**
+//     *
+//     * @param szBuffer
+//     */
+//    template<typename ForwardIterator1, typename ForwardIterator2>
+//	void parseResponseHeader(const ForwardIterator1 &beginIt, const ForwardIterator2 &headerIt)
+//	{
+//		string line = "\r\n";
+//
+//		auto it = std::search(beginIt, headerIt, line.c_str(), line.c_str() + line.size());
+//
+//		assert(it != headerIt);
+//
+//		string sep = " ";
+//
+//		auto f1 = std::search(beginIt, headerIt, sep.c_str(), sep.c_str() + sep.size());
+//		if(f1 == headerIt)
+//		{
+//			throw TC_HttpResponse_Exception("[TC_HttpResponse_Exception::parseResponeHeader] http response parse version format error : " + string(beginIt, it));
+//		}
+//
+//		auto f2 = std::search(f1 + 1, headerIt, sep.c_str(), sep.c_str() + sep.size());
+//		if(f1 == headerIt)
+//		{
+//			throw TC_HttpResponse_Exception("[TC_HttpResponse_Exception::parseResponeHeader] http response parse status format error : " + string(beginIt, it));
+//		}
+//
+//		_headerLine = string(beginIt, it);
+//
+//		if(TC_Port::strncasecmp(_headerLine.c_str(), "HTTP/", 5) != 0)
+//		{
+//			throw TC_HttpResponse_Exception("[TC_HttpResponse_Exception::parseResponeHeader] http response version is not start with 'HTTP/' : " + _headerLine);
+//		}
+//
+//		_version    = string(beginIt, f1);
+//
+//		_status     = TC_Common::strto<int>(string(f1 + 1, f2));
+//
+//		_about      = TC_Common::trim(string(f2 + 1, it));
+//
+//		parseHeader(beginIt, headerIt, _headers);
+//	}
+
+	size_t parseResponseHeaderString(const char *beginIt, const char *headerIt);
+
 protected:
     /**
-     * 添加内容, 增量解析用到
+     * 添加内容
      * @param sBuffer
      */
     void addContent(const string &sBuffer);
+
+    /**
+     * 添加内容
+     * @param buffer
+     * @param length
+     */
 	void addContent(const char *buffer, size_t length);
 
 protected:
@@ -1042,11 +1094,6 @@ protected:
      */
     string  _about;
 
-    /**
-     * 获取版本
-     */
-    string  _version;
-
     /**
      * 获取第一行
      */
@@ -1089,11 +1136,12 @@ public:
         REQUEST_PUT,
         REQUEST_DELETE,
         REQUEST_PATCH,
+	    REQUEST_PRI,
     };
 
     /**
      * @brief 检查http请求是否收全.
-     *  
+     *
      * @param sBuffer http请求
      * @throws TC_HttpRequest_Exception, 不支持的http协议, 抛出异常
      * @return  true: 收全, false:不全
@@ -1142,7 +1190,16 @@ public:
      */
     bool decode(const string &sBuffer);
 
-    /**
+	/**
+	* @brief 解析http请求, 如果不是HTTP请求则抛出异常.
+	*
+	* @param sBuffer 要解析的http请求
+	* @return        sBuffer是否是完整的http请求
+	* @throw         TC_HttpRequest_Exception
+	*/
+	bool decode(const vector<char> &sBuffer);
+
+	/**
      * @brief 解析http请求,
      *        如果不是HTTP请求则抛出异常(采用vector<char>方式).
      *  
@@ -1276,6 +1333,12 @@ public:
 	 */
 	void setRequestType(int requestType) {  _requestType = requestType ; }
 
+	/**
+	 * get method
+	 * @return
+	 */
+	const string &getMethod() const;
+
 	/**
 	 * set method
 	 * @param
@@ -1335,10 +1398,9 @@ public:
      * @return 是delete请求返回true,否则返回false
      */
     bool isDELETE() const { return _requestType == REQUEST_DELETE; }
-
     /**
      * @brief 获取请求的URL.
-     * 
+     *
      * @return const TC_URL&
      */
     const TC_URL &getURL() const { return _httpURL; }
@@ -1379,13 +1441,13 @@ public:
      */
     void parseRequestHeader(const char* szBuffer, const char *header);
 
-    /**
-     * @brief 请求类型到字符串.
-     *
-     * @param iRequestType  请求
-     * @return              解析后的字符串
-     */
-    string requestType2str(int iRequestType) const;
+//    /**
+//     * @brief 请求类型到字符串.
+//     *
+//     * @param iRequestType  请求
+//     * @return              解析后的字符串
+//     */
+//    const char *requestType2str(int iRequestType) const;
 
 protected:
 
@@ -1396,7 +1458,7 @@ protected:
      * @param iRequestType 编码后的输出流
      * @return void
      */
-    void encode(int iRequestType, ostream &os);
+//    void encode(int iRequestType, ostream &os);
 
     /**
      * @brief 解析URL

+ 5 - 4
util/include/util/tc_http2.h

@@ -198,11 +198,12 @@ public:
      * @param buff
      * @return
      */
-    int submit(const string &method, const string &path, const map<string, string> &header, const vector<char> &buff);
+//    int submit(const string &method, const string &path, const map<string, string> &header, const vector<char> &buff);
+	int submit(const TC_HttpRequest &request);
 
-    /**
-     * @brief response
-     */
+	/**
+	 * @brief response
+	 */
     std::unordered_map<int, shared_ptr<TC_HttpResponse>> &responses() { return _responses; }
 
     /** 

+ 19 - 18
util/include/util/tc_logger.h

@@ -134,7 +134,8 @@ namespace tars
 	/**
 	 * @brief 具体写日志基类
 	 */
-	class TC_LoggerRoll : public TC_HandleBase
+
+	class UTIL_DLL_API TC_LoggerRoll : public TC_HandleBase
 	{
 	public:
 		/**
@@ -1231,7 +1232,7 @@ namespace tars
 
 					//抛异常前继续进入_t 以便打远程日志
 					_t(_of, buffer);
-					TARS_THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollBySize::roll]:fopen fail: " + sLogFileName);
+					THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollBySize::roll]:fopen fail: " + sLogFileName);
 					// throw TC_Logger_Exception("[TC_RollBySize::roll]:fopen fail: " + sLogFileName, TC_Exception::getSystemCode());
 				}
 			}
@@ -1281,7 +1282,7 @@ namespace tars
 			_of.open(sLogFileName.c_str(), ios::app);
 			if (!_of)
 			{
-				TARS_THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollBySize::roll]:fopen fail: " + sLogFileName);
+				THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollBySize::roll]:fopen fail: " + sLogFileName);
 				// throw TC_Logger_Exception("[TC_RollBySize::roll]:fopen fail: " + sLogFileName, TC_Exception::getSystemCode());
 			}
 		}
@@ -1329,16 +1330,16 @@ namespace tars
 	/**
 	 * @brief 根据时间滚动日志分隔类型
 	 */
-	class TarsLogType : public TC_HandleBase
+	class LogType : public TC_HandleBase
 	{
 	public:
-		TarsLogType() : _next_time_t(0), _format("%Y%m%d"), _frequency(1), _des("day")
+		LogType() : _next_time_t(0), _format("%Y%m%d"), _frequency(1), _des("day")
 		{
 			_next_time_t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
 			_next_cut_time = TC_Common::tm2str(_next_time_t, "%Y%m%d");
 		}
 
-		virtual ~TarsLogType() {}
+		virtual ~LogType() {}
 		//频率值
 		virtual size_t frequence() = 0;
 
@@ -1391,15 +1392,15 @@ namespace tars
 		size_t _frequency;
 		string _des;
 	};
-	typedef TC_AutoPtr<TarsLogType> TarsLogTypePtr;
+	typedef TC_AutoPtr<LogType> LogTypePtr;
 
-	class TarsLogByDay : public TarsLogType
+	class LogByDay : public LogType
 	{
 	public:
 		static const string FORMAT;
 
 	public:
-		explicit TarsLogByDay(const string &format = "%Y%m%d", size_t frequency = 1)
+		explicit LogByDay(const string &format = "%Y%m%d", size_t frequency = 1)
 		{
 			init(format, frequency);
 			_des = TC_Common::tostr(_frequency) + "day";
@@ -1411,13 +1412,13 @@ namespace tars
 		}
 	};
 
-	class TarsLogByHour : public TarsLogType
+	class LogByHour : public LogType
 	{
 	public:
 		static const string FORMAT;
 
 	public:
-		explicit TarsLogByHour(const string &format = "%Y%m%d%H", size_t frequency = 1)
+		explicit LogByHour(const string &format = "%Y%m%d%H", size_t frequency = 1)
 		{
 			init(format, frequency);
 			_des = TC_Common::tostr(_frequency) + "hour";
@@ -1430,13 +1431,13 @@ namespace tars
 		}
 	};
 
-	class TarsLogByMinute : public TarsLogType
+	class LogByMinute : public LogType
 	{
 	public:
 		static const string FORMAT;
 
 	public:
-		explicit TarsLogByMinute(const string &format = "%Y%m%d%H%M", size_t frequency = 1)
+		explicit LogByMinute(const string &format = "%Y%m%d%H%M", size_t frequency = 1)
 		{
 			init(format, frequency);
 			_des = TC_Common::tostr(_frequency) + "minute";
@@ -1470,10 +1471,10 @@ namespace tars
 			 * @param format,日志文件记录格式,按天,小时,分钟
 			 * @param bHasSufix,日志文件是否添加".log"后缀
 			 * @param sConcatstr,日志路径和时间字串之间的连接符,例如:app_log/test_20121210.log
-			 * @param logTypePtr,日志记录类型,详见TarsLogType
+			 * @param logTypePtr,日志记录类型,详见LogType
 			 * @param bIsRemote,是否是远程日志实例
 			 */
-			void init(const string &path, const string &format = "%Y%m%d", bool bHasSufix = true, const string &sConcatstr = "_", const TarsLogTypePtr &logTypePtr = NULL, bool bIsRemote = false)
+			void init(const string &path, const string &format = "%Y%m%d", bool bHasSufix = true, const string &sConcatstr = "_", const LogTypePtr &logTypePtr = NULL, bool bIsRemote = false)
 			{
 				this->_roll->init(path, format, bHasSufix, sConcatstr, logTypePtr, bIsRemote);
 			}
@@ -1539,7 +1540,7 @@ namespace tars
 		 * @param bIsRemote
 		 */
 
-		void init(const string &path, const string &format = "%Y%m%d", bool bHasSufix = true, const string &sConcatstr = "_", const TarsLogTypePtr &logTypePtr = NULL, bool bIsRemote = false)
+		void init(const string &path, const string &format = "%Y%m%d", bool bHasSufix = true, const string &sConcatstr = "_", const LogTypePtr &logTypePtr = NULL, bool bIsRemote = false)
 		{
 			std::lock_guard<std::mutex> lock(*this);
 
@@ -1692,7 +1693,7 @@ namespace tars
 				{
 					//抛异常前继续进入_t 以便打远程日志
 					_t(_of, buffer);
-					TARS_THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollByTime::roll]:fopen fail: " + sLogFileName);
+					THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollByTime::roll]:fopen fail: " + sLogFileName);
 					// throw TC_Logger_Exception("[TC_RollByTime::roll]:fopen fail: " + sLogFileName, TC_Exception::getSystemCode());
 				}
 			}
@@ -1744,7 +1745,7 @@ namespace tars
 		 * 按天/小时/分钟输出日志时的记录类型
 		 */
 
-		TarsLogTypePtr _logTypePtr;
+		LogTypePtr _logTypePtr;
 		/**
 		 * 是否是远程日志实例
 		 */

+ 11 - 5
util/include/util/tc_network_buffer.h

@@ -368,11 +368,17 @@ public:
         }
     }
 
-    /**
-     * 获取connection, 不同服务模型中获取的对象不一样, 需要自己强制转换
-     * @param buff
-     */
-    void* getConnection() { return _connection; }
+	/**
+	 * 获取connection, 不同服务模型中获取的对象不一样, 需要自己强制转换
+	 * @param buff
+	 */
+	void* getConnection() { return _connection; }
+
+	/**
+	 * 获取connection, 不同服务模型中获取的对象不一样, 需要自己强制转换
+	 * @param buff
+	 */
+	void setConnection(void *connection) { _connection = connection; }
 
     /**
      * 设置上下文数据, 可以业务存放数据

+ 1 - 1
util/include/util/tc_openssl.h

@@ -77,7 +77,7 @@ public:
      * @param verifyClient
      * @return
      */
-	static shared_ptr<CTX> newCtx(const std::string& cafile, const std::string& certfile, const std::string& keyfile, bool verifyClient);
+	static shared_ptr<CTX> newCtx(const std::string& cafile, const std::string& certfile, const std::string& keyfile, bool verifyClient, const string &ciphers);
 
 	/**
 	 * new ssl

+ 39 - 0
util/include/util/tc_platform.h

@@ -43,4 +43,43 @@
 #include <unistd.h>
 #endif
 
+
+//UTIL 动态库编译的导入和导出
+#if TARGET_PLATFORM_WINDOWS
+
+#ifdef UTIL_DLL_EXPORT
+#define UTIL_DLL_API __declspec(dllexport)
+#else
+
+#ifdef UTIL_USE_DLL
+#define UTIL_DLL_API __declspec(dllimport)
+#else
+#define UTIL_DLL_API 
+#endif
+
+#endif
+
+#else
+#define UTIL_DLL_API 
+#endif
+
+//servant 动态库编译的导入和导出
+#if TARGET_PLATFORM_WINDOWS
+
+#ifdef SVT_DLL_EXPORT
+#define SVT_DLL_API __declspec(dllexport)
+#else
+
+#ifdef SVT_USE_DLL
+#define SVT_DLL_API __declspec(dllimport)
+#else
+#define SVT_DLL_API 
+#endif
+
+#endif
+
+#else
+#define SVT_DLL_API 
+#endif
+
 #endif

+ 72 - 37
util/include/util/tc_singleton.h

@@ -163,9 +163,35 @@ public:
     }
 };
 
+template<typename T>
+class CreateRealStatic
+{
+public:
+    /**
+	 * @brief   创建.
+     *
+     * @return T*
+     */
+    static T* create()
+    {
+        static T t;
+        return &t;
+    }
+
+    /**
+	 * @brief   释放.
+	 *
+     * @param t
+     */
+    static void destroy(T *t)
+    {
+    }
+};
+
 ////////////////////////////////////////////////////////////////
 /**
  * @brief 定义LifetimePolicy:定义对象的声明周期管理
+ * 进程退出时销毁对象
  */
 template<typename T>
 class DefaultLifetime
@@ -182,6 +208,12 @@ public:
     }
 };
 
+/**
+ * @brief,
+ *       对象被销毁后可以重生(比如log,全局任何时候都需要)
+ *
+ * @author jarod (7/29/2015)
+ */
 template<typename T>
 class PhoneixLifetime
 {
@@ -202,10 +234,15 @@ private:
 template <class T> 
 bool PhoneixLifetime<T>::_bDestroyedOnce = false; 
 
-template <typename T> 
-struct NoDestroyLifetime 
-{ 
-    static void scheduleDestruction(T*, void (*)()) 
+/**
+ * @brief 不做对象销毁
+ *
+ * @author jarod (7/29/2015)
+ */
+template <typename T>
+struct NoDestroyLifetime
+{
+    static void scheduleDestruction(T*, void (*)())
     {
     } 
 
@@ -237,56 +274,54 @@ public:
      */
     static T *getInstance()
     {
-        //加锁, 双check机制, 保证正确和效率
-        if(!_pInstance)
-        {
-            TC_ThreadLock::Lock lock(_tl);
-            if(!_pInstance)
-            {
-                if(_destroyed)
+        static std::mutex __mutex_singleton;
+
+        auto sin= __pInstance.load();
+        if ( !sin ){
+            std::lock_guard<std::mutex> myLock(__mutex_singleton);
+            sin= __pInstance.load();
+            if( !sin ){
+                if(__destroyed)
                 {
                     LifetimePolicy<T>::deadReference();
-                    _destroyed = false;
+                    __destroyed = false;
                 }
-                _pInstance = CreatePolicy<T>::create();
-                LifetimePolicy<T>::scheduleDestruction((T*)_pInstance, &destroySingleton);
+
+                sin = CreatePolicy<T>::create();
+                __pInstance.store(sin);
+                LifetimePolicy<T>::scheduleDestruction(__pInstance, &destroySingleton);
             }
         }
-        
-        return (T*)_pInstance;
+
+        return sin;
     }
-    
-protected:
 
+    virtual ~TC_Singleton(){};
+
+protected:
     static void destroySingleton()
     {
-        assert(!_destroyed);
-        CreatePolicy<T>::destroy((T*)_pInstance);
-        _pInstance = NULL;
-        _destroyed = true;
+        assert(!__destroyed);
+        CreatePolicy<T>::destroy((T*)__pInstance);
+        __pInstance = NULL;
+        __destroyed = true;
     }
 protected:
 
-    static TC_ThreadLock    _tl;
-    static volatile T*      _pInstance;
-    static bool             _destroyed;
+    static atomic<T*>       __pInstance;
+    static bool             __destroyed;
 
 protected:
-    TC_Singleton(){}
-    virtual ~TC_Singleton(){}; 
-    TC_Singleton (const TC_Singleton &); 
-    TC_Singleton &operator=(const TC_Singleton &);
+    TC_Singleton() = default;
+    TC_Singleton (const TC_Singleton &) = default;
+    TC_Singleton &operator=(const TC_Singleton &) = default;
 };
 
-template <class T, template<class> class CreatePolicy, template<class> class LifetimePolicy> 
-TC_ThreadLock TC_Singleton<T, CreatePolicy, LifetimePolicy>::_tl; 
-
-template <class T, template<class> class CreatePolicy, template<class> class LifetimePolicy> 
-bool TC_Singleton<T, CreatePolicy, LifetimePolicy>::_destroyed = false; 
-
-template <class T, template<class> class CreatePolicy, template<class> class LifetimePolicy> 
-volatile T* TC_Singleton<T, CreatePolicy, LifetimePolicy>::_pInstance = NULL; 
+template <class T, template<class> class CreatePolicy, template<class> class LifetimePolicy>
+bool TC_Singleton<T, CreatePolicy, LifetimePolicy>::__destroyed = false;
 
+template <class T, template<class> class CreatePolicy, template<class> class LifetimePolicy>
+atomic<T*> TC_Singleton<T, CreatePolicy, LifetimePolicy>::__pInstance = {nullptr};
 }
 
 #endif

+ 2 - 1
util/include/util/tc_spin_lock.h

@@ -2,6 +2,7 @@
 #ifndef __TC_SPIN_LOCK_H
 #define __TC_SPIN_LOCK_H
 
+#include "util/tc_platform.h"
 #include <atomic>
 #include <memory>
 
@@ -15,7 +16,7 @@ namespace tars
  * 不能阻塞wait, 只能快速加解锁, 适用于锁粒度非常小的情况, 减小线程切换的开销
  * 不支持trylock
  */
-class TC_SpinLock
+class UTIL_DLL_API TC_SpinLock
 {
 public:
 

+ 5 - 4
util/include/util/tc_thread_mutex.h

@@ -18,6 +18,7 @@
 #define __TC_THREAD_MUTEX_H
 
 #include "util/tc_lock.h"
+#include "util/tc_platform.h"
 #include <mutex>
 #include <atomic>
 
@@ -41,7 +42,7 @@ class TC_ThreadCond;
 *  
 * 通常不直接使用,和TC_Monitor配合使用,即TC_ThreadLock; 
 */
-class TC_ThreadMutex
+class UTIL_DLL_API TC_ThreadMutex
 {
 public:
 
@@ -68,8 +69,8 @@ public:
 protected:
 
     // noncopyable
-    TC_ThreadMutex(const TC_ThreadMutex&);
-    void operator=(const TC_ThreadMutex&);
+    TC_ThreadMutex(const TC_ThreadMutex&) = delete;
+    void operator=(const TC_ThreadMutex&) = delete;
 
     friend class TC_ThreadCond;
 
@@ -82,7 +83,7 @@ protected:
 *  
 * 采用线程库实现
 **/
-class TC_ThreadRecMutex
+class UTIL_DLL_API TC_ThreadRecMutex
 {
 public:
 

+ 2 - 1
util/include/util/tc_thread_rwlock.h

@@ -20,6 +20,7 @@
 #include <mutex>
 #include <condition_variable>
 #include "util/tc_lock.h"
+#include "util/tc_platform.h"
 #include <functional>
 
 using namespace std;
@@ -36,7 +37,7 @@ namespace tars
 
 /////////////////////////////////////////////////
 
-class TC_ThreadRWLocker
+class UTIL_DLL_API TC_ThreadRWLocker
 {
 protected:
 

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels