From a5cf1a3746027f7ee8ce68cb8afb99dd29105d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=85=E3=81=AE=E5=A3=AB?= Date: Thu, 17 Apr 2025 11:10:48 +0800 Subject: [PATCH] HttpServer::loop idx iteration exception --- http/server/HttpServer.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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; }