2013-11-23 03:36:07 +00:00
|
|
|
/*
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
2014-01-01 02:37:12 +00:00
|
|
|
Copyright (c) 2013-2014 winlin
|
2013-11-23 03:36:07 +00:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
|
|
the Software without restriction, including without limitation the rights to
|
|
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2014-03-01 02:42:55 +00:00
|
|
|
#include <srs_kernel_log.hpp>
|
2014-03-01 02:30:16 +00:00
|
|
|
#include <srs_kernel_error.hpp>
|
2014-03-02 13:49:09 +00:00
|
|
|
#include <srs_app_server.hpp>
|
|
|
|
#include <srs_app_config.hpp>
|
|
|
|
#include <srs_app_log.hpp>
|
2014-03-01 10:06:20 +00:00
|
|
|
|
|
|
|
// kernel module.
|
|
|
|
ISrsLog* _srs_log = new SrsFastLog();
|
|
|
|
ISrsThreadContext* _srs_context = new SrsThreadContext();
|
|
|
|
// app module.
|
|
|
|
SrsConfig* _srs_config = new SrsConfig();
|
|
|
|
SrsServer* _srs_server = new SrsServer();
|
2013-11-23 03:36:07 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
2014-03-06 10:12:19 +00:00
|
|
|
#ifdef SRS_GPERF_HEAP_PROFILE
|
|
|
|
#include <gperftools/heap-profiler.h>
|
|
|
|
#endif
|
|
|
|
#ifdef SRS_GPERF_CPU_PROFILE
|
|
|
|
#include <gperftools/profiler.h>
|
|
|
|
#endif
|
|
|
|
|
2013-11-23 03:36:07 +00:00
|
|
|
void handler(int signo)
|
|
|
|
{
|
|
|
|
srs_trace("get a signal, signo=%d", signo);
|
2014-03-01 10:06:20 +00:00
|
|
|
_srs_server->on_signal(signo);
|
2013-11-23 03:36:07 +00:00
|
|
|
}
|
|
|
|
|
2014-03-01 10:27:55 +00:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2013-11-23 03:36:07 +00:00
|
|
|
int ret = ERROR_SUCCESS;
|
2014-03-06 10:12:19 +00:00
|
|
|
|
|
|
|
#ifdef SRS_GPERF_HEAP_PROFILE
|
|
|
|
HeapProfilerStart("gperf.srs");
|
|
|
|
#endif
|
|
|
|
#ifdef SRS_GPERF_CPU_PROFILE
|
|
|
|
ProfilerStart("gperf.srs.prof");
|
|
|
|
#endif
|
|
|
|
|
2013-11-23 03:36:07 +00:00
|
|
|
signal(SIGNAL_RELOAD, handler);
|
2014-03-07 04:24:47 +00:00
|
|
|
signal(SIGINT, handler);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
2014-03-01 10:06:20 +00:00
|
|
|
if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) {
|
2013-11-23 03:36:07 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-01 10:06:20 +00:00
|
|
|
if ((ret = _srs_server->initialize()) != ERROR_SUCCESS) {
|
2013-11-23 03:36:07 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-01 10:06:20 +00:00
|
|
|
// TODO: create log dir in _srs_config->get_log_dir()
|
2013-12-05 15:34:26 +00:00
|
|
|
|
2014-03-01 10:06:20 +00:00
|
|
|
if ((ret = _srs_server->listen()) != ERROR_SUCCESS) {
|
2013-11-23 03:36:07 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-01 10:06:20 +00:00
|
|
|
if ((ret = _srs_server->cycle()) != ERROR_SUCCESS) {
|
2013-11-23 03:36:07 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|