mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-14 20:15:58 +08:00
使用static_pointer_cast优化性能
This commit is contained in:
@@ -202,7 +202,7 @@ bool HttpSession::checkLiveStream(const string &schema, const string &url_suffi
|
||||
}
|
||||
|
||||
bool close_flag = !strcasecmp(_parser["Connection"].data(), "close");
|
||||
weak_ptr<HttpSession> weak_self = dynamic_pointer_cast<HttpSession>(shared_from_this());
|
||||
weak_ptr<HttpSession> weak_self = static_pointer_cast<HttpSession>(shared_from_this());
|
||||
|
||||
//鉴权结果回调
|
||||
auto onRes = [cb, weak_self, close_flag](const string &err) {
|
||||
@@ -266,7 +266,7 @@ bool HttpSession::checkLiveStreamFMP4(const function<void()> &cb){
|
||||
//直播牺牲延时提升发送性能
|
||||
setSocketFlags();
|
||||
onWrite(std::make_shared<BufferString>(fmp4_src->getInitSegment()), true);
|
||||
weak_ptr<HttpSession> weak_self = dynamic_pointer_cast<HttpSession>(shared_from_this());
|
||||
weak_ptr<HttpSession> weak_self = static_pointer_cast<HttpSession>(shared_from_this());
|
||||
fmp4_src->pause(false);
|
||||
_fmp4_reader = fmp4_src->getRing()->attach(getPoller());
|
||||
_fmp4_reader->setGetInfoCB([weak_self]() { return weak_self.lock(); });
|
||||
@@ -308,7 +308,7 @@ bool HttpSession::checkLiveStreamTS(const function<void()> &cb){
|
||||
|
||||
//直播牺牲延时提升发送性能
|
||||
setSocketFlags();
|
||||
weak_ptr<HttpSession> weak_self = dynamic_pointer_cast<HttpSession>(shared_from_this());
|
||||
weak_ptr<HttpSession> weak_self = static_pointer_cast<HttpSession>(shared_from_this());
|
||||
ts_src->pause(false);
|
||||
_ts_reader = ts_src->getRing()->attach(getPoller());
|
||||
_ts_reader->setGetInfoCB([weak_self]() { return weak_self.lock(); });
|
||||
@@ -406,7 +406,7 @@ void HttpSession::Handle_Req_GET_l(ssize_t &content_len, bool sendBody) {
|
||||
}
|
||||
|
||||
bool bClose = !strcasecmp(_parser["Connection"].data(),"close");
|
||||
weak_ptr<HttpSession> weak_self = dynamic_pointer_cast<HttpSession>(shared_from_this());
|
||||
weak_ptr<HttpSession> weak_self = static_pointer_cast<HttpSession>(shared_from_this());
|
||||
HttpFileManager::onAccessPath(*this, _parser, [weak_self, bClose](int code, const string &content_type,
|
||||
const StrCaseMap &responseHeader, const HttpBody::Ptr &body) {
|
||||
auto strong_self = weak_self.lock();
|
||||
@@ -434,12 +434,13 @@ class AsyncSenderData {
|
||||
public:
|
||||
friend class AsyncSender;
|
||||
using Ptr = std::shared_ptr<AsyncSenderData>;
|
||||
AsyncSenderData(const Session::Ptr &session, const HttpBody::Ptr &body, bool close_when_complete) {
|
||||
_session = dynamic_pointer_cast<HttpSession>(session);
|
||||
AsyncSenderData(HttpSession::Ptr session, const HttpBody::Ptr &body, bool close_when_complete) {
|
||||
_session = std::move(session);
|
||||
_body = body;
|
||||
_close_when_complete = close_when_complete;
|
||||
}
|
||||
~AsyncSenderData() = default;
|
||||
|
||||
private:
|
||||
std::weak_ptr<HttpSession> _session;
|
||||
HttpBody::Ptr _body;
|
||||
@@ -612,7 +613,7 @@ void HttpSession::sendResponse(int code,
|
||||
}
|
||||
|
||||
//发送http body
|
||||
AsyncSenderData::Ptr data = std::make_shared<AsyncSenderData>(static_pointer_cast<Session>(shared_from_this()), body, bClose);
|
||||
AsyncSenderData::Ptr data = std::make_shared<AsyncSenderData>(static_pointer_cast<HttpSession>(shared_from_this()), body, bClose);
|
||||
getSock()->setOnFlush([data]() { return AsyncSender::onSocketFlushed(data); });
|
||||
AsyncSender::onSocketFlushed(data);
|
||||
}
|
||||
@@ -639,7 +640,7 @@ void HttpSession::urlDecode(Parser &parser){
|
||||
bool HttpSession::emitHttpEvent(bool doInvoke){
|
||||
bool bClose = !strcasecmp(_parser["Connection"].data(),"close");
|
||||
/////////////////////异步回复Invoker///////////////////////////////
|
||||
weak_ptr<HttpSession> weak_self = dynamic_pointer_cast<HttpSession>(shared_from_this());
|
||||
weak_ptr<HttpSession> weak_self = static_pointer_cast<HttpSession>(shared_from_this());
|
||||
HttpResponseInvoker invoker = [weak_self,bClose](int code, const KeyValue &headerOut, const HttpBody::Ptr &body){
|
||||
auto strong_self = weak_self.lock();
|
||||
if(!strong_self) {
|
||||
|
||||
Reference in New Issue
Block a user