mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine main
This commit is contained in:
parent
83c251fc1c
commit
dd1c769f65
2 changed files with 165 additions and 164 deletions
|
@ -59,7 +59,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#define RTMP_SIG_SRS_SERVER RTMP_SIG_SRS_KEY"/"RTMP_SIG_SRS_VERSION"("RTMP_SIG_SRS_CODE")"
|
||||
|
||||
// stable major version
|
||||
#define VERSION_STABLE 1
|
||||
#define VERSION_STABLE 2
|
||||
#define VERSION_STABLE_BRANCH SRS_XSTR(VERSION_STABLE)".0release"
|
||||
|
||||
// internal macros, covert macro values to str,
|
||||
|
|
|
@ -51,6 +51,7 @@ using namespace std;
|
|||
// pre-declare
|
||||
int run(SrsServer* svr);
|
||||
int run_master(SrsServer* svr);
|
||||
void show_macro_features();
|
||||
|
||||
// @global log and context.
|
||||
ISrsLog* _srs_log = new SrsFastLog();
|
||||
|
@ -61,6 +62,111 @@ SrsConfig* _srs_config = new SrsConfig();
|
|||
// @global version of srs, which can grep keyword "XCORE"
|
||||
extern const char* _srs_version;
|
||||
|
||||
/**
|
||||
* main entrance.
|
||||
*/
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// TODO: support both little and big endian.
|
||||
srs_assert(srs_is_little_endian());
|
||||
|
||||
// for gperf gmp or gcp,
|
||||
// should never enable it when not enabled for performance issue.
|
||||
#ifdef SRS_AUTO_GPERF_MP
|
||||
HeapProfilerStart("gperf.srs.gmp");
|
||||
#endif
|
||||
#ifdef SRS_AUTO_GPERF_CP
|
||||
ProfilerStart("gperf.srs.gcp");
|
||||
#endif
|
||||
|
||||
// directly compile error when these two macro defines.
|
||||
#if defined(SRS_AUTO_GPERF_MC) && defined(SRS_AUTO_GPERF_MP)
|
||||
#error ("option --with-gmc confict with --with-gmp, "
|
||||
"@see: http://google-perftools.googlecode.com/svn/trunk/doc/heap_checker.html\n"
|
||||
"Note that since the heap-checker uses the heap-profiling framework internally, "
|
||||
"it is not possible to run both the heap-checker and heap profiler at the same time");
|
||||
#endif
|
||||
|
||||
// never use gmp to check memory leak.
|
||||
#ifdef SRS_AUTO_GPERF_MP
|
||||
#warning "gmp is not used for memory leak, please use gmc instead."
|
||||
#endif
|
||||
|
||||
// never use srs log(srs_trace, srs_error, etc) before config parse the option,
|
||||
// which will load the log config and apply it.
|
||||
if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// change the work dir and set cwd.
|
||||
string cwd = _srs_config->get_work_dir();
|
||||
if (!cwd.empty() && cwd != "./" && (ret = chdir(cwd.c_str())) != ERROR_SUCCESS) {
|
||||
srs_error("change cwd to %s failed. ret=%d", cwd.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
if ((ret = _srs_config->initialize_cwd()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// config parsed, initialize log.
|
||||
if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// config already applied to log.
|
||||
srs_trace(RTMP_SIG_SRS_SERVER", stable is "RTMP_SIG_SRS_PRIMARY);
|
||||
srs_trace("license: "RTMP_SIG_SRS_LICENSE", "RTMP_SIG_SRS_COPYRIGHT);
|
||||
srs_trace("authors: "RTMP_SIG_SRS_AUTHROS);
|
||||
srs_trace("contributors: "SRS_AUTO_CONSTRIBUTORS);
|
||||
srs_trace("build: %s, configure:%s, uname: %s", SRS_AUTO_BUILD_DATE, SRS_AUTO_USER_CONFIGURE, SRS_AUTO_UNAME);
|
||||
srs_trace("configure detail: "SRS_AUTO_CONFIGURE);
|
||||
#ifdef SRS_AUTO_EMBEDED_TOOL_CHAIN
|
||||
srs_trace("crossbuild tool chain: "SRS_AUTO_EMBEDED_TOOL_CHAIN);
|
||||
#endif
|
||||
srs_trace("cwd=%s, work_dir=%s", _srs_config->cwd().c_str(), cwd.c_str());
|
||||
|
||||
#ifdef SRS_PERF_GLIBC_MEMORY_CHECK
|
||||
// ensure glibc write error to stderr.
|
||||
setenv("LIBC_FATAL_STDERR_", "1", 1);
|
||||
// ensure glibc to do alloc check.
|
||||
setenv("MALLOC_CHECK_", "1", 1);
|
||||
srs_trace("env MALLOC_CHECK_=1 LIBC_FATAL_STDERR_=1");
|
||||
#endif
|
||||
|
||||
#ifdef SRS_AUTO_GPERF_MD
|
||||
char* TCMALLOC_PAGE_FENCE = getenv("TCMALLOC_PAGE_FENCE");
|
||||
if (!TCMALLOC_PAGE_FENCE || strcmp(TCMALLOC_PAGE_FENCE, "1")) {
|
||||
srs_trace("gmd enabled without env TCMALLOC_PAGE_FENCE=1");
|
||||
} else {
|
||||
srs_trace("env TCMALLOC_PAGE_FENCE=1");
|
||||
}
|
||||
#endif
|
||||
|
||||
// we check the config when the log initialized.
|
||||
if ((ret = _srs_config->check_config()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// features
|
||||
show_macro_features();
|
||||
|
||||
SrsServer* svr = new SrsServer();
|
||||
SrsAutoFree(SrsServer, svr);
|
||||
|
||||
/**
|
||||
* we do nothing in the constructor of server,
|
||||
* and use initialize to create members, set hooks for instance the reload handler,
|
||||
* all initialize will done in this stage.
|
||||
*/
|
||||
if ((ret = svr->initialize(NULL)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return run(svr);
|
||||
}
|
||||
|
||||
/**
|
||||
* show the features by macro, the actual macro values.
|
||||
*/
|
||||
|
@ -224,111 +330,6 @@ void show_macro_features()
|
|||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* main entrance.
|
||||
*/
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// TODO: support both little and big endian.
|
||||
srs_assert(srs_is_little_endian());
|
||||
|
||||
// for gperf gmp or gcp,
|
||||
// should never enable it when not enabled for performance issue.
|
||||
#ifdef SRS_AUTO_GPERF_MP
|
||||
HeapProfilerStart("gperf.srs.gmp");
|
||||
#endif
|
||||
#ifdef SRS_AUTO_GPERF_CP
|
||||
ProfilerStart("gperf.srs.gcp");
|
||||
#endif
|
||||
|
||||
// directly compile error when these two macro defines.
|
||||
#if defined(SRS_AUTO_GPERF_MC) && defined(SRS_AUTO_GPERF_MP)
|
||||
#error ("option --with-gmc confict with --with-gmp, "
|
||||
"@see: http://google-perftools.googlecode.com/svn/trunk/doc/heap_checker.html\n"
|
||||
"Note that since the heap-checker uses the heap-profiling framework internally, "
|
||||
"it is not possible to run both the heap-checker and heap profiler at the same time");
|
||||
#endif
|
||||
|
||||
// never use gmp to check memory leak.
|
||||
#ifdef SRS_AUTO_GPERF_MP
|
||||
#warning "gmp is not used for memory leak, please use gmc instead."
|
||||
#endif
|
||||
|
||||
// never use srs log(srs_trace, srs_error, etc) before config parse the option,
|
||||
// which will load the log config and apply it.
|
||||
if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// change the work dir and set cwd.
|
||||
string cwd = _srs_config->get_work_dir();
|
||||
if (!cwd.empty() && cwd != "./" && (ret = chdir(cwd.c_str())) != ERROR_SUCCESS) {
|
||||
srs_error("change cwd to %s failed. ret=%d", cwd.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
if ((ret = _srs_config->initialize_cwd()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// config parsed, initialize log.
|
||||
if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// config already applied to log.
|
||||
srs_trace(RTMP_SIG_SRS_SERVER", stable is "RTMP_SIG_SRS_PRIMARY);
|
||||
srs_trace("license: "RTMP_SIG_SRS_LICENSE", "RTMP_SIG_SRS_COPYRIGHT);
|
||||
srs_trace("authors: "RTMP_SIG_SRS_AUTHROS);
|
||||
srs_trace("contributors: "SRS_AUTO_CONSTRIBUTORS);
|
||||
srs_trace("build: %s, configure:%s, uname: %s", SRS_AUTO_BUILD_DATE, SRS_AUTO_USER_CONFIGURE, SRS_AUTO_UNAME);
|
||||
srs_trace("configure detail: "SRS_AUTO_CONFIGURE);
|
||||
#ifdef SRS_AUTO_EMBEDED_TOOL_CHAIN
|
||||
srs_trace("crossbuild tool chain: "SRS_AUTO_EMBEDED_TOOL_CHAIN);
|
||||
#endif
|
||||
srs_trace("cwd=%s, work_dir=%s", _srs_config->cwd().c_str(), cwd.c_str());
|
||||
|
||||
#ifdef SRS_PERF_GLIBC_MEMORY_CHECK
|
||||
// ensure glibc write error to stderr.
|
||||
setenv("LIBC_FATAL_STDERR_", "1", 1);
|
||||
// ensure glibc to do alloc check.
|
||||
setenv("MALLOC_CHECK_", "1", 1);
|
||||
srs_trace("env MALLOC_CHECK_=1 LIBC_FATAL_STDERR_=1");
|
||||
#endif
|
||||
|
||||
#ifdef SRS_AUTO_GPERF_MD
|
||||
char* TCMALLOC_PAGE_FENCE = getenv("TCMALLOC_PAGE_FENCE");
|
||||
if (!TCMALLOC_PAGE_FENCE || strcmp(TCMALLOC_PAGE_FENCE, "1")) {
|
||||
srs_trace("gmd enabled without env TCMALLOC_PAGE_FENCE=1");
|
||||
} else {
|
||||
srs_trace("env TCMALLOC_PAGE_FENCE=1");
|
||||
}
|
||||
#endif
|
||||
|
||||
// we check the config when the log initialized.
|
||||
if ((ret = _srs_config->check_config()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// features
|
||||
show_macro_features();
|
||||
|
||||
SrsServer* svr = new SrsServer();
|
||||
SrsAutoFree(SrsServer, svr);
|
||||
|
||||
/**
|
||||
* we do nothing in the constructor of server,
|
||||
* and use initialize to create members, set hooks for instance the reload handler,
|
||||
* all initialize will done in this stage.
|
||||
*/
|
||||
if ((ret = svr->initialize(NULL)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return run(svr);
|
||||
}
|
||||
|
||||
int run(SrsServer* svr)
|
||||
{
|
||||
// if not deamon, directly run master.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue