From afd64283660b998992e2c667e9c74449f0856ccd Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 23 Sep 2015 17:21:57 +0800 Subject: [PATCH] refine code of server. --- trunk/src/app/srs_app_server.cpp | 51 ++++++++++++++++---------------- trunk/src/app/srs_app_server.hpp | 16 +++++----- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index c88884551..f6b48278e 100755 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -918,29 +918,6 @@ int SrsServer::cycle() return ret; } -void SrsServer::remove(SrsConnection* conn) -{ - std::vector::iterator it = std::find(conns.begin(), conns.end(), conn); - - // removed by destroy, ignore. - if (it == conns.end()) { - srs_warn("server moved connection, ignore."); - return; - } - - conns.erase(it); - - srs_info("conn removed. conns=%d", (int)conns.size()); - - SrsStatistic* stat = SrsStatistic::instance(); - stat->kbps_add_delta(conn); - stat->on_disconnect(conn->srs_id()); - - // all connections are created by server, - // so we free it here. - srs_freep(conn); -} - void SrsServer::on_signal(int signo) { if (signo == SRS_SIGNAL_RELOAD) { @@ -1002,10 +979,9 @@ int SrsServer::do_cycle() int heartbeat_max_resolution = (int)(_srs_config->get_heartbeat_interval() / SRS_SYS_CYCLE_INTERVAL); // dynamic fetch the max. - int temp_max = max; - temp_max = srs_max(temp_max, heartbeat_max_resolution); + int dynamic_max = srs_max(max, heartbeat_max_resolution); - for (int i = 0; i < temp_max; i++) { + for (int i = 0; i < dynamic_max; i++) { st_usleep(SRS_SYS_CYCLE_INTERVAL * 1000); // gracefully quit for SIGINT or SIGTERM(SRS_SIGNAL_GRACEFULLY_QUIT). @@ -1331,6 +1307,29 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) return ret; } +void SrsServer::remove(SrsConnection* conn) +{ + std::vector::iterator it = std::find(conns.begin(), conns.end(), conn); + + // removed by destroy, ignore. + if (it == conns.end()) { + srs_warn("server moved connection, ignore."); + return; + } + + conns.erase(it); + + srs_info("conn removed. conns=%d", (int)conns.size()); + + SrsStatistic* stat = SrsStatistic::instance(); + stat->kbps_add_delta(conn); + stat->on_disconnect(conn->srs_id()); + + // all connections are created by server, + // so we free it here. + srs_freep(conn); +} + int SrsServer::on_reload_listen() { return listen(); diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index 04cf9644a..3f3e00637 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -315,14 +315,6 @@ public: virtual int ingest(); virtual int start_kafka(); virtual int cycle(); -// IConnectionManager -public: - /** - * callback for connection to remove itself. - * when connection thread cycle terminated, callback this to delete connection. - * @see SrsConnection.on_thread_stop(). - */ - virtual void remove(SrsConnection* conn); // server utilities. public: /** @@ -372,6 +364,14 @@ public: * @param client_stfd, the client fd in st boxed, the underlayer fd. */ virtual int accept_client(SrsListenerType type, st_netfd_t client_stfd); +// IConnectionManager +public: + /** + * callback for connection to remove itself. + * when connection thread cycle terminated, callback this to delete connection. + * @see SrsConnection.on_thread_stop(). + */ + virtual void remove(SrsConnection* conn); // interface ISrsReloadHandler. public: virtual int on_reload_listen();