#554·proxygen

HTTPSessionAcceptor::getController() 应返回一个原始指针,而不是 std::shared_ptr

作者: rainliu创建于 2025年4月15日更新于 2025年4月15日

原因是因为:一个 HTTPSessionController 被映射到一个 HTTPSession。HTTPSessionAcceptor 管理多个控制器。最好采用与 HQSessionController 相同的生命周期管理,即返回一个原始指针,并在 HQSessionController::detachSession() 中让自己自行销毁。否则,在 https://GitHub.com/facebook/proxygen/blob/3f8d21fc2fb4def298785b28d79168e301438c20/proxygen/lib/http/session/HTTPSessionAcceptor.cpp#L71 中,控制器被创建为 shared_ptr,但在 https://GitHub.com/facebook/proxygen/blob/3f8d21fc2fb4def298785b28d79168e301438c20/proxygen/lib/http/session/HTTPSessionAcceptor.cpp#L99 中,它被用作原始指针。然后在 HTTPSessionAcceptor::onNewConnection 完成后会自动释放。

内容来源: facebook/proxygen