mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine code of server.
This commit is contained in:
parent
8b6c78b862
commit
afd6428366
2 changed files with 33 additions and 34 deletions
|
@ -918,29 +918,6 @@ int SrsServer::cycle()
|
|||
return ret;
|
||||
}
|
||||
|
||||
void SrsServer::remove(SrsConnection* conn)
|
||||
{
|
||||
std::vector<SrsConnection*>::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<SrsConnection*>::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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue