mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
For #913, refine server initialize st
This commit is contained in:
parent
4e4091231e
commit
ca9f0bdb1e
3 changed files with 31 additions and 32 deletions
|
@ -586,14 +586,14 @@ srs_error_t SrsServer::initialize(ISrsServerCycle* cycle_handler)
|
|||
return err;
|
||||
}
|
||||
|
||||
int SrsServer::initialize_st()
|
||||
srs_error_t SrsServer::initialize_st()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// init st
|
||||
if ((ret = srs_st_init()) != ERROR_SUCCESS) {
|
||||
srs_error("init st failed. ret=%d", ret);
|
||||
return ret;
|
||||
return srs_error_new(ret, "initialize st failed");
|
||||
}
|
||||
|
||||
// @remark, st alloc segment use mmap, which only support 32757 threads,
|
||||
|
@ -601,11 +601,11 @@ int SrsServer::initialize_st()
|
|||
// TODO: FIXME: maybe can use "sysctl vm.max_map_count" to refine.
|
||||
#define __MMAP_MAX_CONNECTIONS 32756
|
||||
if (_srs_config->get_max_connections() > __MMAP_MAX_CONNECTIONS) {
|
||||
ret = ERROR_ST_EXCEED_THREADS;
|
||||
srs_error("st mmap for stack allocation must <= %d threads, "
|
||||
"@see Makefile of st for MALLOC_STACK, please build st manually by "
|
||||
"\"make EXTRA_CFLAGS=-DMALLOC_STACK linux-debug\", ret=%d", __MMAP_MAX_CONNECTIONS, ret);
|
||||
return ret;
|
||||
"\"make EXTRA_CFLAGS=-DMALLOC_STACK linux-debug\"", __MMAP_MAX_CONNECTIONS);
|
||||
return srs_error_new(ERROR_ST_EXCEED_THREADS, "%d exceed max %d threads",
|
||||
_srs_config->get_max_connections(), __MMAP_MAX_CONNECTIONS);
|
||||
}
|
||||
|
||||
// set current log id.
|
||||
|
@ -614,22 +614,20 @@ int SrsServer::initialize_st()
|
|||
// initialize the conponents that depends on st.
|
||||
#ifdef SRS_AUTO_KAFKA
|
||||
if ((ret = srs_initialize_kafka()) != ERROR_SUCCESS) {
|
||||
srs_error("initialize kafka failed, ret=%d", ret);
|
||||
return ret;
|
||||
return srs_error_new(ret, "initialize kafka");
|
||||
}
|
||||
#endif
|
||||
|
||||
// check asprocess.
|
||||
bool asprocess = _srs_config->get_asprocess();
|
||||
if (asprocess && ppid == 1) {
|
||||
ret = ERROR_SYSTEM_ASSERT_FAILED;
|
||||
srs_error("for asprocess, ppid should never be init(1), ret=%d", ret);
|
||||
return ret;
|
||||
return srs_error_new(ERROR_SYSTEM_ASSERT_FAILED, "ppid=%d illegal for asprocess", ppid);
|
||||
}
|
||||
srs_trace("server main cid=%d, pid=%d, ppid=%d, asprocess=%d",
|
||||
_srs_context->get_id(), ::getpid(), ppid, asprocess);
|
||||
|
||||
return ret;
|
||||
srs_trace("server main cid=%d, pid=%d, ppid=%d, asprocess=%d",
|
||||
_srs_context->get_id(), ::getpid(), ppid, asprocess);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int SrsServer::initialize_signal()
|
||||
|
|
|
@ -302,7 +302,7 @@ public:
|
|||
* @remark user must free the cycle handler.
|
||||
*/
|
||||
virtual srs_error_t initialize(ISrsServerCycle* cycle_handler);
|
||||
virtual int initialize_st();
|
||||
virtual srs_error_t initialize_st();
|
||||
virtual int initialize_signal();
|
||||
virtual int acquire_pid_file();
|
||||
virtual int listen();
|
||||
|
|
|
@ -51,7 +51,7 @@ using namespace std;
|
|||
|
||||
// pre-declare
|
||||
srs_error_t run(SrsServer* svr);
|
||||
int run_master(SrsServer* svr);
|
||||
srs_error_t run_master(SrsServer* svr);
|
||||
void show_macro_features();
|
||||
string srs_getenv(const char* name);
|
||||
|
||||
|
@ -342,7 +342,7 @@ void show_macro_features()
|
|||
|
||||
#if VERSION_MAJOR > VERSION_STABLE
|
||||
#warning "Current branch is unstable."
|
||||
srs_warn("Develop is unstable, please use branch: git checkout %s", VERSION_STABLE_BRANCH);
|
||||
srs_warn("Develop is unstable, please use branch: git checkout -b %s origin/%s", VERSION_STABLE_BRANCH, VERSION_STABLE_BRANCH);
|
||||
#endif
|
||||
|
||||
#if defined(SRS_PERF_SO_SNDBUF_SIZE) && !defined(SRS_PERF_MW_SO_SNDBUF)
|
||||
|
@ -377,8 +377,8 @@ srs_error_t run(SrsServer* svr)
|
|||
|
||||
// if not deamon, directly run master.
|
||||
if (!_srs_config->get_deamon()) {
|
||||
if ((ret = run_master(svr)) != ERROR_SUCCESS) {
|
||||
return srs_error_new(ret, "run master");
|
||||
if ((err = run_master(svr)) != srs_success) {
|
||||
return srs_error_wrap(err, "run master");
|
||||
}
|
||||
return srs_success;
|
||||
}
|
||||
|
@ -414,49 +414,50 @@ srs_error_t run(SrsServer* svr)
|
|||
// son
|
||||
srs_trace("son(deamon) process running.");
|
||||
|
||||
if ((ret = run_master(svr)) != ERROR_SUCCESS) {
|
||||
return srs_error_new(ret, "daemon run master");
|
||||
if ((err = run_master(svr)) != srs_success) {
|
||||
return srs_error_wrap(err, "daemon run master");
|
||||
}
|
||||
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
int run_master(SrsServer* svr)
|
||||
srs_error_t run_master(SrsServer* svr)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if ((ret = svr->initialize_st()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
if ((err = svr->initialize_st()) != srs_success) {
|
||||
return srs_error_wrap(err, "initialize st");
|
||||
}
|
||||
|
||||
if ((ret = svr->initialize_signal()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "initialize signal");
|
||||
}
|
||||
|
||||
if ((ret = svr->acquire_pid_file()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "acquire pid file");
|
||||
}
|
||||
|
||||
if ((ret = svr->listen()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "listen");
|
||||
}
|
||||
|
||||
if ((ret = svr->register_signal()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "register signal");
|
||||
}
|
||||
|
||||
if ((ret = svr->http_handle()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "http handle");
|
||||
}
|
||||
|
||||
if ((ret = svr->ingest()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "ingest");
|
||||
}
|
||||
|
||||
if ((ret = svr->cycle()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "main cycle");
|
||||
}
|
||||
|
||||
return 0;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue