1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00

Main: Refine sever manager.

This commit is contained in:
winlin 2021-02-09 12:44:56 +08:00
parent 98c29a1494
commit ee1d06c613
5 changed files with 35 additions and 18 deletions

View file

@ -91,8 +91,8 @@ srs_error_t SrsServerAdapter::run()
return srs_error_wrap(err, "ingest");
}
if ((err = srs->cycle()) != srs_success) {
return srs_error_wrap(err, "main cycle");
if ((err = srs->start()) != srs_success) {
return srs_error_wrap(err, "start");
}
return err;
@ -151,29 +151,17 @@ srs_error_t SrsHybridServer::run()
{
srs_error_t err = srs_success;
// TODO: FIXME: Identify master server directly.
// Run master server in this main thread.
SrsServerAdapter* master_server = NULL;
vector<ISrsHybridServer*>::iterator it;
for (it = servers.begin(); it != servers.end(); ++it) {
ISrsHybridServer* server = *it;
if (!master_server) {
master_server = dynamic_cast<SrsServerAdapter*>(server);
if (master_server) {
continue;
}
}
if ((err = server->run()) != srs_success) {
return srs_error_wrap(err, "run server");
}
}
if (master_server) {
return master_server->run();
}
// Wait for all server to quit.
srs_thread_exit(NULL);
return err;
}

View file

@ -728,6 +728,7 @@ SrsServer::SrsServer()
http_server = new SrsHttpServer(this);
http_heartbeat = new SrsHttpHeartbeat();
ingester = new SrsIngester();
trd_ = new SrsSTCoroutine("srs", this, _srs_context->get_id());
}
SrsServer::~SrsServer()
@ -738,7 +739,9 @@ SrsServer::~SrsServer()
void SrsServer::destroy()
{
srs_warn("start destroy server");
srs_freep(trd_);
dispose();
srs_freep(http_api_mux);
@ -1101,6 +1104,17 @@ srs_error_t SrsServer::ingest()
return err;
}
srs_error_t SrsServer::start()
{
srs_error_t err = srs_success;
if ((err = trd_->start()) != srs_success) {
return srs_error_wrap(err, "start");
}
return err;
}
srs_error_t SrsServer::cycle()
{
srs_error_t err = srs_success;
@ -1249,6 +1263,10 @@ srs_error_t SrsServer::do_cycle()
int dynamic_max = srs_max(max, heartbeat_max_resolution);
for (int i = 0; i < dynamic_max; i++) {
if ((err = trd_->pull()) != srs_success) {
return srs_error_wrap(err, "pull");
}
srs_usleep(SRS_SYS_CYCLE_INTERVAL);
// asprocess check.

View file

@ -260,7 +260,8 @@ public:
// TODO: FIXME: Rename to SrsLiveServer.
// SRS RTMP server, initialize and listen, start connection service thread, destroy client.
class SrsServer : virtual public ISrsReloadHandler, virtual public ISrsSourceHandler, virtual public ISrsResourceManager
class SrsServer : virtual public ISrsReloadHandler, virtual public ISrsSourceHandler
, virtual public ISrsResourceManager, virtual public ISrsCoroutineHandler
{
private:
// TODO: FIXME: Extract an HttpApiServer.
@ -269,6 +270,7 @@ private:
SrsHttpHeartbeat* http_heartbeat;
SrsIngester* ingester;
SrsResourceManager* conn_manager;
SrsCoroutine* trd_;
private:
// The pid file fd, lock the file write when server is running.
// @remark the init.d script should cleanup the pid file, when stop service,
@ -315,6 +317,9 @@ public:
virtual srs_error_t register_signal();
virtual srs_error_t http_handle();
virtual srs_error_t ingest();
virtual srs_error_t start();
// interface ISrsCoroutineHandler
public:
virtual srs_error_t cycle();
// server utilities.
public:

View file

@ -151,6 +151,11 @@ srs_thread_t srs_thread_self()
return (srs_thread_t)st_thread_self();
}
void srs_thread_exit(void* retval)
{
st_thread_exit(retval);
}
srs_error_t srs_tcp_connect(string server, int port, srs_utime_t tm, srs_netfd_t* pstfd)
{
st_utime_t timeout = ST_UTIME_NO_TIMEOUT;

View file

@ -57,6 +57,7 @@ extern srs_error_t srs_fd_keepalive(int fd);
// Get current coroutine/thread.
extern srs_thread_t srs_thread_self();
extern void srs_thread_exit(void* retval);
// For client, to open socket and connect to server.
// @param tm The timeout in srs_utime_t.