Skip to content

Commit a01b3b4

Browse files
authored
Remove an assertion when removing channels (#195)
1 parent 1af2c68 commit a01b3b4

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

trantor/net/Channel.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ void Channel::update()
5353
void Channel::handleEvent()
5454
{
5555
// LOG_TRACE<<"revents_="<<revents_;
56+
if (events_ == kNoneEvent)
57+
return;
5658
if (tied_)
5759
{
5860
std::shared_ptr<void> guard = tie_.lock();

trantor/net/EventLoop.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,6 @@ void EventLoop::removeChannel(Channel *channel)
136136
{
137137
assert(channel->ownerLoop() == this);
138138
assertInLoopThread();
139-
if (eventHandling_)
140-
{
141-
assert(currentActiveChannel_ == channel ||
142-
std::find(activeChannels_.begin(),
143-
activeChannels_.end(),
144-
channel) == activeChannels_.end());
145-
}
146139
poller_->removeChannel(channel);
147140
}
148141
void EventLoop::quit()

trantor/net/TcpServer.cc

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,26 @@ void TcpServer::stop()
165165
void TcpServer::connectionClosed(const TcpConnectionPtr &connectionPtr)
166166
{
167167
LOG_TRACE << "connectionClosed";
168-
// loop_->assertInLoopThread();
169-
loop_->runInLoop([this, connectionPtr]() {
168+
if (loop_->isInLoopThread())
169+
{
170170
size_t n = connSet_.erase(connectionPtr);
171171
(void)n;
172172
assert(n == 1);
173-
});
174-
175-
static_cast<TcpConnectionImpl *>(connectionPtr.get())->connectDestroyed();
173+
loop_->queueInLoop([connectionPtr]() {
174+
static_cast<TcpConnectionImpl *>(connectionPtr.get())
175+
->connectDestroyed();
176+
});
177+
}
178+
else
179+
{
180+
loop_->queueInLoop([this, connectionPtr]() {
181+
size_t n = connSet_.erase(connectionPtr);
182+
(void)n;
183+
assert(n == 1);
184+
static_cast<TcpConnectionImpl *>(connectionPtr.get())
185+
->connectDestroyed();
186+
});
187+
}
176188
}
177189

178190
const std::string TcpServer::ipPort() const

0 commit comments

Comments
 (0)