Sfoglia il codice sorgente

change pause to wait_group and update some codes

liyingxin 2 anni fa
parent
commit
782112b533

+ 35 - 15
docs/en/rpc.md

@@ -8,14 +8,14 @@
 | Thrift Binary HttpTransport | Thrift    | HTTP          | Binary       | Not supported        | Not supported | Supported        | Not supported | Not supported |
 | GRPC                        | PB        | HTTP2         | Binary       | gzip/zlib/lz4/snappy | Supported     | Not supported    | Supported     | Supported     |
 | BRPC Std                    | PB        | TCP           | Binary       | gzip/zlib/lz4/snappy | Supported     | Not supported    | Supported     | Supported     |
-| SogouRPC Std                | PB/Thrift | TCP           | Binary/JSON  | gzip/zlib/lz4/snappy | Supported     | Supported        | Supported     | Not supported |
-| SogouRPC Std HTTP           | PB/Thrift | HTTP          | Binary/JSON  | gzip/zlib/lz4/snappy | Supported     | Supported        | Supported     | Not supported |
+| SRPC Std                | PB/Thrift | TCP           | Binary/JSON  | gzip/zlib/lz4/snappy | Supported     | Supported        | Supported     | Not supported |
+| SRPC Std HTTP           | PB/Thrift | HTTP          | Binary/JSON  | gzip/zlib/lz4/snappy | Supported     | Supported        | Supported     | Not supported |
 | tRPC Std                    | PB        | TCP           | Binary/JSON  | gzip/zlib/lz4/snappy | Supported     | Supported        | Supported     | Not supported |
 
 ## Basic concepts
 
 - Communication layer: TCP/TPC\_SSL/HTTP/HTTPS/HTTP2
-- Protocol layer: Thrift-binary/BRPC-std/SogouRPC-std/tRPC-std
+- Protocol layer: Thrift-binary/BRPC-std/SRPC-std/tRPC-std
 - Compression layer: no compression/gzip/zlib/lz4/snappy
 - Data layer: PB binary/Thrift binary/JSON string
 - IDL serialization layer: PB/Thrift serialization
@@ -93,7 +93,7 @@ service Example {
 
 ## RPC Service
 
-- It is the basic unit for sogouRPC services.
+- It is the basic unit for SRPC services.
 - Each service must be generated by one type of IDLs.
 - Service is determined by IDL type, not by specific network communication protocol.
 
@@ -103,7 +103,7 @@ You can follow the detailed example below:
 
 - Use the same `example.proto` IDL above.
 - Run the official `protoc example.proto --cpp_out=./ --proto_path=./` to get two files: `example.pb.h` and `example.pb.cpp`.
-- Run the `srpc_generator protobuf ./example.proto ./` in SogouRPC to get `example.srpc.h`.
+- Run the `srpc_generator protobuf ./example.proto ./` in SRPC to get `example.srpc.h`.
 - Derive `Example::Service` to implement the rpc business logic, which is an RPC Service.
 - Please note that this Service does not involve any concepts such as network, port, communication protocol, etc., and it is only responsible for completing the business logic that convert `EchoRequest` to `EchoResponse`.
 
@@ -141,8 +141,8 @@ You can follow the detailed example below:
 - Imagine that we can also derive more Serivce from `Example::Service`, which have different implementations of rpc `Echo`.
 - Imagine that we can create N different RPC Servers on N different ports, serving on different network protocols.
 - Imagine that we can use `add_service()` to add the same ServiceIMPL instance on different Servers, or we can use `add_service()` to add different ServiceIMPL instances on the same server.
-- Imagine that we can use the same `ExampleServiceImpl`, serving BPRC-STD, SogouRPC-STD, SogouRPC-Http at three different ports at the same time.
-- And we can use `add_service()` to add one `ExampleServiceImpl` related to Protobuf IDL and one `AnotherThriftServiceImpl` related to Thrift IDL to the same SogouRPC-STD Server, and the two IDLs work perfectly on the same port!
+- Imagine that we can use the same `ExampleServiceImpl`, serving BPRC-STD, SRPC-STD, SRPC-Http at three different ports at the same time.
+- And we can use `add_service()` to add one `ExampleServiceImpl` related to Protobuf IDL and one `AnotherThriftServiceImpl` related to Thrift IDL to the same SRPC-STD Server, and the two IDLs work perfectly on the same port!
 
 ~~~cpp
 int main()
@@ -151,6 +151,8 @@ int main()
     SRPCHttpServer server_srpc_http;
     BRPCServer server_brpc;
     ThriftServer server_thrift;
+    TRPCServer server_trpc;
+    TRPCHttpServer server_trpc_http;
 
     ExampleServiceImpl impl_pb;
     AnotherThriftServiceImpl impl_thrift;
@@ -161,12 +163,19 @@ int main()
     server_srpc_http.add_service(&impl_thrift);
     server_brpc.add_service(&impl_pb);
     server_thrift.add_service(&impl_thrift);
+    server_trpc.add_service(&impl_pb);
+    server_trpc_http.add_service(&impl_pb);
 
     server_srpc.start(1412);
     server_srpc_http.start(8811);
     server_brpc.start(2020);
     server_thrift.start(9090);
-    pause();
+    server_trpc.start(2022);
+    server_trpc_http.start(8822);
+
+    getchar();
+    server_trpc_http.stop();
+    server_trpc.stop();
     server_thrift.stop();
     server_brpc.stop();
     server_srpc_http.stop();
@@ -194,6 +203,7 @@ You can follow the detailed example below:
 ~~~cpp
 #include <stdio.h>
 #include "example.srpc.h"
+#include "workflow/WFFacilities.h"
 
 using namespace srpc;
 
@@ -201,18 +211,21 @@ int main()
 {
     Example::SRPCClient client("127.0.0.1", 1412);
     EchoRequest req;
-    req.set_message("Hello, sogou rpc!");
-    req.set_name("Li Yingxin");
+    req.set_message("Hello!");
+    req.set_name("SRPCClient");
+
+    WFFacilities::WaitGroup wait_group(1);
 
-    client.Echo(&req, [](EchoResponse *response, RPCContext *ctx) {
+    client.Echo(&req, [&wait_group](EchoResponse *response, RPCContext *ctx) {
         if (ctx->success())
             printf("%s\n", response->DebugString().c_str());
         else
             printf("status[%d] error[%d] errmsg:%s\n",
                     ctx->get_status_code(), ctx->get_error(), ctx->get_errmsg());
+        wait_group.done();
     });
 
-    pause();
+    wait_group.wait();
     return 0;
 }
 ~~~
@@ -476,13 +489,20 @@ int main()
     auto *calc_task = WFTaskFactory::create_go_task(calc, 3, 4);
 
     EchoRequest req;
-    req.set_message("Hello, sogou rpc!");
+    req.set_message("Hello!");
     req.set_name("1412");
     rpc_task->serialize_input(&req);
 
-    ((*http_task * rpc_task) > calc_task).start();
+    WFFacilities::WaitGroup wait_group(1);
+
+    SeriesWork *series = Workflow::create_series_work(http_task, [&wait_group](const SeriesWork *) {
+        wait_group.done();
+    });
+    series->push_back(rpc_task);
+    series->push_back(calc_task);
+    series->start();
 
-    pause();
+    wait_group.wait();
     return 0;
 }
 ~~~

+ 2 - 2
docs/en/tutorial-02-service.md

@@ -2,7 +2,7 @@
 
 ## RPC Service
 
-- It is the basic unit for sogouRPC services.
+- It is the basic unit for SRPC services.
 - Each service must be generated by one type of IDLs.
 - Service is determined by IDL type, not by specific network communication protocol.
 
@@ -12,7 +12,7 @@ You can follow the detailed example below:
 
 - Use the same `example.proto` IDL above.
 - Run the official `protoc example.proto --cpp_out=./ --proto_path=./` to get two files: `example.pb.h` and `example.pb.cpp`.
-- Run the `srpc_generator protobuf ./example.proto ./` in SogouRPC to get `example.srpc.h`.
+- Run the `srpc_generator protobuf ./example.proto ./` in SRPC to get `example.srpc.h`.
 - Derive `Example::Service` to implement the rpc business logic, which is an RPC Service.
 - Please note that this Service does not involve any concepts such as network, port, communication protocol, etc., and it is only responsible for completing the business logic that convert `EchoRequest` to `EchoResponse`.
 

+ 12 - 3
docs/en/tutorial-03-server.md

@@ -19,8 +19,8 @@ You can follow the detailed example below:
 - Imagine that we can also derive more Serivce from `Example::Service`, which have different implementations of rpc `Echo`.
 - Imagine that we can create N different RPC Servers on N different ports, serving on different network protocols.
 - Imagine that we can use `add_service()` to add the same ServiceIMPL instance on different Servers, or we can use `add_service()` to add different ServiceIMPL instances on the same server.
-- Imagine that we can use the same `ExampleServiceImpl`, serving BPRC-STD, SogouRPC-STD, SogouRPC-Http at three different ports at the same time.
-- And we can use `add_service()` to add one `ExampleServiceImpl` related to Protobuf IDL and one `AnotherThriftServiceImpl` related to Thrift IDL to the same SogouRPC-STD Server, and the two IDLs work perfectly on the same port!
+- Imagine that we can use the same `ExampleServiceImpl`, serving BPRC-STD, SRPC-STD, SRPC-Http at three different ports at the same time.
+- And we can use `add_service()` to add one `ExampleServiceImpl` related to Protobuf IDL and one `AnotherThriftServiceImpl` related to Thrift IDL to the same SRPC-STD Server, and the two IDLs work perfectly on the same port!
 
 ~~~cpp
 int main()
@@ -29,6 +29,8 @@ int main()
     SRPCHttpServer server_srpc_http;
     BRPCServer server_brpc;
     ThriftServer server_thrift;
+    TRPCServer server_trpc;
+    TRPCHttpServer server_trpc_http;
 
     ExampleServiceImpl impl_pb;
     AnotherThriftServiceImpl impl_thrift;
@@ -39,12 +41,19 @@ int main()
     server_srpc_http.add_service(&impl_thrift);
     server_brpc.add_service(&impl_pb);
     server_thrift.add_service(&impl_thrift);
+    server_trpc.add_service(&impl_pb);
+    server_trpc_http.add_service(&impl_pb);
 
     server_srpc.start(1412);
     server_srpc_http.start(8811);
     server_brpc.start(2020);
     server_thrift.start(9090);
-    pause();
+	server_trpc.start(2022);
+	server_trpc_http.start(8822);
+	
+    getchar();
+	server_trpc_http.stop();
+	server_trpc.stop();
     server_thrift.stop();
     server_brpc.stop();
     server_srpc_http.stop();

+ 8 - 4
docs/en/tutorial-04-client.md

@@ -18,6 +18,7 @@ You can follow the detailed example below:
 ~~~cpp
 #include <stdio.h>
 #include "example.srpc.h"
+#include "workflow/WFFacilities.h"
 
 using namespace srpc;
 
@@ -25,18 +26,21 @@ int main()
 {
     Example::SRPCClient client("127.0.0.1", 1412);
     EchoRequest req;
-    req.set_message("Hello, sogou rpc!");
-    req.set_name("Li Yingxin");
+    req.set_message("Hello!");
+    req.set_name("SRPCClient");
 
-    client.Echo(&req, [](EchoResponse *response, RPCContext *ctx) {
+    WFFacilities::WaitGroup wait_group(1);
+
+    client.Echo(&req, [&wait_group](EchoResponse *response, RPCContext *ctx) {
         if (ctx->success())
             printf("%s\n", response->DebugString().c_str());
         else
             printf("status[%d] error[%d] errmsg:%s\n",
                     ctx->get_status_code(), ctx->get_error(), ctx->get_errmsg());
+        wait_group.done();
     });
 
-    pause();
+    wait_group.wait();
     return 0;
 }
 ~~~

+ 10 - 3
docs/en/tutorial-06-workflow.md

@@ -89,13 +89,20 @@ int main()
     auto *calc_task = WFTaskFactory::create_go_task(calc, 3, 4);
 
     EchoRequest req;
-    req.set_message("Hello, sogou rpc!");
+    req.set_message("Hello!");
     req.set_name("1412");
     rpc_task->serialize_input(&req);
 
-    ((*http_task * rpc_task) > calc_task).start();
+    WFFacilities::WaitGroup wait_group(1);
 
-    pause();
+    SeriesWork *series = Workflow::create_series_work(http_task, [&wait_group](const SeriesWork *) {
+        wait_group.done();
+    });
+    series->push_back(rpc_task);
+    series->push_back(calc_task);
+    series->start();
+
+    wait_group.wait();
     return 0;
 }
 ~~~

+ 1 - 1
docs/en/tutorial-07-http.md

@@ -146,7 +146,7 @@ int main()
 {
     Example::SRPCClient client("127.0.0.1", 1412);
     EchoRequest req;
-    req.set_message("Hello, sogou rpc!");
+    req.set_message("Hello, srpc!");
 
     auto *task = client.create_Echo_task([](EchoResponse *resp, RPCContext *ctx) {                                                                              
         if (ctx->success())

+ 34 - 14
docs/rpc.md

@@ -7,13 +7,13 @@
 |Thrift Binary HttpTransport| Thrift    | http | 二进制      |不支持               | 不支持      |  支持    | 不支持  |  不支持      |
 |GRPC                       | PB        | http2| 二进制      |gzip/zlib/lz4/snappy| 支持        |  不支持  | 支持    |  支持       |
 |BRPC Std                   | PB        | tcp  | 二进制      |gzip/zlib/lz4/snappy| 支持        |  不支持  | 支持    |  支持       |
-|SogouRPC Std               | PB/Thrift | tcp  | 二进制/JSON |gzip/zlib/lz4/snappy| 支持        |  支持    | 支持    |  不支持     |
-|SogouRPC Std Http          | PB/Thrift | http | 二进制/JSON |gzip/zlib/lz4/snappy| 支持        |  支持    | 支持    |  不支持     |
+|SRPC Std               | PB/Thrift | tcp  | 二进制/JSON |gzip/zlib/lz4/snappy| 支持        |  支持    | 支持    |  不支持     |
+|SRPC Std Http          | PB/Thrift | http | 二进制/JSON |gzip/zlib/lz4/snappy| 支持        |  支持    | 支持    |  不支持     |
 |tRPC Std                   | PB        | tcp  | 二进制/JSON |gzip/zlib/lz4/snappy| 支持        |  支持    | 支持    |  不支持     |
 
 ## 基础概念
 - 通信层:TCP/TPC_SSL/HTTP/HTTPS/HTTP2
-- 协议层:Thrift-binary/BRPC-std/SogouRPC-std/tRPC-std
+- 协议层:Thrift-binary/BRPC-std/SRPC-std/tRPC-std
 - 压缩层:不压缩/gzip/zlib/lz4/snappy
 - 数据层:PB binary/Thrift binary/Json string
 - IDL序列化层:PB/Thrift serialization
@@ -85,7 +85,7 @@ service Example {
 ~~~
 
 ## RPC Service
-- 组成sogouRPC服务的基本单元
+- 组成SRPC服务的基本单元
 - 每一个Service一定由某一种IDL生成
 - Service由IDL决定,与网络通信具体协议无关
 
@@ -93,7 +93,7 @@ service Example {
 下面我们通过一个具体例子来呈现
 - 沿用上面的``example.proto``IDL描述文件
 - 执行官方的``protoc example.proto --cpp_out=./ --proto_path=./``获得``example.pb.h``和``example.pb.cpp``两个文件
-- 执行SogouRPC的``srpc_generator protobuf ./example.proto ./``获得``example.srpc.h``文件
+- 执行SRPC的``srpc_generator protobuf ./example.proto ./``获得``example.srpc.h``文件
 - 我们派生``Example::Service``来实现具体的rpc业务逻辑,这就是一个RPC Service
 - 注意这个Service没有任何网络、端口、通信协议等概念,仅仅负责完成实现从``EchoRequest``输入到输出``EchoResponse``的业务逻辑
 
@@ -129,8 +129,8 @@ public:
 - 想像一下,我们也可以从``Example::Service``派生出多个Service,而它们的rpc``Echo``实现的功能可以不同
 - 想像一下,我们可以在N个不同的端口创建N个不同的RPC Server,代表着不同的协议
 - 想像一下,我们可以把同一个ServiceIMPL实例``add_service()``到不同的Server上,我们也可以把不同的ServiceIMPL实例``add_service``到同一个Server上
-- 想像一下,我们可以用同一个``ExampleServiceImpl``,在三个不同端口、同时服务于BPRC-STD、SogouRPC-STD、SogouRPC-Http
-- 甚至,我们可以将1个Protobuf IDL相关的``ExampleServiceImpl``和1个Thrift IDL相关的``AnotherThriftServiceImpl``,``add_service``到同一个SogouRPC-STD Server,两种IDL在同一个端口上完美工作!
+- 想像一下,我们可以用同一个``ExampleServiceImpl``,在三个不同端口、同时服务于BPRC-STD、SRPC-STD、SRPC-Http
+- 甚至,我们可以将1个Protobuf IDL相关的``ExampleServiceImpl``和1个Thrift IDL相关的``AnotherThriftServiceImpl``,``add_service``到同一个SRPC-STD Server,两种IDL在同一个端口上完美工作!
 
 ~~~cpp
 int main()
@@ -139,6 +139,8 @@ int main()
     SRPCHttpServer server_srpc_http;
     BRPCServer server_brpc;
     ThriftServer server_thrift;
+    TRPCServer server_trpc;
+    TRPCHttpServer server_trpc_http;
 
     ExampleServiceImpl impl_pb;
     AnotherThriftServiceImpl impl_thrift;
@@ -149,12 +151,19 @@ int main()
     server_srpc_http.add_service(&impl_thrift);
     server_brpc.add_service(&impl_pb);
     server_thrift.add_service(&impl_thrift);
+    server_trpc.add_service(&impl_pb);
+    server_trpc_http.add_service(&impl_pb);
 
     server_srpc.start(1412);
     server_srpc_http.start(8811);
     server_brpc.start(2020);
     server_thrift.start(9090);
+    server_trpc.start(2022);
+    server_trpc_http.start(8822);
+
     getchar();
+    server_trpc_http.stop();
+    server_trpc.stop();
     server_thrift.stop();
     server_brpc.stop();
     server_srpc_http.stop();
@@ -179,6 +188,7 @@ int main()
 ~~~cpp
 #include <stdio.h>
 #include "example.srpc.h"
+#include "workflow/WFFacilities.h"
 
 using namespace srpc;
 
@@ -186,18 +196,21 @@ int main()
 {
     Example::SRPCClient client("127.0.0.1", 1412);
     EchoRequest req;
-    req.set_message("Hello, sogou rpc!");
-    req.set_name("Li Yingxin");
+    req.set_message("Hello!");
+    req.set_name("SRPCClient");
+
+    WFFacilities::WaitGroup wait_group(1);
 
-    client.Echo(&req, [](EchoResponse *response, RPCContext *ctx) {
+    client.Echo(&req, [&wait_group](EchoResponse *response, RPCContext *ctx) {
         if (ctx->success())
             printf("%s\n", response->DebugString().c_str());
         else
             printf("status[%d] error[%d] errmsg:%s\n",
                     ctx->get_status_code(), ctx->get_error(), ctx->get_errmsg());
+        wait_group.done();
     });
 
-    getchar();
+    wait_group.wait();
     return 0;
 }
 ~~~
@@ -418,13 +431,20 @@ int main()
     auto *calc_task = WFTaskFactory::create_go_task(calc, 3, 4);
 
     EchoRequest req;
-    req.set_message("Hello, sogou rpc!");
+    req.set_message("Hello!");
     req.set_name("1412");
     rpc_task->serialize_input(&req);
 
-    ((*http_task * rpc_task) > calc_task).start();
+    WFFacilities::WaitGroup wait_group(1);
 
-    getchar();
+    SeriesWork *series = Workflow::create_series_work(http_task, [&wait_group](const SeriesWork *) {
+        wait_group.done();
+    });
+    series->push_back(rpc_task);
+    series->push_back(calc_task);
+    series->start();
+
+    wait_group.wait();
     return 0;
 }
 ~~~

+ 2 - 2
docs/tutorial-02-service.md

@@ -1,7 +1,7 @@
 [English version](/docs/en/tutorial-02-service.md)
 
 ## RPC Service
-- 组成sogouRPC服务的基本单元
+- 组成SRPC服务的基本单元
 - 每一个Service一定由某一种IDL生成
 - Service只与IDL有关,与网络通信具体协议无关
 
@@ -9,7 +9,7 @@
 下面我们通过一个具体例子来呈现
 - 沿用上面的``example.proto``IDL描述文件
 - 执行官方的``protoc example.proto --cpp_out=./ --proto_path=./``获得``example.pb.h``和``example.pb.cpp``两个文件
-- 执行SogouRPC的``srpc_generator protobuf ./example.proto ./``获得``example.srpc.h``文件
+- 执行SRPC的``srpc_generator protobuf ./example.proto ./``获得``example.srpc.h``文件
 - 我们派生``Example::Service``来实现具体的rpc业务逻辑,这就是一个RPC Service
 - 注意这个Service没有任何网络、端口、通信协议等概念,仅仅负责完成实现从``EchoRequest``输入到输出``EchoResponse``的业务逻辑
 

+ 12 - 3
docs/tutorial-03-server.md

@@ -16,8 +16,8 @@
 - 想像一下,我们也可以从``Example::Service``派生更多的功能的rpc``Echo``不同实现的Service
 - 想像一下,我们可以在N个不同的端口创建N个不同的RPC Server、代表着不同的协议
 - 想像一下,我们可以把同一个ServiceIMPL实例``add_service``到不同的Server上,我们也可以把不同的ServiceIMPL实例``add_service``到同一个Server上
-- 想像一下,我们可以用同一个``ExampleServiceImpl``,在三个不同端口、同时服务于BPRC-STD、SogouRPC-STD、SogouRPC-Http
-- 甚至,我们可以将1个PB的``ExampleServiceImpl``和1个Thrift的``AnotherThriftServiceImpl``,``add_service``到同一个SogouRPC-STD Server,两种IDL在同一个端口上完美工作!
+- 想像一下,我们可以用同一个``ExampleServiceImpl``,在三个不同端口、同时服务于BPRC-STD、SRPC-STD、SRPC-Http
+- 甚至,我们可以将1个PB的``ExampleServiceImpl``和1个Thrift的``AnotherThriftServiceImpl``,``add_service``到同一个SRPC-STD Server,两种IDL在同一个端口上完美工作!
 
 ~~~cpp
 int main()
@@ -26,6 +26,8 @@ int main()
     SRPCHttpServer server_srpc_http;
     BRPCServer server_brpc;
     ThriftServer server_thrift;
+    TRPCServer server_trpc;
+    TRPCHttpServer server_trpc_http;
 
     ExampleServiceImpl impl_pb;
     AnotherThriftServiceImpl impl_thrift;
@@ -36,12 +38,19 @@ int main()
     server_srpc_http.add_service(&impl_thrift);
     server_brpc.add_service(&impl_pb);
     server_thrift.add_service(&impl_thrift);
+    server_trpc.add_service(&impl_pb);
+    server_trpc_http.add_service(&impl_thrift);
 
     server_srpc.start(1412);
     server_srpc_http.start(8811);
     server_brpc.start(2020);
     server_thrift.start(9090);
-    pause();
+    server_trpc.start(2022);
+    server_trpc_http.start(8822);
+    
+    getchar();
+    server_trpc_http.stop();
+    server_trpc.stop();
     server_thrift.stop();
     server_brpc.stop();
     server_srpc_http.stop();

+ 8 - 4
docs/tutorial-04-client.md

@@ -15,6 +15,7 @@
 ~~~cpp
 #include <stdio.h>
 #include "example.srpc.h"
+#include "workflow/WFFacilities.h"
 
 using namespace srpc;
 
@@ -22,18 +23,21 @@ int main()
 {
     Example::SRPCClient client("127.0.0.1", 1412);
     EchoRequest req;
-    req.set_message("Hello, sogou rpc!");
-    req.set_name("Li Yingxin");
+    req.set_message("Hello!");
+    req.set_name("SRPCClient");
 
-    client.Echo(&req, [](EchoResponse *response, RPCContext *ctx) {
+    WFFacilities::WaitGroup wait_group(1);
+
+    client.Echo(&req, [&wait_group](EchoResponse *response, RPCContext *ctx) {
         if (ctx->success())
             printf("%s\n", response->DebugString().c_str());
         else
             printf("status[%d] error[%d] errmsg:%s\n",
                     ctx->get_status_code(), ctx->get_error(), ctx->get_errmsg());
+        wait_group.done();
     });
 
-    pause();
+    wait_group.wait();
     return 0;
 }
 ~~~

+ 10 - 3
docs/tutorial-06-workflow.md

@@ -84,13 +84,20 @@ int main()
     auto *calc_task = WFTaskFactory::create_go_task(calc, 3, 4);
 
     EchoRequest req;
-    req.set_message("Hello, sogou rpc!");
+    req.set_message("Hello!");
     req.set_name("1412");
     rpc_task->serialize_input(&req);
 
-    ((*http_task * rpc_task) > calc_task).start();
+    WFFacilities::WaitGroup wait_group(1);
 
-    pause();
+    SeriesWork *series = Workflow::create_series_work(http_task, [&wait_group](const SeriesWork *) {
+        wait_group.done();
+    });
+    series->push_back(rpc_task);
+    series->push_back(calc_task);
+    series->start();
+
+    wait_group.wait();
     return 0;
 }
 ~~~

+ 1 - 1
docs/tutorial-07-http.md

@@ -142,7 +142,7 @@ int main()
 {
     Example::SRPCClient client("127.0.0.1", 1412);
     EchoRequest req;
-    req.set_message("Hello, sogou rpc!");
+    req.set_message("Hello, srpc!");
 
     auto *task = client.create_Echo_task([](EchoResponse *resp, RPCContext *ctx) {                                                                              
         if (ctx->success())

+ 16 - 10
docs/wiki.md

@@ -42,12 +42,12 @@ srpc整体代码量大约1万行,内部使用多种泛型编程的方式,实
 * **IDL序列化**(protobuf/thrift serialization)
 * **数据组织** (protobuf/thrift/json)
 * **压缩**(none/gzip/zlib/snappy/lz4)
-* **协议** (Sogou-std/Baidu-std/Thrift-framed/TRPC)
+* **协议** (SRPC-std/BRPC-std/Thrift-framed/TRPC)
 * **通信** (TCP/HTTP)
 
 以上各层级可以相互拼装,利用函数重载、派生子类实现父类接口和模版特化等多种多态方式,来实现内部使用同一套代码的高度复用,以后如果想架构升级,无论是中间再加一层、还是某层内横向添加一种内容都非常方便,整体设计比较精巧。
 
-且得益于workflow的性能,srpc本身的性能也很优异。srpc系统除了Sogou-std协议以外,同时实现了Baidu-std协议、Thrift-framed协议、腾讯的TRPC协议,同协议下与brpc系统和apache thrift系统进行了性能对比,吞吐性能领先,长尾性能与brpc各有优势但都比thrift强。
+且得益于workflow的性能,srpc本身的性能也很优异。srpc系统除了SRPC-std协议以外,同时实现了BRPC-std协议、Thrift-framed协议、腾讯的TRPC协议,同协议下与brpc系统和apache thrift系统进行了性能对比,吞吐性能领先,长尾性能与brpc各有优势但都比thrift强。
 
 srpc目前在搜狗公司内部和开源后业界一些开发者的团队中已经稳定使用一段时间,并以其简单的接口让小伙伴们可以快速开发,且协助业务性能带来好几倍的提升。
 
@@ -74,7 +74,7 @@ srpc目前在搜狗公司内部和开源后业界一些开发者的团队中已
 
 ### 2. RPC协议层
 
-中间那列是具体的协议,我们实现了``Sogou-std``,``Baidu-std``,``Thrift-framed``和``TRPC``,其中**Sogou-std**的协议如下:
+中间那列是具体的协议,我们实现了``SRPC-std``,``BRPC-std``,``Thrift-framed``和``TRPC``,其中**SRPC-std**的协议如下:
 
 <img src="https://raw.githubusercontent.com/wiki/sogou/srpc/srpc-protocol.jpg" width = "719" height = "280" alt="srpc_protocol" align=center />
 
@@ -90,12 +90,13 @@ srpc目前在搜狗公司内部和开源后业界一些开发者的团队中已
 
 我们把``service``/``method``拼到``URL``的host后面,接下来把具体协议的``meta``的内容按照HTTP可以识别的header key一项一项填进``header``里。 最后把具体``request``/``response``作为HTTP的``body``填好,发送出去。
 
-我们除了HTTP + Baidu-std/TRPC没有实现,其他两两结合一共实现出了6种网络通信协议:
+我们除了BRPC + Http没有实现,其他两两结合一共实现出了7种网络通信协议:
 
 * SRPCStd
 * SRPCHttp
 * BRPCStd
-* TRPC
+* TRPCStd
+* TRPCHttp
 * ThriftBinaryFramed
 * ThriftBinaryHttp
 
@@ -243,7 +244,9 @@ int main()
 
     // 3. 把server启动起来
     server.start(PORT);
-    pause();
+
+    // 4. server启动是异步的,需要暂时卡住主线程
+    getchar();
     server.stop();
     return 0;
 }
@@ -291,25 +294,28 @@ int main()
     SRPCServer server_srpc;
     SRPCHttpServer server_srpc_http;
     BRPCServer server_brpc;
-    TRPCServer server_trpc;
     ThriftServer server_thrift;
+    TRPCServer server_trpc;
+    TRPCHttpServer server_trpc_http;
 
     ExampleServiceImpl impl_pb;                   // 使用pb作为接口的service
     AnotherThriftServiceImpl impl_thrift;         // 使用thrift作为接口的service
 
     server_srpc.add_service(&impl_pb);            // 只要协议本身支持这种IDL,就可以把这类service往里加
     server_srpc.add_service(&impl_thrift); 
-    server_srpc_http.add_service(&impl_pb);       // srpc还可以同时提供TCP和Http服务
+    server_srpc_http.add_service(&impl_pb);       // 还可以同时提供二进制协议和Http服务
     server_srpc_http.add_service(&impl_thrift);
-    server_brpc.add_service(&impl_pb);            // baidu-std协议只支持了protobuf
-    server_trpc.add_service(&impl_pb);            // 只需要改一个字母,就可以方便兼容不同协议
+    server_brpc.add_service(&impl_pb);            // brpc-std协议只支持了protobuf
     server_thrift.add_service(&impl_thrift);      // thrift-binary协议只支持了thrift
+    server_trpc.add_service(&impl_pb);            // 只需要改一个字母,就可以方便兼容不同协议
+    server_trpc_http.add_service(&impl_pb);       // 目前也是唯一开源的trpc协议实现
 
     server_srpc.start(1412);
     server_srpc_http.start(8811);
     server_brpc.start(2020);
     server_trpc.start(2021);
     server_thrift.start(9090);
+    server_trpc_http.start(8822);
     ....
 
     return 0;

+ 1 - 1
src/message/rpc_message_srpc.h

@@ -34,7 +34,7 @@ namespace srpc
 
 static constexpr int SRPC_HEADER_SIZE = 16;
 
-// define sogou rpc protocol
+// define srpc protocol
 class SRPCMessage : public RPCMessage
 {
 public:

+ 2 - 2
tutorial/tutorial-02-srpc_pb_client.cc

@@ -29,7 +29,7 @@ int main()
 
 	//async
 	EchoRequest req;
-	req.set_message("Hello, sogou rpc!");
+	req.set_message("Hello, srpc!");
 	req.set_name("1412");
 
 	client.Echo(&req, [](EchoResponse *resp, RPCContext *ctx) {
@@ -45,7 +45,7 @@ int main()
 	EchoResponse sync_resp;
 	RPCSyncContext sync_ctx;
 
-	sync_req.set_message("Hello, sogou rpc!");
+	sync_req.set_message("Hello, srpc!");
 	sync_req.set_name("Sync");
 	client.Echo(&sync_req, &sync_resp, &sync_ctx);
 	if (sync_ctx.success)

+ 3 - 3
tutorial/tutorial-04-srpc_thrift_client.cc

@@ -26,7 +26,7 @@ int main()
 	//sync
 	EchoResult sync_res;
 
-	client.Echo(sync_res, "Hello, sogou rpc!", "1412");
+	client.Echo(sync_res, "Hello, srpc!", "1412");
 
 	if (client.thrift_last_sync_success())
 		printf("%s\n", sync_res.message.c_str());
@@ -40,7 +40,7 @@ int main()
 
 	//async
 	Example::EchoRequest req;
-	req.message = "Hello, sogou rpc!";
+	req.message = "Hello, srpc!";
 	req.name = "1412";
 
 	client.Echo(&req, [](Example::EchoResponse *resp, RPCContext *ctx) {
@@ -56,7 +56,7 @@ int main()
 	Example::EchoResponse sync_resp;
 	RPCSyncContext sync_ctx;
 
-	sync_req.message = "Hello, sogou rpc!";
+	sync_req.message = "Hello, srpc!";
 	sync_req.name = "Sync";
 
 	client.Echo(&sync_req, &sync_resp, &sync_ctx);

+ 2 - 2
tutorial/tutorial-06-brpc_pb_client.cc

@@ -25,7 +25,7 @@ int main()
 
 	//async
 	EchoRequest req;
-	req.set_message("Hello, sogou rpc!");
+	req.set_message("Hello, srpc!");
 	req.set_name("1412");
 
 	client.Echo(&req, [](EchoResponse *resp, RPCContext *ctx) {
@@ -50,7 +50,7 @@ int main()
 	EchoResponse sync_resp;
 	RPCSyncContext sync_ctx;
 
-	sync_req.set_message("Hello, sogou rpc!");
+	sync_req.set_message("Hello, srpc!");
 	sync_req.set_name("Sync");
 
 	client.Echo(&sync_req, &sync_resp, &sync_ctx);

+ 4 - 4
tutorial/tutorial-08-thrift_thrift_client.cc

@@ -26,7 +26,7 @@ int main()
 	//sync
 	EchoResult sync_res;
 
-	client.Echo(sync_res, "Hello, sogou rpc!", "1412");
+	client.Echo(sync_res, "Hello, srpc!", "1412");
 	if (client.thrift_last_sync_success())
 		printf("%s\n", sync_res.message.c_str());
 	else
@@ -38,7 +38,7 @@ int main()
 	}
 
 	//send/recv
-	client.send_Echo("Hello, sogou rpc!", "1412");
+	client.send_Echo("Hello, srpc!", "1412");
 	//do anything you want
 	client.recv_Echo(sync_res);
 
@@ -54,7 +54,7 @@ int main()
 
 	//async
 	Example::EchoRequest req;
-	req.message = "Hello, sogou rpc!";
+	req.message = "Hello, srpc!";
 	req.name = "1412";
 
 	client.Echo(&req, [](Example::EchoResponse *resp, RPCContext *ctx) {
@@ -70,7 +70,7 @@ int main()
 	Example::EchoResponse sync_resp;
 	RPCSyncContext sync_ctx;
 
-	sync_req.message = "Hello, sogou rpc!";
+	sync_req.message = "Hello, srpc!";
 	sync_req.name = "Sync";
 	client.Echo(&sync_req, &sync_resp, &sync_ctx);
 

+ 10 - 8
tutorial/tutorial-09-client_task.cc

@@ -16,20 +16,17 @@
 
 #include <stdio.h>
 #include <workflow/WFTaskFactory.h>
-#include <workflow/WFOperator.h>
 #include "echo_pb.srpc.h"
 #include "workflow/WFFacilities.h"
 
 using namespace srpc;
 
-static WFFacilities::WaitGroup wait_group(1);
-
 int main()
 {
 	Example::SRPCClient client("127.0.0.1", 1412);
 
 	EchoRequest req;
-	req.set_message("Hello, sogou rpc!");
+	req.set_message("Hello, srpc!");
 	req.set_name("1412");
 
 	auto *rpc_task = client.create_Echo_task([](EchoResponse *resp,
@@ -40,8 +37,6 @@ int main()
 		else
 			printf("status[%d] error[%d] errmsg:%s\n",
 					ctx->get_status_code(), ctx->get_error(), ctx->get_errmsg());
-
-		wait_group.done();
 	});
 
 	auto *http_task = WFTaskFactory::create_http_task("https://www.sogou.com",
@@ -63,10 +58,17 @@ int main()
 	});
 
 	rpc_task->serialize_input(&req);
-	(*http_task > rpc_task).start();
 	rpc_task->log({{"event", "info"}, {"message", "rpc client task log."}});
-	wait_group.wait();
 
+	WFFacilities::WaitGroup wait_group(1);
+
+	SeriesWork *series = Workflow::create_series_work(http_task, [&wait_group](const SeriesWork *) {
+		wait_group.done();
+	});
+	series->push_back(rpc_task);
+	series->start();
+
+	wait_group.wait();
 	return 0;
 }