From f3fda0367d75b119030312521580fc52b1289354 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 12 Jun 2024 23:02:35 +0800 Subject: [PATCH] SmartPtr: Support interrupt transport when close session. --- trunk/src/app/srs_app_rtc_network.cpp | 20 +++++++++++++++++--- trunk/src/app/srs_app_rtc_network.hpp | 3 +++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/trunk/src/app/srs_app_rtc_network.cpp b/trunk/src/app/srs_app_rtc_network.cpp index d001bf5047..3725afaf10 100644 --- a/trunk/src/app/srs_app_rtc_network.cpp +++ b/trunk/src/app/srs_app_rtc_network.cpp @@ -436,7 +436,7 @@ srs_error_t SrsRtcUdpNetwork::write(void* buf, size_t size, ssize_t* nwrite) return sendonly_skt_->sendto(buf, size, SRS_UTIME_NO_TIMEOUT); } -SrsRtcTcpNetwork::SrsRtcTcpNetwork(SrsRtcConnection* conn, SrsEphemeralDelta* delta) : owner_(NULL) +SrsRtcTcpNetwork::SrsRtcTcpNetwork(SrsRtcConnection* conn, SrsEphemeralDelta* delta) : owner_(new SrsRtcTcpConn()) { conn_ = conn; delta_ = delta; @@ -448,6 +448,7 @@ SrsRtcTcpNetwork::SrsRtcTcpNetwork(SrsRtcConnection* conn, SrsEphemeralDelta* de SrsRtcTcpNetwork::~SrsRtcTcpNetwork() { + owner_->interrupt(); srs_freep(transport_); } @@ -693,13 +694,20 @@ void SrsRtcTcpNetwork::dispose() #define SRS_RTC_TCP_PACKET_MAX 1500 -SrsRtcTcpConn::SrsRtcTcpConn(ISrsProtocolReadWriter* skt, std::string cip, int port) +SrsRtcTcpConn::SrsRtcTcpConn() { wrapper_ = NULL; owner_coroutine_ = NULL; owner_cid_ = NULL; cid_ = _srs_context->get_id(); + pkt_ = NULL; + delta_ = NULL; + skt_ = NULL; +} + +SrsRtcTcpConn::SrsRtcTcpConn(ISrsProtocolReadWriter* skt, std::string cip, int port) : SrsRtcTcpConn() +{ ip_ = cip; port_ = port; skt_ = skt; @@ -728,6 +736,12 @@ ISrsKbpsDelta* SrsRtcTcpConn::delta() return delta_; } +void SrsRtcTcpConn::interrupt() +{ + session_ = NULL; + if (owner_coroutine_) owner_coroutine_->interrupt(); +} + std::string SrsRtcTcpConn::desc() { return "Tcp"; @@ -863,7 +877,7 @@ srs_error_t SrsRtcTcpConn::handshake() // Should support only one TCP candidate. SrsRtcTcpNetwork* network = dynamic_cast(session->tcp()); - if (!network->owner().get()) { + if (network->owner().get() != this) { network->set_owner(*wrapper_); session_ = session; } diff --git a/trunk/src/app/srs_app_rtc_network.hpp b/trunk/src/app/srs_app_rtc_network.hpp index 926b92e6c5..82282347fe 100644 --- a/trunk/src/app/srs_app_rtc_network.hpp +++ b/trunk/src/app/srs_app_rtc_network.hpp @@ -253,6 +253,7 @@ class SrsRtcTcpConn : public ISrsConnection, public ISrsCoroutineHandler, public ISrsContextIdSetter* owner_cid_; SrsContextId cid_; public: + SrsRtcTcpConn(); SrsRtcTcpConn(ISrsProtocolReadWriter* skt, std::string cip, int port); virtual ~SrsRtcTcpConn(); public: @@ -260,6 +261,8 @@ class SrsRtcTcpConn : public ISrsConnection, public ISrsCoroutineHandler, public void setup_owner(SrsSharedResource* wrapper, ISrsInterruptable* owner_coroutine, ISrsContextIdSetter* owner_cid); public: ISrsKbpsDelta* delta(); + // Interrupt transport by session. + void interrupt(); // Interface ISrsResource. public: virtual std::string desc();