File tree Expand file tree Collapse file tree 2 files changed +23
-14
lines changed Expand file tree Collapse file tree 2 files changed +23
-14
lines changed Original file line number Diff line number Diff line change @@ -162,30 +162,38 @@ void TcpServer::stop()
162
162
f.get ();
163
163
}
164
164
}
165
- void TcpServer::connectionClosed (const TcpConnectionPtr &connectionPtr)
165
+ void TcpServer::handleCloseInLoop (const TcpConnectionPtr &connectionPtr)
166
166
{
167
- LOG_TRACE << " connectionClosed" ;
168
- if (loop_->isInLoopThread ())
167
+ size_t n = connSet_.erase (connectionPtr);
168
+ (void )n;
169
+ assert (n == 1 );
170
+ auto connLoop = connectionPtr->getLoop ();
171
+ if (connLoop == loop_)
169
172
{
170
- size_t n = connSet_.erase (connectionPtr);
171
- (void )n;
172
- assert (n == 1 );
173
- loop_->queueInLoop ([connectionPtr]() {
174
- static_cast <TcpConnectionImpl *>(connectionPtr.get ())
175
- ->connectDestroyed ();
176
- });
173
+ static_cast <TcpConnectionImpl *>(connectionPtr.get ())
174
+ ->connectDestroyed ();
177
175
}
178
176
else
179
177
{
180
- loop_->queueInLoop ([this , connectionPtr]() {
181
- size_t n = connSet_.erase (connectionPtr);
182
- (void )n;
183
- assert (n == 1 );
178
+ connLoop->queueInLoop ([connectionPtr]() {
184
179
static_cast <TcpConnectionImpl *>(connectionPtr.get ())
185
180
->connectDestroyed ();
186
181
});
187
182
}
188
183
}
184
+ void TcpServer::connectionClosed (const TcpConnectionPtr &connectionPtr)
185
+ {
186
+ LOG_TRACE << " connectionClosed" ;
187
+ if (loop_->isInLoopThread ())
188
+ {
189
+ handleCloseInLoop (connectionPtr);
190
+ }
191
+ else
192
+ {
193
+ loop_->queueInLoop (
194
+ [this , connectionPtr]() { handleCloseInLoop (connectionPtr); });
195
+ }
196
+ }
189
197
190
198
const std::string TcpServer::ipPort () const
191
199
{
Original file line number Diff line number Diff line change @@ -215,6 +215,7 @@ class TRANTOR_EXPORT TcpServer : NonCopyable
215
215
216
216
private:
217
217
EventLoop *loop_;
218
+ void handleCloseInLoop (const TcpConnectionPtr &connectionPtr);
218
219
std::unique_ptr<Acceptor> acceptorPtr_;
219
220
void newConnection (int fd, const InetAddress &peer);
220
221
std::string serverName_;
You can’t perform that action at this time.
0 commit comments