-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.patch
109 lines (101 loc) · 3.88 KB
/
example.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
diff --git a/wangle/CMakeLists.txt b/wangle/CMakeLists.txt
index a1e8e69..03a4569 100644
--- a/wangle/CMakeLists.txt
+++ b/wangle/CMakeLists.txt
@@ -165,7 +165,7 @@ endif()
add_gtest(ssl/test/SSLContextManagerTest.cpp SSLContextManagerTest)
endif()
-option(BUILD_EXAMPLES "BUILD_EXAMPLES" OFF)
+option(BUILD_EXAMPLES "BUILD_EXAMPLES" ON)
if(BUILD_EXAMPLES)
add_executable(EchoClient example/echo/EchoClient.cpp)
diff --git a/wangle/example/echo/EchoClient.cpp b/wangle/example/echo/EchoClient.cpp
index 5ee0cad..bcdd6d0 100644
--- a/wangle/example/echo/EchoClient.cpp
+++ b/wangle/example/echo/EchoClient.cpp
@@ -59,27 +59,50 @@ class EchoPipelineFactory : public PipelineFactory<EchoPipeline> {
int main(int argc, char** argv) {
google::ParseCommandLineFlags(&argc, &argv, true);
+ std::shared_ptr<wangle::IOThreadPoolExecutor> ioPool =
+ std::make_shared<wangle::IOThreadPoolExecutor>(2);
+ std::shared_ptr<EchoPipelineFactory> pipeFact =
+ std::make_shared<EchoPipelineFactory>();
+
ClientBootstrap<EchoPipeline> client;
- client.group(std::make_shared<wangle::IOThreadPoolExecutor>(1));
- client.pipelineFactory(std::make_shared<EchoPipelineFactory>());
+ client.group(ioPool);
+ client.pipelineFactory(pipeFact);
+ //client.group(std::make_shared<wangle::IOThreadPoolExecutor>(1));
+ //client.pipelineFactory(std::make_shared<EchoPipelineFactory>());
auto pipeline = client.connect(SocketAddress(FLAGS_host, FLAGS_port)).get();
try {
while (true) {
- std::string line;
- std::getline(std::cin, line);
- if (line == "") {
- break;
- }
+ try {
+ std::string line;
+ std::getline(std::cin, line);
+ if (line == "") {
+ std::cout << "receive empty line, exit" << std::endl;
+ break;
+ }
+
+ // reset connection
+ //ClientBootstrap<EchoPipeline> client1;
+ //client1.group(ioPool);
+ //client1.pipelineFactory(pipeFact);
+ pipeline = client.connect(SocketAddress(FLAGS_host, FLAGS_port)).get();
- pipeline->write(line + "\r\n").get();
- if (line == "bye") {
- pipeline->close();
- break;
+ std::cout << " reconnected to " << FLAGS_host << " " << FLAGS_port << std::endl;
+ pipeline->write(line + "\r\n").get();
+ if (line == "bye") {
+ std::cout << "receive bye, exit" << std::endl;
+ pipeline->close();
+ break;
+ }
+
+ std::this_thread::sleep_for(std::chrono::seconds(1));
+
+ } catch (const folly::AsyncSocketException& fe) {
+ std::cout << "folly::AsyncSocketException " << exceptionStr(fe) << std::endl;
}
}
} catch (const std::exception& e) {
- std::cout << exceptionStr(e) << std::endl;
+ std::cout << "exception: " << exceptionStr(e) << std::endl;
}
return 0;
diff --git a/wangle/example/echo/EchoServer.cpp b/wangle/example/echo/EchoServer.cpp
index 94af041..ed556fe 100644
--- a/wangle/example/echo/EchoServer.cpp
+++ b/wangle/example/echo/EchoServer.cpp
@@ -26,7 +26,15 @@ typedef Pipeline<IOBufQueue&, std::string> EchoPipeline;
class EchoHandler : public HandlerAdapter<std::string> {
public:
virtual void read(Context* ctx, std::string msg) override {
- std::cout << "handling " << msg << std::endl;
+ bool doSleep = false;
+ if (!doSleep) {
+ std::cout << "handling " << msg << std::endl;
+ } else {
+ std::cout << "thread " << std::this_thread::get_id()
+ << "handling " << msg << "; sleep 5s" << std::endl;
+ sleep(5);
+ std::cout << "; sleep done, echo back" << std::endl;
+ }
write(ctx, msg + "\r\n");
}
};
@@ -50,6 +58,7 @@ int main(int argc, char** argv) {
ServerBootstrap<EchoPipeline> server;
server.childPipeline(std::make_shared<EchoPipelineFactory>());
+ server.group(std::make_shared<wangle::IOThreadPoolExecutor>(2));
server.bind(FLAGS_port);
server.waitForStop();