File tree 2 files changed +27
-2
lines changed
Filter options
2 files changed +27
-2
lines changed
Original file line number Diff line number Diff line change 9
9
#include " asio.hpp"
10
10
#include " format.h"
11
11
12
+ #include " rpc/this_server.h"
12
13
#include " rpc/detail/dev_utils.h"
13
14
#include " rpc/detail/log.h"
14
15
#include " rpc/detail/log.h"
@@ -62,7 +63,8 @@ struct server::impl {
62
63
} else {
63
64
LOG_ERROR (" Error while accepting connection: {}" , ec);
64
65
}
65
- start_accept ();
66
+ if (!this_server ().stopping ())
67
+ start_accept ();
66
68
// TODO: allow graceful exit [sztomi 2016-01-13]
67
69
});
68
70
}
@@ -77,6 +79,9 @@ struct server::impl {
77
79
for (auto &session : sessions_copy) {
78
80
session->close ();
79
81
}
82
+
83
+ if (this_server ().stopping ())
84
+ acceptor_.cancel ();
80
85
}
81
86
82
87
void stop () {
Original file line number Diff line number Diff line change 1
1
#include " gtest/gtest.h"
2
2
3
+ #include < future>
4
+
3
5
#include " rpc/client.h"
4
6
#include " rpc/server.h"
5
7
#include " rpc/this_server.h"
@@ -24,7 +26,7 @@ class this_server_test : public testing::Test {
24
26
rpc::client c2;
25
27
};
26
28
27
- TEST_F (this_server_test, stop ) {
29
+ TEST_F (this_server_test, stop_async ) {
28
30
s.bind (" stop_server" , []() { rpc::this_server ().stop (); });
29
31
s.async_run ();
30
32
c1.call (" stop_server" );
@@ -35,3 +37,21 @@ TEST_F(this_server_test, stop) {
35
37
EXPECT_EQ (c2.get_connection_state (),
36
38
client::connection_state::disconnected);
37
39
}
40
+
41
+ TEST_F (this_server_test, stop_sync) {
42
+ s.bind (" stop_server" , []() { rpc::this_server ().stop (); });
43
+
44
+ auto handle = std::async (std::launch::async, [this ]() {
45
+ std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
46
+ c1.call (" stop_server" );
47
+ std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
48
+ });
49
+
50
+ s.run ();
51
+ handle.get ();
52
+
53
+ EXPECT_EQ (c1.get_connection_state (),
54
+ client::connection_state::disconnected);
55
+ EXPECT_EQ (c2.get_connection_state (),
56
+ client::connection_state::disconnected);
57
+ }
You can’t perform that action at this time.
0 commit comments