For #1657, refine the context for disposing

pull/2023/head
winlin 4 years ago
parent b492d59df0
commit fc21b31714

@ -49,7 +49,7 @@ SrsAppCasterFlv::SrsAppCasterFlv(SrsConfDirective* c)
{
http_mux = new SrsHttpServeMux();
output = _srs_config->get_stream_caster_output(c);
manager = new SrsResourceManager("CasterFLV");
manager = new SrsResourceManager("CFLV");
}
SrsAppCasterFlv::~SrsAppCasterFlv()
@ -259,6 +259,11 @@ srs_error_t SrsDynamicHttpConn::on_reload_http_stream_crossdomain()
return conn->set_crossdomain_enabled(v);
}
srs_error_t SrsDynamicHttpConn::on_start()
{
return srs_success;
}
srs_error_t SrsDynamicHttpConn::on_http_message(ISrsHttpMessage* msg)
{
return srs_success;

@ -99,6 +99,7 @@ public:
virtual srs_error_t on_reload_http_stream_crossdomain();
// Interface ISrsHttpConnOwner.
public:
virtual srs_error_t on_start();
virtual srs_error_t on_http_message(ISrsHttpMessage* msg);
virtual void on_conn_done();
// Interface ISrsResource.

@ -93,7 +93,7 @@ srs_error_t SrsResourceManager::cycle()
{
srs_error_t err = srs_success;
srs_trace("%s connection manager run", label_.c_str());
srs_trace("%s: connection manager run", label_.c_str());
while (true) {
if ((err = trd->pull()) != srs_success) {
@ -183,10 +183,11 @@ void SrsResourceManager::remove(ISrsResource* c)
void SrsResourceManager::do_remove(ISrsResource* c)
{
SrsContextRestore(cid_);
SrsContextRestore(_srs_context->get_id());
if (verbose_) {
_srs_context->set_id(c->get_id());
srs_trace("before dispose resource(%s), zombies=%d", c->desc().c_str(), (int)zombies_.size());
srs_trace("%s: before dispose resource(%s), zombies=%d",
label_.c_str(), c->desc().c_str(), (int)zombies_.size());
}
// Only notify when not removed(in zombies_).
@ -215,7 +216,7 @@ void SrsResourceManager::do_remove(ISrsResource* c)
// Ignore if handler is unsubscribing.
if (!unsubs_.empty() && std::find(unsubs_.begin(), unsubs_.end(), h) != unsubs_.end()) {
srs_warn2(TAG_RESOURCE_UNSUB, "ignore before-dispose for %p", h);
srs_warn2(TAG_RESOURCE_UNSUB, "%s: ignore before-dispose for %p", label_.c_str(), h);
continue;
}
@ -234,7 +235,7 @@ void SrsResourceManager::clear()
SrsContextRestore(cid_);
if (verbose_) {
srs_trace("clear zombies=%d connections", (int)zombies_.size());
srs_trace("%s: clear zombies=%d connections", label_.c_str(), (int)zombies_.size());
}
// Clear all unsubscribing handlers, if not removing any resource.
@ -262,8 +263,8 @@ void SrsResourceManager::do_clear()
if (verbose_) {
_srs_context->set_id(conn->get_id());
srs_trace("disposing resource(%s), zombies=%d/%d", conn->desc().c_str(),
(int)copy.size(), (int)zombies_.size());
srs_trace("%s: disposing resource(%s), zombies=%d/%d", label_.c_str(),
conn->desc().c_str(), (int)copy.size(), (int)zombies_.size());
}
dispose(conn);
@ -304,7 +305,7 @@ void SrsResourceManager::dispose(ISrsResource* c)
// Ignore if handler is unsubscribing.
if (!unsubs_.empty() && std::find(unsubs_.begin(), unsubs_.end(), h) != unsubs_.end()) {
srs_warn2(TAG_RESOURCE_UNSUB, "ignore disposing for %p", h);
srs_warn2(TAG_RESOURCE_UNSUB, "%s: ignore disposing for %p", label_.c_str(), h);
continue;
}

@ -1689,6 +1689,11 @@ SrsHttpApi::~SrsHttpApi()
srs_freep(conn);
}
srs_error_t SrsHttpApi::on_start()
{
return srs_success;
}
srs_error_t SrsHttpApi::on_http_message(ISrsHttpMessage* req)
{
srs_error_t err = srs_success;

@ -268,6 +268,7 @@ public:
virtual ~SrsHttpApi();
// Interface ISrsHttpConnOwner.
public:
virtual srs_error_t on_start();
virtual srs_error_t on_http_message(ISrsHttpMessage* msg);
virtual void on_conn_done();
// Interface ISrsResource.

@ -81,7 +81,7 @@ SrsHttpConn::SrsHttpConn(ISrsHttpConnOwner* handler, srs_netfd_t fd, ISrsHttpSer
clk = new SrsWallClock();
kbps = new SrsKbps(clk);
kbps->set_io(skt, skt);
trd = new SrsSTCoroutine("http", this);
trd = new SrsSTCoroutine("http", this, _srs_context->get_id());
}
SrsHttpConn::~SrsHttpConn()
@ -159,6 +159,11 @@ srs_error_t SrsHttpConn::cycle()
srs_error_t SrsHttpConn::do_cycle()
{
srs_error_t err = srs_success;
// Notify the handler that we are starting to process the connection.
if ((err = handler_->on_start()) != srs_success) {
return srs_error_wrap(err, "start");
}
// set the recv timeout, for some clients never disconnect the connection.
// @see https://github.com/ossrs/srs/issues/398
@ -356,6 +361,11 @@ srs_error_t SrsResponseOnlyHttpConn::on_reload_http_stream_crossdomain()
return conn->set_crossdomain_enabled(v);
}
srs_error_t SrsResponseOnlyHttpConn::on_start()
{
return srs_success;
}
srs_error_t SrsResponseOnlyHttpConn::on_http_message(ISrsHttpMessage* msg)
{
srs_error_t err = srs_success;

@ -61,6 +61,8 @@ public:
ISrsHttpConnOwner();
virtual ~ISrsHttpConnOwner();
public:
// When start the coroutine to process connection.
virtual srs_error_t on_start() = 0;
// Handle the HTTP message msg, which may be parsed partially.
// For the static service or api, discard any body.
// For the stream caster, for instance, http flv streaming, may discard the flv header or not.
@ -166,6 +168,7 @@ public:
virtual srs_error_t on_reload_http_stream_crossdomain();
// Interface ISrsHttpConnOwner.
public:
virtual srs_error_t on_start();
virtual srs_error_t on_http_message(ISrsHttpMessage* msg);
virtual void on_conn_done();
// Extract APIs from SrsTcpConnection.

@ -722,7 +722,7 @@ SrsRtspCaster::SrsRtspCaster(SrsConfDirective* c)
output = _srs_config->get_stream_caster_output(c);
local_port_min = _srs_config->get_stream_caster_rtp_port_min(c);
local_port_max = _srs_config->get_stream_caster_rtp_port_max(c);
manager = new SrsResourceManager("CasterRTSP");
manager = new SrsResourceManager("CRTSP");
}
SrsRtspCaster::~SrsRtspCaster()

@ -656,7 +656,7 @@ SrsServer::SrsServer()
pid_fd = -1;
signal_manager = new SrsSignalManager(this);
conn_manager = new SrsResourceManager("RTMP/API");
conn_manager = new SrsResourceManager("TCP", true);
handler = NULL;
ppid = ::getppid();

Loading…
Cancel
Save