mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 20:01:56 +00:00
For #1657, refine connection interface
This commit is contained in:
parent
0a82719bd3
commit
3038dd473d
4 changed files with 26 additions and 10 deletions
|
@ -314,6 +314,14 @@ void SrsResourceManager::dispose(ISrsResource* c)
|
|||
srs_freep(c);
|
||||
}
|
||||
|
||||
ISrsStartableConneciton::ISrsStartableConneciton()
|
||||
{
|
||||
}
|
||||
|
||||
ISrsStartableConneciton::~ISrsStartableConneciton()
|
||||
{
|
||||
}
|
||||
|
||||
SrsTcpConnection::SrsTcpConnection(ISrsResourceManager* cm, srs_netfd_t c, string cip, int cport)
|
||||
{
|
||||
manager = cm;
|
||||
|
|
|
@ -106,11 +106,20 @@ private:
|
|||
void dispose(ISrsResource* c);
|
||||
};
|
||||
|
||||
// Interface for connection that is startable.
|
||||
class ISrsStartableConneciton : virtual public ISrsConnection
|
||||
, virtual public ISrsStartable, virtual public ISrsKbpsDelta
|
||||
{
|
||||
public:
|
||||
ISrsStartableConneciton();
|
||||
virtual ~ISrsStartableConneciton();
|
||||
};
|
||||
|
||||
// The basic connection of SRS, for TCP based protocols,
|
||||
// all connections accept from listener must extends from this base class,
|
||||
// server will add the connection to manager, and delete it when remove.
|
||||
class SrsTcpConnection : virtual public ISrsConnection, virtual public ISrsCoroutineHandler
|
||||
, virtual public ISrsKbpsDelta, virtual public ISrsReloadHandler, virtual public ISrsStartable
|
||||
class SrsTcpConnection : virtual public ISrsStartableConneciton
|
||||
, virtual public ISrsReloadHandler, virtual public ISrsCoroutineHandler
|
||||
{
|
||||
protected:
|
||||
// Each connection start a green thread,
|
||||
|
|
|
@ -1482,21 +1482,20 @@ srs_error_t SrsServer::accept_client(SrsListenerType type, srs_netfd_t stfd)
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
ISrsResource* r = NULL;
|
||||
ISrsStartableConneciton* conn = NULL;
|
||||
|
||||
if ((err = fd_to_resource(type, stfd, &r)) != srs_success) {
|
||||
if ((err = fd_to_resource(type, stfd, &conn)) != srs_success) {
|
||||
if (srs_error_code(err) == ERROR_SOCKET_GET_PEER_IP && _srs_config->empty_ip_ok()) {
|
||||
srs_close_stfd(stfd); srs_error_reset(err);
|
||||
return srs_success;
|
||||
}
|
||||
return srs_error_wrap(err, "fd to resource");
|
||||
}
|
||||
srs_assert(r);
|
||||
srs_assert(conn);
|
||||
|
||||
// directly enqueue, the cycle thread will remove the client.
|
||||
conn_manager->add(r);
|
||||
conn_manager->add(conn);
|
||||
|
||||
ISrsStartable* conn = dynamic_cast<ISrsStartable*>(r);
|
||||
if ((err = conn->start()) != srs_success) {
|
||||
return srs_error_wrap(err, "start conn coroutine");
|
||||
}
|
||||
|
@ -1509,7 +1508,7 @@ SrsHttpServeMux* SrsServer::api_server()
|
|||
return http_api_mux;
|
||||
}
|
||||
|
||||
srs_error_t SrsServer::fd_to_resource(SrsListenerType type, srs_netfd_t stfd, ISrsResource** pr)
|
||||
srs_error_t SrsServer::fd_to_resource(SrsListenerType type, srs_netfd_t stfd, ISrsStartableConneciton** pr)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
|
@ -1565,7 +1564,7 @@ srs_error_t SrsServer::fd_to_resource(SrsListenerType type, srs_netfd_t stfd, IS
|
|||
|
||||
void SrsServer::remove(ISrsResource* c)
|
||||
{
|
||||
ISrsKbpsDelta* conn = dynamic_cast<ISrsKbpsDelta*>(c);
|
||||
ISrsStartableConneciton* conn = dynamic_cast<ISrsStartableConneciton*>(c);
|
||||
|
||||
SrsStatistic* stat = SrsStatistic::instance();
|
||||
stat->kbps_add_delta(c->get_id(), conn);
|
||||
|
|
|
@ -342,7 +342,7 @@ public:
|
|||
// TODO: FIXME: Fetch from hybrid server manager.
|
||||
virtual SrsHttpServeMux* api_server();
|
||||
private:
|
||||
virtual srs_error_t fd_to_resource(SrsListenerType type, srs_netfd_t stfd, ISrsResource** pr);
|
||||
virtual srs_error_t fd_to_resource(SrsListenerType type, srs_netfd_t stfd, ISrsStartableConneciton** pr);
|
||||
// Interface ISrsResourceManager
|
||||
public:
|
||||
// A callback for connection to remove itself.
|
||||
|
|
Loading…
Reference in a new issue