diff --git a/http/server/HttpServer.cpp b/http/server/HttpServer.cpp index eff0a865c..aa296fe8b 100644 --- a/http/server/HttpServer.cpp +++ b/http/server/HttpServer.cpp @@ -296,12 +296,14 @@ std::shared_ptr HttpServer::loop(int idx) { if (privdata == NULL) return NULL; std::lock_guard locker(privdata->mutex_); if (privdata->loops.empty()) return NULL; - if (idx >= 0 && idx < (int)privdata->loops.size()) { - return privdata->loops[idx]; + if (idx < 0) { + EventLoop* cur = currentThreadEventLoop; + for (auto& loop : privdata->loops) { + if (loop.get() == cur) return loop; + } } - EventLoop* cur = currentThreadEventLoop; - for (auto& loop : privdata->loops) { - if (loop.get() == cur) return loop; + else if (idx >= 0 && idx < (int)privdata->loops.size()) { + return privdata->loops[idx]; } return NULL; }