mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
For #1657, refine the context for disposing
This commit is contained in:
parent
b492d59df0
commit
fc21b31714
9 changed files with 38 additions and 12 deletions
|
@ -49,7 +49,7 @@ SrsAppCasterFlv::SrsAppCasterFlv(SrsConfDirective* c)
|
||||||
{
|
{
|
||||||
http_mux = new SrsHttpServeMux();
|
http_mux = new SrsHttpServeMux();
|
||||||
output = _srs_config->get_stream_caster_output(c);
|
output = _srs_config->get_stream_caster_output(c);
|
||||||
manager = new SrsResourceManager("CasterFLV");
|
manager = new SrsResourceManager("CFLV");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsAppCasterFlv::~SrsAppCasterFlv()
|
SrsAppCasterFlv::~SrsAppCasterFlv()
|
||||||
|
@ -259,6 +259,11 @@ srs_error_t SrsDynamicHttpConn::on_reload_http_stream_crossdomain()
|
||||||
return conn->set_crossdomain_enabled(v);
|
return conn->set_crossdomain_enabled(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
srs_error_t SrsDynamicHttpConn::on_start()
|
||||||
|
{
|
||||||
|
return srs_success;
|
||||||
|
}
|
||||||
|
|
||||||
srs_error_t SrsDynamicHttpConn::on_http_message(ISrsHttpMessage* msg)
|
srs_error_t SrsDynamicHttpConn::on_http_message(ISrsHttpMessage* msg)
|
||||||
{
|
{
|
||||||
return srs_success;
|
return srs_success;
|
||||||
|
|
|
@ -99,6 +99,7 @@ public:
|
||||||
virtual srs_error_t on_reload_http_stream_crossdomain();
|
virtual srs_error_t on_reload_http_stream_crossdomain();
|
||||||
// Interface ISrsHttpConnOwner.
|
// Interface ISrsHttpConnOwner.
|
||||||
public:
|
public:
|
||||||
|
virtual srs_error_t on_start();
|
||||||
virtual srs_error_t on_http_message(ISrsHttpMessage* msg);
|
virtual srs_error_t on_http_message(ISrsHttpMessage* msg);
|
||||||
virtual void on_conn_done();
|
virtual void on_conn_done();
|
||||||
// Interface ISrsResource.
|
// Interface ISrsResource.
|
||||||
|
|
|
@ -93,7 +93,7 @@ srs_error_t SrsResourceManager::cycle()
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
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) {
|
while (true) {
|
||||||
if ((err = trd->pull()) != srs_success) {
|
if ((err = trd->pull()) != srs_success) {
|
||||||
|
@ -183,10 +183,11 @@ void SrsResourceManager::remove(ISrsResource* c)
|
||||||
|
|
||||||
void SrsResourceManager::do_remove(ISrsResource* c)
|
void SrsResourceManager::do_remove(ISrsResource* c)
|
||||||
{
|
{
|
||||||
SrsContextRestore(cid_);
|
SrsContextRestore(_srs_context->get_id());
|
||||||
if (verbose_) {
|
if (verbose_) {
|
||||||
_srs_context->set_id(c->get_id());
|
_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_).
|
// Only notify when not removed(in zombies_).
|
||||||
|
@ -215,7 +216,7 @@ void SrsResourceManager::do_remove(ISrsResource* c)
|
||||||
|
|
||||||
// Ignore if handler is unsubscribing.
|
// Ignore if handler is unsubscribing.
|
||||||
if (!unsubs_.empty() && std::find(unsubs_.begin(), unsubs_.end(), h) != unsubs_.end()) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,7 +235,7 @@ void SrsResourceManager::clear()
|
||||||
|
|
||||||
SrsContextRestore(cid_);
|
SrsContextRestore(cid_);
|
||||||
if (verbose_) {
|
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.
|
// Clear all unsubscribing handlers, if not removing any resource.
|
||||||
|
@ -262,8 +263,8 @@ void SrsResourceManager::do_clear()
|
||||||
|
|
||||||
if (verbose_) {
|
if (verbose_) {
|
||||||
_srs_context->set_id(conn->get_id());
|
_srs_context->set_id(conn->get_id());
|
||||||
srs_trace("disposing resource(%s), zombies=%d/%d", conn->desc().c_str(),
|
srs_trace("%s: disposing resource(%s), zombies=%d/%d", label_.c_str(),
|
||||||
(int)copy.size(), (int)zombies_.size());
|
conn->desc().c_str(), (int)copy.size(), (int)zombies_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose(conn);
|
dispose(conn);
|
||||||
|
@ -304,7 +305,7 @@ void SrsResourceManager::dispose(ISrsResource* c)
|
||||||
|
|
||||||
// Ignore if handler is unsubscribing.
|
// Ignore if handler is unsubscribing.
|
||||||
if (!unsubs_.empty() && std::find(unsubs_.begin(), unsubs_.end(), h) != unsubs_.end()) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1689,6 +1689,11 @@ SrsHttpApi::~SrsHttpApi()
|
||||||
srs_freep(conn);
|
srs_freep(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
srs_error_t SrsHttpApi::on_start()
|
||||||
|
{
|
||||||
|
return srs_success;
|
||||||
|
}
|
||||||
|
|
||||||
srs_error_t SrsHttpApi::on_http_message(ISrsHttpMessage* req)
|
srs_error_t SrsHttpApi::on_http_message(ISrsHttpMessage* req)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
|
@ -268,6 +268,7 @@ public:
|
||||||
virtual ~SrsHttpApi();
|
virtual ~SrsHttpApi();
|
||||||
// Interface ISrsHttpConnOwner.
|
// Interface ISrsHttpConnOwner.
|
||||||
public:
|
public:
|
||||||
|
virtual srs_error_t on_start();
|
||||||
virtual srs_error_t on_http_message(ISrsHttpMessage* msg);
|
virtual srs_error_t on_http_message(ISrsHttpMessage* msg);
|
||||||
virtual void on_conn_done();
|
virtual void on_conn_done();
|
||||||
// Interface ISrsResource.
|
// Interface ISrsResource.
|
||||||
|
|
|
@ -81,7 +81,7 @@ SrsHttpConn::SrsHttpConn(ISrsHttpConnOwner* handler, srs_netfd_t fd, ISrsHttpSer
|
||||||
clk = new SrsWallClock();
|
clk = new SrsWallClock();
|
||||||
kbps = new SrsKbps(clk);
|
kbps = new SrsKbps(clk);
|
||||||
kbps->set_io(skt, skt);
|
kbps->set_io(skt, skt);
|
||||||
trd = new SrsSTCoroutine("http", this);
|
trd = new SrsSTCoroutine("http", this, _srs_context->get_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsHttpConn::~SrsHttpConn()
|
SrsHttpConn::~SrsHttpConn()
|
||||||
|
@ -160,6 +160,11 @@ srs_error_t SrsHttpConn::do_cycle()
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
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.
|
// set the recv timeout, for some clients never disconnect the connection.
|
||||||
// @see https://github.com/ossrs/srs/issues/398
|
// @see https://github.com/ossrs/srs/issues/398
|
||||||
skt->set_recv_timeout(SRS_HTTP_RECV_TIMEOUT);
|
skt->set_recv_timeout(SRS_HTTP_RECV_TIMEOUT);
|
||||||
|
@ -356,6 +361,11 @@ srs_error_t SrsResponseOnlyHttpConn::on_reload_http_stream_crossdomain()
|
||||||
return conn->set_crossdomain_enabled(v);
|
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 SrsResponseOnlyHttpConn::on_http_message(ISrsHttpMessage* msg)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
|
@ -61,6 +61,8 @@ public:
|
||||||
ISrsHttpConnOwner();
|
ISrsHttpConnOwner();
|
||||||
virtual ~ISrsHttpConnOwner();
|
virtual ~ISrsHttpConnOwner();
|
||||||
public:
|
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.
|
// Handle the HTTP message msg, which may be parsed partially.
|
||||||
// For the static service or api, discard any body.
|
// 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.
|
// 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();
|
virtual srs_error_t on_reload_http_stream_crossdomain();
|
||||||
// Interface ISrsHttpConnOwner.
|
// Interface ISrsHttpConnOwner.
|
||||||
public:
|
public:
|
||||||
|
virtual srs_error_t on_start();
|
||||||
virtual srs_error_t on_http_message(ISrsHttpMessage* msg);
|
virtual srs_error_t on_http_message(ISrsHttpMessage* msg);
|
||||||
virtual void on_conn_done();
|
virtual void on_conn_done();
|
||||||
// Extract APIs from SrsTcpConnection.
|
// Extract APIs from SrsTcpConnection.
|
||||||
|
|
|
@ -722,7 +722,7 @@ SrsRtspCaster::SrsRtspCaster(SrsConfDirective* c)
|
||||||
output = _srs_config->get_stream_caster_output(c);
|
output = _srs_config->get_stream_caster_output(c);
|
||||||
local_port_min = _srs_config->get_stream_caster_rtp_port_min(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);
|
local_port_max = _srs_config->get_stream_caster_rtp_port_max(c);
|
||||||
manager = new SrsResourceManager("CasterRTSP");
|
manager = new SrsResourceManager("CRTSP");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtspCaster::~SrsRtspCaster()
|
SrsRtspCaster::~SrsRtspCaster()
|
||||||
|
|
|
@ -656,7 +656,7 @@ SrsServer::SrsServer()
|
||||||
pid_fd = -1;
|
pid_fd = -1;
|
||||||
|
|
||||||
signal_manager = new SrsSignalManager(this);
|
signal_manager = new SrsSignalManager(this);
|
||||||
conn_manager = new SrsResourceManager("RTMP/API");
|
conn_manager = new SrsResourceManager("TCP", true);
|
||||||
|
|
||||||
handler = NULL;
|
handler = NULL;
|
||||||
ppid = ::getppid();
|
ppid = ::getppid();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue