Skip to content

Commit 05bd1ca

Browse files
authored
HttpServer::loop idx iteration exception (#726)
1 parent aa1bbc5 commit 05bd1ca

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

http/server/HttpServer.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,14 @@ std::shared_ptr<hv::EventLoop> HttpServer::loop(int idx) {
296296
if (privdata == NULL) return NULL;
297297
std::lock_guard<std::mutex> locker(privdata->mutex_);
298298
if (privdata->loops.empty()) return NULL;
299-
if (idx >= 0 && idx < (int)privdata->loops.size()) {
300-
return privdata->loops[idx];
299+
if (idx < 0) {
300+
EventLoop* cur = currentThreadEventLoop;
301+
for (auto& loop : privdata->loops) {
302+
if (loop.get() == cur) return loop;
303+
}
301304
}
302-
EventLoop* cur = currentThreadEventLoop;
303-
for (auto& loop : privdata->loops) {
304-
if (loop.get() == cur) return loop;
305+
else if (idx >= 0 && idx < (int)privdata->loops.size()) {
306+
return privdata->loops[idx];
305307
}
306308
return NULL;
307309
}

0 commit comments

Comments
 (0)