diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index ca67fbbf5..9edf94699 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -3540,6 +3540,21 @@ int SrsConfig::check_config() { int ret = ERROR_SUCCESS; + if ((ret = check_normal_config()) != ERROR_SUCCESS) { + return ret; + } + + if ((ret = check_number_connections()) != ERROR_SUCCESS) { + return ret; + } + + return ret; +} + +int SrsConfig::check_normal_config() +{ + int ret = ERROR_SUCCESS; + srs_trace("srs checking config..."); //////////////////////////////////////////////////////////////////////// @@ -3659,51 +3674,6 @@ int SrsConfig::check_config() } } - //////////////////////////////////////////////////////////////////////// - // 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/ossrs/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 + 100, max_open_files, - nb_total, nb_connections, nb_consumed_fds, - ret, nb_connections, nb_canbe, nb_total + 100); - return ret; - } - } - //////////////////////////////////////////////////////////////////////// // check heartbeat //////////////////////////////////////////////////////////////////////// @@ -4097,6 +4067,58 @@ int SrsConfig::check_config() return ret; } +int SrsConfig::check_number_connections() +{ + int ret = ERROR_SUCCESS; + + //////////////////////////////////////////////////////////////////////// + // 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/ossrs/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 + 100, max_open_files, + nb_total, nb_connections, nb_consumed_fds, + ret, nb_connections, nb_canbe, nb_total + 100); + return ret; + } + } + + return ret; +} + int SrsConfig::parse_buffer(SrsConfigBuffer* buffer) { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 29246d7e7..3ac315362 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -544,6 +544,9 @@ public: * check the parsed config. */ virtual int check_config(); +protected: + virtual int check_normal_config(); + virtual int check_number_connections(); protected: /** * parse config from the buffer. diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 3208a81c9..d15b95035 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -78,7 +78,7 @@ int MockSrsConfig::parse(string buf) return ret; } - return check_config(); + return check_normal_config(); } #ifdef ENABLE_UTEST_CONFIG @@ -829,39 +829,6 @@ VOID TEST(ConfigMainTest, CheckConf_srs_log_file) } } -VOID TEST(ConfigMainTest, CheckConf_max_connections) -{ - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"max_connections 1000;")); - } - - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"max_connectionss 1000;")); - } - - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"max_connections 0;")); - } - - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"max_connections 1000000;")); - } - - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"max_connections -1;")); - } - - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"max_connections -1024;")); - } -} - VOID TEST(ConfigMainTest, CheckConf_daemon) { if (true) {