mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
For #1657: Refine connection arch, remove hierachy
This commit is contained in:
parent
2a14dc0ebd
commit
24125b9770
7 changed files with 213 additions and 52 deletions
|
@ -85,7 +85,7 @@ srs_error_t SrsAppCasterFlv::on_tcp_client(srs_netfd_t stfd)
|
|||
srs_warn("empty ip for fd=%d", srs_netfd_fileno(stfd));
|
||||
}
|
||||
|
||||
SrsHttpConn* conn = new SrsDynamicHttpConn(this, stfd, http_mux, ip, port);
|
||||
ISrsStartableConneciton* conn = new SrsDynamicHttpConn(this, stfd, http_mux, ip, port);
|
||||
conns.push_back(conn);
|
||||
|
||||
if ((err = conn->start()) != srs_success) {
|
||||
|
@ -97,14 +97,14 @@ srs_error_t SrsAppCasterFlv::on_tcp_client(srs_netfd_t stfd)
|
|||
|
||||
void SrsAppCasterFlv::remove(ISrsResource* c)
|
||||
{
|
||||
SrsHttpConn* conn = dynamic_cast<SrsHttpConn*>(c);
|
||||
ISrsStartableConneciton* conn = dynamic_cast<ISrsStartableConneciton*>(c);
|
||||
|
||||
std::vector<SrsHttpConn*>::iterator it;
|
||||
std::vector<ISrsStartableConneciton*>::iterator it;
|
||||
if ((it = std::find(conns.begin(), conns.end(), conn)) != conns.end()) {
|
||||
conns.erase(it);
|
||||
}
|
||||
|
||||
// fixbug: SrsHttpConn for CasterFlv is not freed, which could cause memory leak
|
||||
// fixbug: ISrsStartableConneciton for CasterFlv is not freed, which could cause memory leak
|
||||
// so, free conn which is not managed by SrsServer->conns;
|
||||
// @see: https://github.com/ossrs/srs/issues/826
|
||||
manager->remove(c);
|
||||
|
@ -141,23 +141,23 @@ srs_error_t SrsAppCasterFlv::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
|||
return err;
|
||||
}
|
||||
|
||||
SrsDynamicHttpConn::SrsDynamicHttpConn(ISrsResourceManager* cm, srs_netfd_t fd, SrsHttpServeMux* m, string cip, int port) : SrsHttpConn(cm, fd, m, cip, port)
|
||||
SrsDynamicHttpConn::SrsDynamicHttpConn(ISrsResourceManager* cm, srs_netfd_t fd, SrsHttpServeMux* m, string cip, int cport)
|
||||
{
|
||||
manager = cm;
|
||||
sdk = NULL;
|
||||
pprint = SrsPithyPrint::create_caster();
|
||||
conn = new SrsHttpConn(this, fd, m, cip, cport);
|
||||
ip = cip;
|
||||
port = cport;
|
||||
}
|
||||
|
||||
SrsDynamicHttpConn::~SrsDynamicHttpConn()
|
||||
{
|
||||
srs_freep(conn);
|
||||
srs_freep(sdk);
|
||||
srs_freep(pprint);
|
||||
}
|
||||
|
||||
srs_error_t SrsDynamicHttpConn::on_got_http_message(ISrsHttpMessage* msg)
|
||||
{
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
srs_error_t SrsDynamicHttpConn::proxy(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string o)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
@ -249,6 +249,43 @@ srs_error_t SrsDynamicHttpConn::do_proxy(ISrsHttpResponseReader* rr, SrsFlvDecod
|
|||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsDynamicHttpConn::on_http_message(ISrsHttpMessage* msg)
|
||||
{
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
void SrsDynamicHttpConn::on_conn_done()
|
||||
{
|
||||
// Because we use manager to manage this object,
|
||||
// not the http connection object, so we must remove it here.
|
||||
manager->remove(this);
|
||||
}
|
||||
|
||||
std::string SrsDynamicHttpConn::desc()
|
||||
{
|
||||
return "DHttpConn";
|
||||
}
|
||||
|
||||
std::string SrsDynamicHttpConn::remote_ip()
|
||||
{
|
||||
return conn->remote_ip();
|
||||
}
|
||||
|
||||
const SrsContextId& SrsDynamicHttpConn::get_id()
|
||||
{
|
||||
return conn->get_id();
|
||||
}
|
||||
|
||||
srs_error_t SrsDynamicHttpConn::start()
|
||||
{
|
||||
return conn->start();
|
||||
}
|
||||
|
||||
void SrsDynamicHttpConn::remark(int64_t* in, int64_t* out)
|
||||
{
|
||||
conn->remark(in, out);
|
||||
}
|
||||
|
||||
SrsHttpFileReader::SrsHttpFileReader(ISrsHttpResponseReader* h)
|
||||
{
|
||||
http = h;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue