- 根因: httplib默认keep-alive=5秒, MJPEG长连接5秒后断开 - set_keep_alive_max_count(0)会触发处理循环直接退出(HTTP 000) - 改为 max_count=1000, timeout=3600 - 实测: keep-alive 3600s, MJPEG 8秒77帧持续稳定
@@ -78,6 +78,9 @@ public:
}
void setupRoutes() {
+ // MJPEG长连接: keep-alive默认5秒会断开推流, 设为1小时
+ svr.set_keep_alive_max_count(1000); // 复用上限
+ svr.set_keep_alive_timeout(3600); // 1小时
svr.Get("/", [this](const httplib::Request& req, httplib::Response& res) {
if (hooks_set_ && !authed(req)) {
res.status = 302;