Skip to content

Commit

Permalink
SmartPtr: Support interrupt transport when close session.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jun 12, 2024
1 parent a616df2 commit f414449
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
20 changes: 17 additions & 3 deletions trunk/src/app/srs_app_rtc_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -448,6 +448,7 @@ SrsRtcTcpNetwork::SrsRtcTcpNetwork(SrsRtcConnection* conn, SrsEphemeralDelta* de

SrsRtcTcpNetwork::~SrsRtcTcpNetwork()
{
owner_->interrupt();
srs_freep(transport_);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -863,7 +877,7 @@ srs_error_t SrsRtcTcpConn::handshake()

// Should support only one TCP candidate.
SrsRtcTcpNetwork* network = dynamic_cast<SrsRtcTcpNetwork*>(session->tcp());
if (!network->owner().get()) {
if (network->owner().get() != this) {
network->set_owner(*wrapper_);
session_ = session;
}
Expand Down
3 changes: 3 additions & 0 deletions trunk/src/app/srs_app_rtc_network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,16 @@ 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:
// Setup the owner, the wrapper is the shared ptr, the interruptable object is the coroutine, and the cid is the context id.
void setup_owner(SrsSharedResource<SrsRtcTcpConn>* wrapper, ISrsInterruptable* owner_coroutine, ISrsContextIdSetter* owner_cid);
public:
ISrsKbpsDelta* delta();
// Interrupt transport by session.
void interrupt();
// Interface ISrsResource.
public:
virtual std::string desc();
Expand Down

0 comments on commit f414449

Please sign in to comment.