From 3d64f7253c86aa3b83f622ae93a3322a79e822fb Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Thu, 16 Sep 2021 10:03:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96webrtc=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/WebRtcSession.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/webrtc/WebRtcSession.cpp b/webrtc/WebRtcSession.cpp index 943a5b72..03682f1d 100644 --- a/webrtc/WebRtcSession.cpp +++ b/webrtc/WebRtcSession.cpp @@ -67,9 +67,7 @@ void WebRtcSession::onRecv_l(const Buffer::Ptr &buffer) { } _ticker.resetTime(); CHECK(_transport); - //先增加引用技术,防止使用transport时,触发onError事件导致对象释放 - auto transport = _transport; - transport->inputSockData(buffer->data(), buffer->size(), &_peer_addr); + _transport->inputSockData(buffer->data(), buffer->size(), &_peer_addr); } void WebRtcSession::onError(const SockException &err) { @@ -77,8 +75,11 @@ void WebRtcSession::onError(const SockException &err) { //在udp链接迁移时,新的WebRtcSession对象将接管WebRtcTransport对象的生命周期 //本WebRtcSession对象将在超时后自动销毁 WarnP(this) << err.what(); - //取消循环引用 - _transport = nullptr; + + auto transport = std::move(_transport); + this->Session::getPoller()->async([transport] { + //延时减引用,防止使用transport对象时,销毁对象 + }, false); } void WebRtcSession::onManager() {