From 00b3c5184a3b488dc43df65a6be1685b87036356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=A5=9A?= <771730766@qq.com> Date: Sat, 29 Jul 2023 13:24:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DRtpProcess=E6=9E=90=E6=9E=84?= =?UTF-8?q?=E4=B8=AD=E6=8A=9B=E5=BC=82=E5=B8=B8=E5=AF=BC=E8=87=B4=E5=B4=A9?= =?UTF-8?q?=E6=BA=83=E7=9A=84=E9=97=AE=E9=A2=98=20(#2714)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WarnP(this) 时会调用get_peer_ip()接口,此接口可能抛异常; 析构中抛异常可导致程序直接退出。 --- src/Rtp/RtpProcess.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index 741cc4b1..0ca3f704 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -210,31 +210,27 @@ void RtpProcess::setOnDetach(function cb) { } string RtpProcess::get_peer_ip() { - if (!_addr) { + try { + return _addr ? SockUtil::inet_ntoa((sockaddr *)_addr.get()) : "::"; + } catch (std::exception &ex) { return "::"; } - return SockUtil::inet_ntoa((sockaddr *)_addr.get()); } uint16_t RtpProcess::get_peer_port() { - if (!_addr) { + try { + return _addr ? SockUtil::inet_port((sockaddr *)_addr.get()) : 0; + } catch (std::exception &ex) { return 0; } - return SockUtil::inet_port((sockaddr *)_addr.get()); } string RtpProcess::get_local_ip() { - if (_sock) { - return _sock->get_local_ip(); - } - return "::"; + return _sock ? _sock->get_local_ip() : "::"; } uint16_t RtpProcess::get_local_port() { - if (_sock) { - return _sock->get_local_port(); - } - return 0; + return _sock ? _sock->get_local_port() : 0; } string RtpProcess::getIdentifier() const { @@ -305,4 +301,4 @@ float RtpProcess::getLossRate(MediaSource &sender, TrackType type) { } }//namespace mediakit -#endif//defined(ENABLE_RTPPROXY) \ No newline at end of file +#endif//defined(ENABLE_RTPPROXY)