File tree Expand file tree Collapse file tree 1 file changed +22
-5
lines changed Expand file tree Collapse file tree 1 file changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -145,19 +145,36 @@ void TcpServer::start()
145
145
}
146
146
void TcpServer::stop ()
147
147
{
148
- loop_->runInLoop ([this ]() { acceptorPtr_.reset (); });
149
- for (auto connection : connSet_)
148
+ if (loop_->isInLoopThread ())
149
+ {
150
+ acceptorPtr_.reset ();
151
+ for (auto connection : connSet_)
152
+ {
153
+ connection->forceClose ();
154
+ }
155
+ }
156
+ else
150
157
{
151
- connection->forceClose ();
158
+ std::promise<void > pro;
159
+ auto f = pro.get_future ();
160
+ loop_->queueInLoop ([this , &pro]() {
161
+ acceptorPtr_.reset ();
162
+ for (auto connection : connSet_)
163
+ {
164
+ connection->forceClose ();
165
+ }
166
+ pro.set_value ();
167
+ });
168
+ f.get ();
152
169
}
153
170
loopPoolPtr_.reset ();
154
171
for (auto &iter : timingWheelMap_)
155
172
{
156
- std::promise<int > pro;
173
+ std::promise<void > pro;
157
174
auto f = pro.get_future ();
158
175
iter.second ->getLoop ()->runInLoop ([&iter, &pro]() mutable {
159
176
iter.second .reset ();
160
- pro.set_value (1 );
177
+ pro.set_value ();
161
178
});
162
179
f.get ();
163
180
}
You can’t perform that action at this time.
0 commit comments