winlin

refine code of server.

@@ -918,29 +918,6 @@ int SrsServer::cycle() @@ -918,29 +918,6 @@ int SrsServer::cycle()
918 return ret; 918 return ret;
919 } 919 }
920 920
921 -void SrsServer::remove(SrsConnection* conn)  
922 -{  
923 - std::vector<SrsConnection*>::iterator it = std::find(conns.begin(), conns.end(), conn);  
924 -  
925 - // removed by destroy, ignore.  
926 - if (it == conns.end()) {  
927 - srs_warn("server moved connection, ignore.");  
928 - return;  
929 - }  
930 -  
931 - conns.erase(it);  
932 -  
933 - srs_info("conn removed. conns=%d", (int)conns.size());  
934 -  
935 - SrsStatistic* stat = SrsStatistic::instance();  
936 - stat->kbps_add_delta(conn);  
937 - stat->on_disconnect(conn->srs_id());  
938 -  
939 - // all connections are created by server,  
940 - // so we free it here.  
941 - srs_freep(conn);  
942 -}  
943 -  
944 void SrsServer::on_signal(int signo) 921 void SrsServer::on_signal(int signo)
945 { 922 {
946 if (signo == SRS_SIGNAL_RELOAD) { 923 if (signo == SRS_SIGNAL_RELOAD) {
@@ -1002,10 +979,9 @@ int SrsServer::do_cycle() @@ -1002,10 +979,9 @@ int SrsServer::do_cycle()
1002 int heartbeat_max_resolution = (int)(_srs_config->get_heartbeat_interval() / SRS_SYS_CYCLE_INTERVAL); 979 int heartbeat_max_resolution = (int)(_srs_config->get_heartbeat_interval() / SRS_SYS_CYCLE_INTERVAL);
1003 980
1004 // dynamic fetch the max. 981 // dynamic fetch the max.
1005 - int temp_max = max;  
1006 - temp_max = srs_max(temp_max, heartbeat_max_resolution); 982 + int dynamic_max = srs_max(max, heartbeat_max_resolution);
1007 983
1008 - for (int i = 0; i < temp_max; i++) { 984 + for (int i = 0; i < dynamic_max; i++) {
1009 st_usleep(SRS_SYS_CYCLE_INTERVAL * 1000); 985 st_usleep(SRS_SYS_CYCLE_INTERVAL * 1000);
1010 986
1011 // gracefully quit for SIGINT or SIGTERM(SRS_SIGNAL_GRACEFULLY_QUIT). 987 // 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) @@ -1331,6 +1307,29 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
1331 return ret; 1307 return ret;
1332 } 1308 }
1333 1309
  1310 +void SrsServer::remove(SrsConnection* conn)
  1311 +{
  1312 + std::vector<SrsConnection*>::iterator it = std::find(conns.begin(), conns.end(), conn);
  1313 +
  1314 + // removed by destroy, ignore.
  1315 + if (it == conns.end()) {
  1316 + srs_warn("server moved connection, ignore.");
  1317 + return;
  1318 + }
  1319 +
  1320 + conns.erase(it);
  1321 +
  1322 + srs_info("conn removed. conns=%d", (int)conns.size());
  1323 +
  1324 + SrsStatistic* stat = SrsStatistic::instance();
  1325 + stat->kbps_add_delta(conn);
  1326 + stat->on_disconnect(conn->srs_id());
  1327 +
  1328 + // all connections are created by server,
  1329 + // so we free it here.
  1330 + srs_freep(conn);
  1331 +}
  1332 +
1334 int SrsServer::on_reload_listen() 1333 int SrsServer::on_reload_listen()
1335 { 1334 {
1336 return listen(); 1335 return listen();
@@ -315,14 +315,6 @@ public: @@ -315,14 +315,6 @@ public:
315 virtual int ingest(); 315 virtual int ingest();
316 virtual int start_kafka(); 316 virtual int start_kafka();
317 virtual int cycle(); 317 virtual int cycle();
318 -// IConnectionManager  
319 -public:  
320 - /**  
321 - * callback for connection to remove itself.  
322 - * when connection thread cycle terminated, callback this to delete connection.  
323 - * @see SrsConnection.on_thread_stop().  
324 - */  
325 - virtual void remove(SrsConnection* conn);  
326 // server utilities. 318 // server utilities.
327 public: 319 public:
328 /** 320 /**
@@ -372,6 +364,14 @@ public: @@ -372,6 +364,14 @@ public:
372 * @param client_stfd, the client fd in st boxed, the underlayer fd. 364 * @param client_stfd, the client fd in st boxed, the underlayer fd.
373 */ 365 */
374 virtual int accept_client(SrsListenerType type, st_netfd_t client_stfd); 366 virtual int accept_client(SrsListenerType type, st_netfd_t client_stfd);
  367 +// IConnectionManager
  368 +public:
  369 + /**
  370 + * callback for connection to remove itself.
  371 + * when connection thread cycle terminated, callback this to delete connection.
  372 + * @see SrsConnection.on_thread_stop().
  373 + */
  374 + virtual void remove(SrsConnection* conn);
375 // interface ISrsReloadHandler. 375 // interface ISrsReloadHandler.
376 public: 376 public:
377 virtual int on_reload_listen(); 377 virtual int on_reload_listen();