diff --git a/trunk/conf/bandwidth.conf b/trunk/conf/bandwidth.conf index d2b678d6a..33ce199b7 100644 --- a/trunk/conf/bandwidth.conf +++ b/trunk/conf/bandwidth.conf @@ -2,6 +2,7 @@ # @see full.conf for detail config. listen 1935; +max_connections 1000; vhost __defaultVhost__ { } diff --git a/trunk/conf/console.conf b/trunk/conf/console.conf index ad5ddcc1a..e53d87c26 100644 --- a/trunk/conf/console.conf +++ b/trunk/conf/console.conf @@ -2,6 +2,7 @@ # @see full.conf for detail config. listen 1935; +max_connections 1000; daemon off; srs_log_tank console; http_api { diff --git a/trunk/conf/demo.19350.conf b/trunk/conf/demo.19350.conf index 91fa6981f..f5b37a6c1 100644 --- a/trunk/conf/demo.19350.conf +++ b/trunk/conf/demo.19350.conf @@ -3,6 +3,7 @@ # @see full.conf for detail config. listen 19350; +max_connections 1000; daemon on; srs_log_tank file; srs_log_file ./objs/srs.demo.19350.log; diff --git a/trunk/conf/demo.conf b/trunk/conf/demo.conf index f036bb6b7..4396d4446 100644 --- a/trunk/conf/demo.conf +++ b/trunk/conf/demo.conf @@ -3,6 +3,7 @@ # @see full.conf for detail config. listen 1935; +max_connections 1000; daemon on; srs_log_tank file; srs_log_file ./objs/srs.demo.log; diff --git a/trunk/conf/dvr.segment.conf b/trunk/conf/dvr.segment.conf index 9277671cc..3232d154c 100644 --- a/trunk/conf/dvr.segment.conf +++ b/trunk/conf/dvr.segment.conf @@ -3,6 +3,7 @@ # @see full.conf for detail config. listen 1935; +max_connections 1000; vhost __defaultVhost__ { dvr { enabled on; diff --git a/trunk/conf/dvr.session.conf b/trunk/conf/dvr.session.conf index 59496c8c1..265f0f1b7 100644 --- a/trunk/conf/dvr.session.conf +++ b/trunk/conf/dvr.session.conf @@ -3,6 +3,7 @@ # @see full.conf for detail config. listen 1935; +max_connections 1000; vhost __defaultVhost__ { dvr { enabled on; diff --git a/trunk/conf/edge.conf b/trunk/conf/edge.conf index f59972634..407d9ff85 100644 --- a/trunk/conf/edge.conf +++ b/trunk/conf/edge.conf @@ -3,6 +3,7 @@ # @see full.conf for detail config. listen 1935; +max_connections 1000; pid objs/edge.pid; srs_log_file ./objs/edge.log; vhost __defaultVhost__ { diff --git a/trunk/conf/edge.token.traverse.conf b/trunk/conf/edge.token.traverse.conf index a7ed4dc83..bd6bc7513 100644 --- a/trunk/conf/edge.token.traverse.conf +++ b/trunk/conf/edge.token.traverse.conf @@ -2,7 +2,8 @@ # @see https://github.com/winlinvip/simple-rtmp-server/wiki/DRM # @see full.conf for detail config. -listen 1935; +listen 1935 +max_connections 1000; vhost __defaultVhost__ { mode remote; origin 127.0.0.1:19350; diff --git a/trunk/conf/ffmpeg.transcode.conf b/trunk/conf/ffmpeg.transcode.conf index 789dcd0aa..917934341 100644 --- a/trunk/conf/ffmpeg.transcode.conf +++ b/trunk/conf/ffmpeg.transcode.conf @@ -3,6 +3,7 @@ # @see full.conf for detail config. listen 1935; +max_connections 1000; vhost __defaultVhost__ { transcode { enabled on; diff --git a/trunk/conf/forward.master.conf b/trunk/conf/forward.master.conf index ca4a72160..b0a6f51f2 100644 --- a/trunk/conf/forward.master.conf +++ b/trunk/conf/forward.master.conf @@ -3,6 +3,7 @@ # @see full.conf for detail config. listen 1935; +max_connections 1000; pid ./objs/srs.master.pid; srs_log_tank file; srs_log_file ./objs/srs.master.log; diff --git a/trunk/conf/forward.slave.conf b/trunk/conf/forward.slave.conf index 5d010d81e..1ff57db46 100644 --- a/trunk/conf/forward.slave.conf +++ b/trunk/conf/forward.slave.conf @@ -3,6 +3,7 @@ # @see full.conf for detail config. listen 19350; +max_connections 1000; pid ./objs/srs.slave.pid; srs_log_tank file; srs_log_file ./objs/srs.slave.log; diff --git a/trunk/conf/hls.conf b/trunk/conf/hls.conf index 397918b81..9e4981548 100644 --- a/trunk/conf/hls.conf +++ b/trunk/conf/hls.conf @@ -3,6 +3,7 @@ # @see full.conf for detail config. listen 1935; +max_connections 1000; vhost __defaultVhost__ { hls { enabled on; diff --git a/trunk/conf/http.heartbeat.conf b/trunk/conf/http.heartbeat.conf index 52513e11a..8455ad35f 100644 --- a/trunk/conf/http.heartbeat.conf +++ b/trunk/conf/http.heartbeat.conf @@ -1,7 +1,8 @@ # the config for srs http heartbeat, report its info to api-server # @see full.conf for detail config. -listen 1935; +listen 1935 +max_connections 1000; heartbeat { enabled on; interval 9.3; diff --git a/trunk/conf/http.hls.conf b/trunk/conf/http.hls.conf index 799a99037..468a13a45 100644 --- a/trunk/conf/http.hls.conf +++ b/trunk/conf/http.hls.conf @@ -3,6 +3,7 @@ # @see full.conf for detail config. listen 1935; +max_connections 1000; http_stream { enabled on; listen 8080; diff --git a/trunk/conf/http.hooks.callback.conf b/trunk/conf/http.hooks.callback.conf index 12d165d6c..6e4838aa9 100644 --- a/trunk/conf/http.hooks.callback.conf +++ b/trunk/conf/http.hooks.callback.conf @@ -2,6 +2,7 @@ # @see full.conf for detail config. listen 1935; +max_connections 1000; srs_log_tank file; srs_log_file ./objs/srs.log; vhost __defaultVhost__ { diff --git a/trunk/conf/ingest.conf b/trunk/conf/ingest.conf index e6a1d659f..651fbec8d 100644 --- a/trunk/conf/ingest.conf +++ b/trunk/conf/ingest.conf @@ -3,6 +3,7 @@ # @see full.conf for detail config. listen 1935; +max_connections 1000; vhost __defaultVhost__ { ingest livestream { enabled on; diff --git a/trunk/conf/origin.conf b/trunk/conf/origin.conf index f178e822c..da9296a2e 100644 --- a/trunk/conf/origin.conf +++ b/trunk/conf/origin.conf @@ -3,6 +3,7 @@ # @see full.conf for detail config. listen 19350; +max_connections 1000; pid objs/origin.pid; srs_log_file ./objs/origin.log; vhost __defaultVhost__ { diff --git a/trunk/conf/realtime.conf b/trunk/conf/realtime.conf index 55d4e4b60..b440762a5 100644 --- a/trunk/conf/realtime.conf +++ b/trunk/conf/realtime.conf @@ -3,6 +3,7 @@ # @see full.conf for detail config. listen 1935; +max_connections 1000; vhost __defaultVhost__ { gop_cache off; queue_length 10; diff --git a/trunk/conf/rtmp.conf b/trunk/conf/rtmp.conf index 76dbfec00..c43c58386 100644 --- a/trunk/conf/rtmp.conf +++ b/trunk/conf/rtmp.conf @@ -3,5 +3,6 @@ # @see full.conf for detail config. listen 1935; +max_connections 1000; vhost __defaultVhost__ { } diff --git a/trunk/conf/srs.conf b/trunk/conf/srs.conf index 98090d47f..6197f4187 100644 --- a/trunk/conf/srs.conf +++ b/trunk/conf/srs.conf @@ -2,6 +2,7 @@ # @see full.conf for detail config. listen 1935; +max_connections 1000; srs_log_tank file; srs_log_file ./objs/srs.log; http_api { diff --git a/trunk/conf/transcode2hls.audio.only.conf b/trunk/conf/transcode2hls.audio.only.conf index 8e24cbff8..b096ef2b1 100644 --- a/trunk/conf/transcode2hls.audio.only.conf +++ b/trunk/conf/transcode2hls.audio.only.conf @@ -3,6 +3,7 @@ # @see full.conf for detail config. listen 1935; +max_connections 1000; vhost __defaultVhost__ { hls { enabled on; diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 363a7d153..a6777afb3 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -23,6 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include +#include #include #include #include @@ -1405,6 +1406,18 @@ int SrsConfig::check_config() return ret; } + // check max connections of system limits + if (true) { + int max_open_files = sysconf(_SC_OPEN_MAX); + if (get_max_connections() > max_open_files) { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("invalid max_connections=%d, system limit to %d, ret=%d. " + "you can login as root and set the limit: ulimit -HSn %d", get_max_connections(), max_open_files, + ret, get_max_connections()); + return ret; + } + } + //////////////////////////////////////////////////////////////////////// // check heartbeat //////////////////////////////////////////////////////////////////////// diff --git a/trunk/src/app/srs_app_log.cpp b/trunk/src/app/srs_app_log.cpp index 034c8e892..7df15cc47 100644 --- a/trunk/src/app/srs_app_log.cpp +++ b/trunk/src/app/srs_app_log.cpp @@ -197,7 +197,9 @@ void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...) va_end(ap); // add strerror() to error msg. - size += snprintf(log_data + size, LOG_MAX_SIZE - size, "(%s)", strerror(errno)); + if (errno != 0) { + size += snprintf(log_data + size, LOG_MAX_SIZE - size, "(%s)", strerror(errno)); + } write_log(fd, log_data, size, SrsLogLevel::Error); } diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 12831f9e8..c3773efa5 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -1787,11 +1787,13 @@ VOID TEST(ConfigMainTest, ParseEmpty) VOID TEST(ConfigMainTest, ParseMinConf) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse("listen 1935;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.parse("listen 1935; max_connections 1000;")); vector listens = conf.get_listen(); EXPECT_EQ(1, (int)listens.size()); EXPECT_STREQ("1935", listens.at(0).c_str()); + + EXPECT_EQ(1000, conf.get_max_connections()); } VOID TEST(ConfigMainTest, ParseInvalidDirective) @@ -4364,3 +4366,94 @@ VOID TEST(ConfigMainTest, CheckConf_listen) EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listen -1935;")); } } + +VOID TEST(ConfigMainTest, CheckConf_pid) +{ + if (true) { + MockSrsConfig conf; + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("pids ./objs/srs.pid;")); + } +} + +VOID TEST(ConfigMainTest, CheckConf_chunk_size) +{ + if (true) { + MockSrsConfig conf; + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_sizes 60000;")); + } + + if (true) { + MockSrsConfig conf; + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size 0;")); + } + + if (true) { + MockSrsConfig conf; + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size 1;")); + } + + if (true) { + MockSrsConfig conf; + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size 127;")); + } + + if (true) { + MockSrsConfig conf; + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size -1;")); + } + + if (true) { + MockSrsConfig conf; + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size -4096;")); + } + + if (true) { + MockSrsConfig conf; + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size 65536;")); + } +} + +VOID TEST(ConfigMainTest, CheckConf_ff_log_dir) +{ + if (true) { + MockSrsConfig conf; + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("ff_log_dirs ./objs;")); + } +} + +VOID TEST(ConfigMainTest, CheckConf_srs_log_level) +{ + if (true) { + MockSrsConfig conf; + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("srs_log_levels trace;")); + } +} + +VOID TEST(ConfigMainTest, CheckConf_srs_log_file) +{ + if (true) { + MockSrsConfig conf; + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("srs_log_files ./objs/srs.log;")); + } +} + +VOID TEST(ConfigMainTest, CheckConf_max_connections) +{ + if (true) { + MockSrsConfig conf; + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("max_connectionss 1000;")); + } + + if (true) { + MockSrsConfig conf; + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("max_connections 0;")); + } +} + +VOID TEST(ConfigMainTest, CheckConf_) +{ + if (true) { + MockSrsConfig conf; + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listens 1935;")); + } +}