mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 03:41:55 +00:00
refine code, move the order of functions.
This commit is contained in:
parent
71f2726b31
commit
65b2ed7ac5
4 changed files with 514 additions and 513 deletions
|
@ -535,271 +535,6 @@ int SrsConfig::reload()
|
|||
return reload_conf(&conf);
|
||||
}
|
||||
|
||||
int SrsConfig::reload_conf(SrsConfig* conf)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
SrsConfDirective* old_root = root;
|
||||
SrsAutoFree(SrsConfDirective, old_root);
|
||||
|
||||
root = conf->root;
|
||||
conf->root = NULL;
|
||||
|
||||
// merge config.
|
||||
std::vector<ISrsReloadHandler*>::iterator it;
|
||||
|
||||
// never support reload:
|
||||
// daemon
|
||||
//
|
||||
// always support reload without additional code:
|
||||
// chunk_size, ff_log_dir,
|
||||
// bandcheck, http_hooks, heartbeat,
|
||||
// token_traverse, debug_srs_upnode,
|
||||
// security
|
||||
|
||||
// merge config: max_connections
|
||||
if (!srs_directive_equals(root->get("max_connections"), old_root->get("max_connections"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_max_conns()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes reload max_connections failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload max_connections success.");
|
||||
}
|
||||
|
||||
// merge config: listen
|
||||
if (!srs_directive_equals(root->get("listen"), old_root->get("listen"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_listen()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes reload listen failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload listen success.");
|
||||
}
|
||||
|
||||
// merge config: pid
|
||||
if (!srs_directive_equals(root->get("pid"), old_root->get("pid"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_pid()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes reload pid failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload pid success.");
|
||||
}
|
||||
|
||||
// merge config: srs_log_tank
|
||||
if (!srs_directive_equals(root->get("srs_log_tank"), old_root->get("srs_log_tank"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_log_tank()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes reload srs_log_tank failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload srs_log_tank success.");
|
||||
}
|
||||
|
||||
// merge config: srs_log_level
|
||||
if (!srs_directive_equals(root->get("srs_log_level"), old_root->get("srs_log_level"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_log_level()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes reload srs_log_level failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload srs_log_level success.");
|
||||
}
|
||||
|
||||
// merge config: srs_log_file
|
||||
if (!srs_directive_equals(root->get("srs_log_file"), old_root->get("srs_log_file"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_log_file()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes reload srs_log_file failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload srs_log_file success.");
|
||||
}
|
||||
|
||||
// merge config: pithy_print_ms
|
||||
if (!srs_directive_equals(root->get("pithy_print_ms"), old_root->get("pithy_print_ms"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_pithy_print()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes pithy_print_ms listen failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload pithy_print_ms success.");
|
||||
}
|
||||
|
||||
// merge config: http_api
|
||||
if ((ret = reload_http_api(old_root)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// merge config: http_stream
|
||||
if ((ret = reload_http_stream(old_root)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// TODO: FIXME: support reload stream_caster.
|
||||
|
||||
// merge config: vhost
|
||||
if ((ret = reload_vhost(old_root)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsConfig::reload_http_api(SrsConfDirective* old_root)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// merge config.
|
||||
std::vector<ISrsReloadHandler*>::iterator it;
|
||||
|
||||
// state graph
|
||||
// old_http_api new_http_api
|
||||
// DISABLED => ENABLED
|
||||
// ENABLED => DISABLED
|
||||
// ENABLED => ENABLED (modified)
|
||||
|
||||
SrsConfDirective* new_http_api = root->get("http_api");
|
||||
SrsConfDirective* old_http_api = old_root->get("http_api");
|
||||
|
||||
// DISABLED => ENABLED
|
||||
if (!get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes http_api disabled=>enabled failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload disabled=>enabled http_api success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ENABLED => DISABLED
|
||||
if (get_http_api_enabled(old_http_api) && !get_http_api_enabled(new_http_api)) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_http_api_disabled()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes http_api enabled=>disabled failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload enabled=>disabled http_api success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ENABLED => ENABLED (modified)
|
||||
if (get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)
|
||||
&& !srs_directive_equals(old_http_api, new_http_api)
|
||||
) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes http_api enabled modified failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload enabled modified http_api success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
srs_trace("reload http_api not changed success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsConfig::reload_http_stream(SrsConfDirective* old_root)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// merge config.
|
||||
std::vector<ISrsReloadHandler*>::iterator it;
|
||||
|
||||
// state graph
|
||||
// old_http_stream new_http_stream
|
||||
// DISABLED => ENABLED
|
||||
// ENABLED => DISABLED
|
||||
// ENABLED => ENABLED (modified)
|
||||
|
||||
SrsConfDirective* new_http_stream = root->get("http_stream");
|
||||
// http_stream rename to http_server in SRS2.
|
||||
if (!new_http_stream) {
|
||||
new_http_stream = root->get("http_server");
|
||||
}
|
||||
|
||||
SrsConfDirective* old_http_stream = old_root->get("http_stream");
|
||||
// http_stream rename to http_server in SRS2.
|
||||
if (!old_http_stream) {
|
||||
old_http_stream = root->get("http_server");
|
||||
}
|
||||
|
||||
// DISABLED => ENABLED
|
||||
if (!get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_http_stream_enabled()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes http_stream disabled=>enabled failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload disabled=>enabled http_stream success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ENABLED => DISABLED
|
||||
if (get_http_stream_enabled(old_http_stream) && !get_http_stream_enabled(new_http_stream)) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_http_stream_disabled()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes http_stream enabled=>disabled failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload enabled=>disabled http_stream success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ENABLED => ENABLED (modified)
|
||||
if (get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)
|
||||
&& !srs_directive_equals(old_http_stream, new_http_stream)
|
||||
) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_http_stream_updated()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes http_stream enabled modified failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload enabled modified http_stream success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
srs_trace("reload http_stream not changed success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsConfig::reload_vhost(SrsConfDirective* old_root)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
@ -1084,6 +819,271 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SrsConfig::reload_conf(SrsConfig* conf)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
SrsConfDirective* old_root = root;
|
||||
SrsAutoFree(SrsConfDirective, old_root);
|
||||
|
||||
root = conf->root;
|
||||
conf->root = NULL;
|
||||
|
||||
// merge config.
|
||||
std::vector<ISrsReloadHandler*>::iterator it;
|
||||
|
||||
// never support reload:
|
||||
// daemon
|
||||
//
|
||||
// always support reload without additional code:
|
||||
// chunk_size, ff_log_dir,
|
||||
// bandcheck, http_hooks, heartbeat,
|
||||
// token_traverse, debug_srs_upnode,
|
||||
// security
|
||||
|
||||
// merge config: max_connections
|
||||
if (!srs_directive_equals(root->get("max_connections"), old_root->get("max_connections"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_max_conns()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes reload max_connections failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload max_connections success.");
|
||||
}
|
||||
|
||||
// merge config: listen
|
||||
if (!srs_directive_equals(root->get("listen"), old_root->get("listen"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_listen()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes reload listen failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload listen success.");
|
||||
}
|
||||
|
||||
// merge config: pid
|
||||
if (!srs_directive_equals(root->get("pid"), old_root->get("pid"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_pid()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes reload pid failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload pid success.");
|
||||
}
|
||||
|
||||
// merge config: srs_log_tank
|
||||
if (!srs_directive_equals(root->get("srs_log_tank"), old_root->get("srs_log_tank"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_log_tank()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes reload srs_log_tank failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload srs_log_tank success.");
|
||||
}
|
||||
|
||||
// merge config: srs_log_level
|
||||
if (!srs_directive_equals(root->get("srs_log_level"), old_root->get("srs_log_level"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_log_level()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes reload srs_log_level failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload srs_log_level success.");
|
||||
}
|
||||
|
||||
// merge config: srs_log_file
|
||||
if (!srs_directive_equals(root->get("srs_log_file"), old_root->get("srs_log_file"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_log_file()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes reload srs_log_file failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload srs_log_file success.");
|
||||
}
|
||||
|
||||
// merge config: pithy_print_ms
|
||||
if (!srs_directive_equals(root->get("pithy_print_ms"), old_root->get("pithy_print_ms"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_pithy_print()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes pithy_print_ms listen failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload pithy_print_ms success.");
|
||||
}
|
||||
|
||||
// merge config: http_api
|
||||
if ((ret = reload_http_api(old_root)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// merge config: http_stream
|
||||
if ((ret = reload_http_stream(old_root)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// TODO: FIXME: support reload stream_caster.
|
||||
|
||||
// merge config: vhost
|
||||
if ((ret = reload_vhost(old_root)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsConfig::reload_http_api(SrsConfDirective* old_root)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// merge config.
|
||||
std::vector<ISrsReloadHandler*>::iterator it;
|
||||
|
||||
// state graph
|
||||
// old_http_api new_http_api
|
||||
// DISABLED => ENABLED
|
||||
// ENABLED => DISABLED
|
||||
// ENABLED => ENABLED (modified)
|
||||
|
||||
SrsConfDirective* new_http_api = root->get("http_api");
|
||||
SrsConfDirective* old_http_api = old_root->get("http_api");
|
||||
|
||||
// DISABLED => ENABLED
|
||||
if (!get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes http_api disabled=>enabled failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload disabled=>enabled http_api success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ENABLED => DISABLED
|
||||
if (get_http_api_enabled(old_http_api) && !get_http_api_enabled(new_http_api)) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_http_api_disabled()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes http_api enabled=>disabled failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload enabled=>disabled http_api success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ENABLED => ENABLED (modified)
|
||||
if (get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)
|
||||
&& !srs_directive_equals(old_http_api, new_http_api)
|
||||
) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes http_api enabled modified failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload enabled modified http_api success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
srs_trace("reload http_api not changed success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsConfig::reload_http_stream(SrsConfDirective* old_root)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// merge config.
|
||||
std::vector<ISrsReloadHandler*>::iterator it;
|
||||
|
||||
// state graph
|
||||
// old_http_stream new_http_stream
|
||||
// DISABLED => ENABLED
|
||||
// ENABLED => DISABLED
|
||||
// ENABLED => ENABLED (modified)
|
||||
|
||||
SrsConfDirective* new_http_stream = root->get("http_stream");
|
||||
// http_stream rename to http_server in SRS2.
|
||||
if (!new_http_stream) {
|
||||
new_http_stream = root->get("http_server");
|
||||
}
|
||||
|
||||
SrsConfDirective* old_http_stream = old_root->get("http_stream");
|
||||
// http_stream rename to http_server in SRS2.
|
||||
if (!old_http_stream) {
|
||||
old_http_stream = root->get("http_server");
|
||||
}
|
||||
|
||||
// DISABLED => ENABLED
|
||||
if (!get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_http_stream_enabled()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes http_stream disabled=>enabled failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload disabled=>enabled http_stream success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ENABLED => DISABLED
|
||||
if (get_http_stream_enabled(old_http_stream) && !get_http_stream_enabled(new_http_stream)) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_http_stream_disabled()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes http_stream enabled=>disabled failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload enabled=>disabled http_stream success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ENABLED => ENABLED (modified)
|
||||
if (get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)
|
||||
&& !srs_directive_equals(old_http_stream, new_http_stream)
|
||||
) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_http_stream_updated()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes http_stream enabled modified failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload enabled modified http_stream success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
srs_trace("reload http_stream not changed success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsConfig::reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
@ -1482,9 +1482,6 @@ int SrsConfig::check_config()
|
|||
|
||||
srs_trace("srs checking config...");
|
||||
|
||||
vector<SrsConfDirective*> vhosts = get_vhosts();
|
||||
vector<SrsConfDirective*> stream_casters = get_stream_casters();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check empty
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1558,6 +1555,170 @@ int SrsConfig::check_config()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check listen for rtmp.
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
if (true) {
|
||||
vector<string> listens = get_listens();
|
||||
if (listens.size() <= 0) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("directive \"listen\" is empty, ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
for (int i = 0; i < (int)listens.size(); i++) {
|
||||
string port = listens[i];
|
||||
if (port.empty() || ::atoi(port.c_str()) <= 0) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("directive listen invalid, port=%s, ret=%d", port.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check max connections
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
if (get_max_connections() <= 0) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("directive max_connections invalid, max_connections=%d, ret=%d", get_max_connections(), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// check max connections of system limits
|
||||
if (true) {
|
||||
int nb_consumed_fds = (int)get_listens().size();
|
||||
if (!get_http_api_listen().empty()) {
|
||||
nb_consumed_fds++;
|
||||
}
|
||||
if (!get_http_stream_listen().empty()) {
|
||||
nb_consumed_fds++;
|
||||
}
|
||||
if (get_log_tank_file()) {
|
||||
nb_consumed_fds++;
|
||||
}
|
||||
// 0, 1, 2 for stdin, stdout and stderr.
|
||||
nb_consumed_fds += 3;
|
||||
|
||||
int nb_connections = get_max_connections();
|
||||
int nb_total = nb_connections + nb_consumed_fds;
|
||||
|
||||
int max_open_files = (int)sysconf(_SC_OPEN_MAX);
|
||||
int nb_canbe = max_open_files - nb_consumed_fds - 1;
|
||||
|
||||
// for each play connections, we open a pipe(2fds) to convert SrsConsumver to io,
|
||||
// refine performance, @see: https://github.com/simple-rtmp-server/srs/issues/194
|
||||
if (nb_total >= max_open_files) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("invalid max_connections=%d, required=%d, system limit to %d, "
|
||||
"total=%d(max_connections=%d, nb_consumed_fds=%d), ret=%d. "
|
||||
"you can change max_connections from %d to %d, or "
|
||||
"you can login as root and set the limit: ulimit -HSn %d",
|
||||
nb_connections, nb_total + 1, max_open_files,
|
||||
nb_total, nb_connections, nb_consumed_fds,
|
||||
ret, nb_connections, nb_canbe, nb_total + 1);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check heartbeat
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
if (get_heartbeat_interval() <= 0) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("directive heartbeat interval invalid, interval=%"PRId64", ret=%d",
|
||||
get_heartbeat_interval(), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check stats
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
if (get_stats_network() < 0) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("directive stats network invalid, network=%d, ret=%d",
|
||||
get_stats_network(), ret);
|
||||
return ret;
|
||||
}
|
||||
if (true) {
|
||||
vector<std::string> ips = srs_get_local_ipv4_ips();
|
||||
int index = get_stats_network();
|
||||
if (index >= (int)ips.size()) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("stats network invalid, total local ip count=%d, index=%d, ret=%d",
|
||||
(int)ips.size(), index, ret);
|
||||
return ret;
|
||||
}
|
||||
srs_warn("stats network use index=%d, ip=%s", index, ips.at(index).c_str());
|
||||
}
|
||||
if (true) {
|
||||
SrsConfDirective* conf = get_stats_disk_device();
|
||||
if (conf == NULL || (int)conf->args.size() <= 0) {
|
||||
srs_warn("stats disk not configed, disk iops disabled.");
|
||||
} else {
|
||||
string disks;
|
||||
for (int i = 0; i < (int)conf->args.size(); i++) {
|
||||
disks += conf->args.at(i);
|
||||
disks += " ";
|
||||
}
|
||||
srs_warn("stats disk list: %s", disks.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check http api
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
if (get_http_api_listen().empty()) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("directive http_api listen invalid, listen=%s, ret=%d",
|
||||
get_http_api_listen().c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check http stream
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
if (get_http_stream_listen().empty()) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("directive http_stream listen invalid, listen=%s, ret=%d",
|
||||
get_http_stream_listen().c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check log name and level
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
if (true) {
|
||||
std::string log_filename = this->get_log_file();
|
||||
if (get_log_tank_file() && log_filename.empty()) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("must specifies the file to write log to. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
if (get_log_tank_file()) {
|
||||
srs_trace("write log to file %s", log_filename.c_str());
|
||||
srs_trace("you can: tailf %s", log_filename.c_str());
|
||||
srs_trace("@see: %s", SRS_WIKI_URL_LOG);
|
||||
} else {
|
||||
srs_trace("write log to console");
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check features
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
#ifndef SRS_AUTO_HTTP_SERVER
|
||||
if (get_http_stream_enabled()) {
|
||||
srs_warn("http_stream is disabled by configure");
|
||||
}
|
||||
#endif
|
||||
#ifndef SRS_AUTO_HTTP_API
|
||||
if (get_http_api_enabled()) {
|
||||
srs_warn("http_api is disabled by configure");
|
||||
}
|
||||
#endif
|
||||
|
||||
vector<SrsConfDirective*> stream_casters = get_stream_casters();
|
||||
for (int n = 0; n < (int)stream_casters.size(); n++) {
|
||||
SrsConfDirective* stream_caster = stream_casters[n];
|
||||
for (int i = 0; stream_caster && i < (int)stream_caster->directives.size(); i++) {
|
||||
|
@ -1572,6 +1733,9 @@ int SrsConfig::check_config()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
vector<SrsConfDirective*> vhosts;
|
||||
get_vhosts(vhosts);
|
||||
for (int n = 0; n < (int)vhosts.size(); n++) {
|
||||
SrsConfDirective* vhost = vhosts[n];
|
||||
for (int i = 0; vhost && i < (int)vhost->directives.size(); i++) {
|
||||
|
@ -1753,135 +1917,6 @@ int SrsConfig::check_config()
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check listen for rtmp.
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
if (true) {
|
||||
vector<string> listens = get_listens();
|
||||
if (listens.size() <= 0) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("directive \"listen\" is empty, ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
for (int i = 0; i < (int)listens.size(); i++) {
|
||||
string port = listens[i];
|
||||
if (port.empty() || ::atoi(port.c_str()) <= 0) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("directive listen invalid, port=%s, ret=%d", port.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check max connections
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
if (get_max_connections() <= 0) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("directive max_connections invalid, max_connections=%d, ret=%d", get_max_connections(), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// check max connections of system limits
|
||||
if (true) {
|
||||
int nb_consumed_fds = (int)get_listens().size();
|
||||
if (!get_http_api_listen().empty()) {
|
||||
nb_consumed_fds++;
|
||||
}
|
||||
if (!get_http_stream_listen().empty()) {
|
||||
nb_consumed_fds++;
|
||||
}
|
||||
if (get_log_tank_file()) {
|
||||
nb_consumed_fds++;
|
||||
}
|
||||
// 0, 1, 2 for stdin, stdout and stderr.
|
||||
nb_consumed_fds += 3;
|
||||
|
||||
int nb_connections = get_max_connections();
|
||||
int nb_total = nb_connections + nb_consumed_fds;
|
||||
|
||||
int max_open_files = (int)sysconf(_SC_OPEN_MAX);
|
||||
int nb_canbe = max_open_files - nb_consumed_fds - 1;
|
||||
|
||||
// for each play connections, we open a pipe(2fds) to convert SrsConsumver to io,
|
||||
// refine performance, @see: https://github.com/simple-rtmp-server/srs/issues/194
|
||||
if (nb_total >= max_open_files) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("invalid max_connections=%d, required=%d, system limit to %d, "
|
||||
"total=%d(max_connections=%d, nb_consumed_fds=%d), ret=%d. "
|
||||
"you can change max_connections from %d to %d, or "
|
||||
"you can login as root and set the limit: ulimit -HSn %d",
|
||||
nb_connections, nb_total + 1, max_open_files,
|
||||
nb_total, nb_connections, nb_consumed_fds,
|
||||
ret, nb_connections, nb_canbe, nb_total + 1);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check heartbeat
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
if (get_heartbeat_interval() <= 0) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("directive heartbeat interval invalid, interval=%"PRId64", ret=%d",
|
||||
get_heartbeat_interval(), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check stats
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
if (get_stats_network() < 0) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("directive stats network invalid, network=%d, ret=%d",
|
||||
get_stats_network(), ret);
|
||||
return ret;
|
||||
}
|
||||
if (true) {
|
||||
vector<std::string> ips = srs_get_local_ipv4_ips();
|
||||
int index = get_stats_network();
|
||||
if (index >= (int)ips.size()) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("stats network invalid, total local ip count=%d, index=%d, ret=%d",
|
||||
(int)ips.size(), index, ret);
|
||||
return ret;
|
||||
}
|
||||
srs_warn("stats network use index=%d, ip=%s", index, ips.at(index).c_str());
|
||||
}
|
||||
if (true) {
|
||||
SrsConfDirective* conf = get_stats_disk_device();
|
||||
if (conf == NULL || (int)conf->args.size() <= 0) {
|
||||
srs_warn("stats disk not configed, disk iops disabled.");
|
||||
} else {
|
||||
string disks;
|
||||
for (int i = 0; i < (int)conf->args.size(); i++) {
|
||||
disks += conf->args.at(i);
|
||||
disks += " ";
|
||||
}
|
||||
srs_warn("stats disk list: %s", disks.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check http api
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
if (get_http_api_listen().empty()) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("directive http_api listen invalid, listen=%s, ret=%d",
|
||||
get_http_api_listen().c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check http stream
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
if (get_http_stream_listen().empty()) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("directive http_stream listen invalid, listen=%s, ret=%d",
|
||||
get_http_stream_listen().c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check chunk size
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1906,39 +1941,6 @@ int SrsConfig::check_config()
|
|||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check log name and level
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
if (true) {
|
||||
std::string log_filename = this->get_log_file();
|
||||
if (get_log_tank_file() && log_filename.empty()) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("must specifies the file to write log to. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
if (get_log_tank_file()) {
|
||||
srs_trace("write log to file %s", log_filename.c_str());
|
||||
srs_trace("you can: tailf %s", log_filename.c_str());
|
||||
srs_trace("@see: %s", SRS_WIKI_URL_LOG);
|
||||
} else {
|
||||
srs_trace("write log to console");
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check features
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
#ifndef SRS_AUTO_HTTP_SERVER
|
||||
if (get_http_stream_enabled()) {
|
||||
srs_warn("http_stream is disabled by configure");
|
||||
}
|
||||
#endif
|
||||
#ifndef SRS_AUTO_HTTP_API
|
||||
if (get_http_api_enabled()) {
|
||||
srs_warn("http_api is disabled by configure");
|
||||
}
|
||||
#endif
|
||||
for (int i = 0; i < (int)vhosts.size(); i++) {
|
||||
SrsConfDirective* vhost = vhosts[i];
|
||||
srs_assert(vhost != NULL);
|
||||
|
@ -2207,12 +2209,10 @@ SrsConfDirective* SrsConfig::get_vhost(string vhost)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
vector<SrsConfDirective*> SrsConfig::get_vhosts()
|
||||
void SrsConfig::get_vhosts(vector<SrsConfDirective*>& vhosts)
|
||||
{
|
||||
srs_assert(root);
|
||||
|
||||
std::vector<SrsConfDirective*> vhosts;
|
||||
|
||||
for (int i = 0; i < (int)root->directives.size(); i++) {
|
||||
SrsConfDirective* conf = root->at(i);
|
||||
|
||||
|
@ -2222,8 +2222,6 @@ vector<SrsConfDirective*> SrsConfig::get_vhosts()
|
|||
|
||||
vhosts.push_back(conf);
|
||||
}
|
||||
|
||||
return vhosts;
|
||||
}
|
||||
|
||||
bool SrsConfig::get_vhost_enabled(string vhost)
|
||||
|
|
|
@ -253,6 +253,11 @@ public:
|
|||
* @remark, user can test the config before reload it.
|
||||
*/
|
||||
virtual int reload();
|
||||
private:
|
||||
/**
|
||||
* reload the vhost section of config.
|
||||
*/
|
||||
virtual int reload_vhost(SrsConfDirective* old_root);
|
||||
protected:
|
||||
/**
|
||||
* reload from the config.
|
||||
|
@ -269,10 +274,6 @@ private:
|
|||
*/
|
||||
virtual int reload_http_stream(SrsConfDirective* old_root);
|
||||
/**
|
||||
* reload the vhost section of config.
|
||||
*/
|
||||
virtual int reload_vhost(SrsConfDirective* old_root);
|
||||
/**
|
||||
* reload the transcode section of vhost of config.
|
||||
*/
|
||||
virtual int reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost);
|
||||
|
@ -413,7 +414,7 @@ public:
|
|||
/**
|
||||
* get all vhosts in config file.
|
||||
*/
|
||||
virtual std::vector<SrsConfDirective*> get_vhosts();
|
||||
virtual void get_vhosts(std::vector<SrsConfDirective*>& vhosts);
|
||||
/**
|
||||
* whether vhost is enabled
|
||||
* @param vhost, the vhost name.
|
||||
|
|
|
@ -543,20 +543,21 @@ int SrsHttpApi::do_cycle()
|
|||
// always free it in this scope.
|
||||
SrsAutoFree(ISrsHttpMessage, req);
|
||||
|
||||
// TODO: FIXME: use the post body.
|
||||
std::string res;
|
||||
|
||||
// get response body.
|
||||
if ((ret = req->body_read_all(res)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ok, handle http request.
|
||||
SrsHttpResponseWriter writer(&skt);
|
||||
if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// read all rest bytes in request body.
|
||||
char buf[SRS_HTTP_READ_CACHE_BYTES];
|
||||
ISrsHttpResponseReader* br = req->body_reader();
|
||||
while (!br->eof()) {
|
||||
if ((ret = br->read(buf, SRS_HTTP_READ_CACHE_BYTES, NULL)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
// donot keep alive, disconnect it.
|
||||
// @see https://github.com/simple-rtmp-server/srs/issues/399
|
||||
if (!req->is_keep_alive()) {
|
||||
|
|
|
@ -293,7 +293,8 @@ int SrsIngester::parse()
|
|||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// parse ingesters
|
||||
std::vector<SrsConfDirective*> vhosts = _srs_config->get_vhosts();
|
||||
std::vector<SrsConfDirective*> vhosts;
|
||||
_srs_config->get_vhosts(vhosts);
|
||||
|
||||
for (int i = 0; i < (int)vhosts.size(); i++) {
|
||||
SrsConfDirective* vhost = vhosts[i];
|
||||
|
|
Loading…
Reference in a new issue