1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

refine the global variables.

This commit is contained in:
winlin 2016-12-08 17:26:04 +08:00
parent b06203e777
commit 2d387035cd
6 changed files with 42 additions and 39 deletions

View file

@ -55,7 +55,7 @@ using namespace std;
using namespace _srs_internal;
// the version to identify the core.
// @global the version to identify the core.
const char* _srs_version = "XCORE-"RTMP_SIG_SRS_SERVER;
#define SRS_WIKI_URL_LOG "https://github.com/ossrs/srs/wiki/v1_CN_SrsLog"
@ -4194,7 +4194,7 @@ bool SrsConfig::get_utc_time()
}
string SrsConfig::get_work_dir() {
static string DEFAULT = "";
static string DEFAULT = "./";
SrsConfDirective* conf = root->get("work_dir");
if( !conf || conf->arg0().empty()) {

View file

@ -125,7 +125,7 @@ extern std::string srs_config_bool2switch(const std::string& sbool);
*/
extern int srs_config_transform_vhost(SrsConfDirective* root);
// global config
// @global config object.
extern SrsConfig* _srs_config;
/**

View file

@ -1318,6 +1318,7 @@ SrsConnection* SrsServer::fd2conn(SrsListenerType type, st_netfd_t stfd)
}
SrsConnection* conn = NULL;
bool close_for_not_served = false;
if (type == SrsListenerRtmpStream) {
conn = new SrsRtmpConn(this, stfd, ip);
@ -1326,18 +1327,23 @@ SrsConnection* SrsServer::fd2conn(SrsListenerType type, st_netfd_t stfd)
conn = new SrsHttpApi(this, stfd, http_api_mux, ip);
#else
srs_warn("close http client for server not support http-api");
srs_close_stfd(stfd);
return ret;
close_for_not_served = true;
#endif
} else if (type == SrsListenerHttpStream) {
#ifdef SRS_AUTO_HTTP_SERVER
conn = new SrsResponseOnlyHttpConn(this, stfd, http_server, ip);
#else
srs_warn("close http client for server not support http-server");
return NULL;
close_for_not_served = true;
#endif
} else {
// TODO: FIXME: handler others
srs_assert(false);
}
if (close_for_not_served) {
srs_close_stfd(stfd);
return NULL;
}
return conn;

View file

@ -124,10 +124,10 @@ public:
virtual int set_id(int v);
};
// user must provides a log object
// @global user must provides a log object
extern ISrsLog* _srs_log;
// user must implements the LogContext and define a global instance.
// @global user must implements the LogContext and define a global instance.
extern ISrsThreadContext* _srs_context;
// donot print method

View file

@ -52,15 +52,11 @@ using namespace std;
// pre-declare
int proxy_hls2rtmp(std::string hls, std::string rtmp);
// for the main objects(server, config, log, context),
// never subscribe handler in constructor,
// instead, subscribe handler in initialize method.
// kernel module.
// @global log and context.
ISrsLog* _srs_log = new SrsFastLog();
ISrsThreadContext* _srs_context = new ISrsThreadContext();
// app module.
// @global config object for app module.
SrsConfig* _srs_config = NULL;
SrsServer* _srs_server = NULL;
#if defined(SRS_AUTO_HTTP_CORE)

View file

@ -46,21 +46,19 @@ using namespace std;
#include <srs_kernel_utility.hpp>
#include <srs_core_performance.hpp>
#include <srs_app_utility.hpp>
#include <srs_core_autofree.hpp>
// pre-declare
int run();
int run_master();
int run(SrsServer* svr);
int run_master(SrsServer* svr);
// for the main objects(server, config, log, context),
// never subscribe handler in constructor,
// instead, subscribe handler in initialize method.
// kernel module.
// @global log and context.
ISrsLog* _srs_log = new SrsFastLog();
ISrsThreadContext* _srs_context = new SrsThreadContext();
// app module.
ISrsThreadContext* _srs_context = new ISrsThreadContext();
// @global config object for app module.
SrsConfig* _srs_config = new SrsConfig();
SrsServer* _srs_server = new SrsServer();
// version of srs, which can grep keyword "XCORE"
// @global version of srs, which can grep keyword "XCORE"
extern const char* _srs_version;
/**
@ -316,23 +314,26 @@ int main(int argc, char** argv)
// 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 = _srs_server->initialize(NULL)) != ERROR_SUCCESS) {
if ((ret = svr->initialize(NULL)) != ERROR_SUCCESS) {
return ret;
}
return run();
return run(svr);
}
int run()
int run(SrsServer* svr)
{
// if not deamon, directly run master.
if (!_srs_config->get_deamon()) {
return run_master();
return run_master(svr);
}
srs_trace("start deamon mode...");
@ -370,42 +371,42 @@ int run()
// son
srs_trace("son(deamon) process running.");
return run_master();
return run_master(svr);
}
int run_master()
int run_master(SrsServer* svr)
{
int ret = ERROR_SUCCESS;
if ((ret = _srs_server->initialize_st()) != ERROR_SUCCESS) {
if ((ret = svr->initialize_st()) != ERROR_SUCCESS) {
return ret;
}
if ((ret = _srs_server->initialize_signal()) != ERROR_SUCCESS) {
if ((ret = svr->initialize_signal()) != ERROR_SUCCESS) {
return ret;
}
if ((ret = _srs_server->acquire_pid_file()) != ERROR_SUCCESS) {
if ((ret = svr->acquire_pid_file()) != ERROR_SUCCESS) {
return ret;
}
if ((ret = _srs_server->listen()) != ERROR_SUCCESS) {
if ((ret = svr->listen()) != ERROR_SUCCESS) {
return ret;
}
if ((ret = _srs_server->register_signal()) != ERROR_SUCCESS) {
if ((ret = svr->register_signal()) != ERROR_SUCCESS) {
return ret;
}
if ((ret = _srs_server->http_handle()) != ERROR_SUCCESS) {
if ((ret = svr->http_handle()) != ERROR_SUCCESS) {
return ret;
}
if ((ret = _srs_server->ingest()) != ERROR_SUCCESS) {
if ((ret = svr->ingest()) != ERROR_SUCCESS) {
return ret;
}
if ((ret = _srs_server->cycle()) != ERROR_SUCCESS) {
if ((ret = svr->cycle()) != ERROR_SUCCESS) {
return ret;
}